Skip to content

Commit 241cb61

Browse files
bartoszherbaMarcin Kwiatkowski
authored andcommitted
fix(myaccount): fix error handling for customer data and email update action (#777)
1 parent 10f0644 commit 241cb61

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

packages/theme/components/MyAccount/ProfileUpdateForm.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@
6767
required
6868
class="form__element"
6969
style="margin-top: 10px"
70-
@keypress.enter="handleSubmit(submitForm(reset))"
7170
/>
7271
<SfButton
7372
class="form__button"
74-
@click="handleSubmit(submitForm(reset))"
7573
>
7674
{{ $t('Update personal data') }}
7775
</SfButton>
@@ -91,11 +89,9 @@
9189
required
9290
class="form__element"
9391
style="margin-top: 10px"
94-
@keypress.enter="handleSubmit(submitForm(reset))"
9592
/>
9693
<SfButton
9794
class="form__button"
98-
@click="handleSubmit(submitForm(reset))"
9995
>
10096
{{ $t('Update personal data') }}
10197
</SfButton>
@@ -114,8 +110,8 @@
114110
import { defineComponent, ref } from '@nuxtjs/composition-api';
115111
import { ValidationProvider, ValidationObserver, extend } from 'vee-validate';
116112
import { email } from 'vee-validate/dist/rules';
117-
import { userGetters } from '~/getters';
118113
import { SfInput, SfButton, SfModal } from '@storefront-ui/vue';
114+
import { userGetters } from '~/getters';
119115
import { useUiNotification, useUser } from '~/composables';
120116
121117
extend('email', {
@@ -169,10 +165,15 @@ export default defineComponent({
169165
resetValidationFn();
170166
};
171167
172-
const onError = () => {
173-
form.value = resetForm();
174-
requirePassword.value = false;
175-
currentPassword.value = '';
168+
const onError = (msg) => {
169+
sendNotification({
170+
id: Symbol('user_updated'),
171+
message: msg,
172+
type: 'danger',
173+
icon: 'cross',
174+
persist: false,
175+
title: 'User Account',
176+
});
176177
};
177178
178179
if (

packages/theme/composables/useUser/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export const useUser = (): UseUser => {
3232
error.value = errorsFactory();
3333
};
3434

35+
const updateCustomerEmail = async (credentials: { email: string, password: string }): Promise<void> => {
36+
const { errors } = await app.context.$vsf.$magento.api.updateCustomerEmail(credentials);
37+
38+
if (errors) {
39+
throw errors.map((e) => e.message).join(',');
40+
}
41+
};
42+
3543
// eslint-disable-next-line consistent-return
3644
const updateUser = async ({ user: providedUser, customQuery }) => {
3745
Logger.debug('[Magento] Update user information', { providedUser, customQuery });
@@ -45,7 +53,7 @@ export const useUser = (): UseUser => {
4553
const userData = generateUserData(updateData);
4654

4755
if (email && email !== oldEmail) {
48-
await app.context.$vsf.$magento.api.updateCustomerEmail({
56+
await updateCustomerEmail({
4957
email,
5058
password,
5159
});
@@ -57,6 +65,7 @@ export const useUser = (): UseUser => {
5765
if (errors) {
5866
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
5967
Logger.error(errors.map((e) => e.message).join(','));
68+
error.value.updateUser = errors.map((e) => e.message).join(',');
6069
}
6170

6271
customerStore.user = data?.updateCustomerV2?.customer || {};

packages/theme/pages/MyAccount/MyProfile.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ import {
3636
confirmed,
3737
} from 'vee-validate/dist/rules';
3838
import { SfTabs } from '@storefront-ui/vue';
39-
import { onSSR } from '@vue-storefront/core';
40-
import { defineComponent } from '@nuxtjs/composition-api';
39+
import { defineComponent, useFetch } from '@nuxtjs/composition-api';
4140
import { useUser } from '~/composables';
4241
import ProfileUpdateForm from '~/components/MyAccount/ProfileUpdateForm.vue';
4342
import PasswordResetForm from '~/components/MyAccount/PasswordResetForm.vue';
@@ -112,7 +111,7 @@ export default defineComponent({
112111
new: form.value.newPassword,
113112
}), onComplete, onError);
114113
115-
onSSR(async () => {
114+
useFetch(async () => {
116115
await load();
117116
});
118117

0 commit comments

Comments
 (0)