Skip to content

Commit

Permalink
fix(myaccount): fix error handling for customer data and email update…
Browse files Browse the repository at this point in the history
… action (#777)
  • Loading branch information
bartoszherba authored Mar 23, 2022
1 parent e2214bd commit d15e140
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
19 changes: 10 additions & 9 deletions packages/theme/components/MyAccount/ProfileUpdateForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@
required
class="form__element"
style="margin-top: 10px"
@keypress.enter="handleSubmit(submitForm(reset))"
/>
<SfButton
class="form__button"
@click="handleSubmit(submitForm(reset))"
>
{{ $t('Update personal data') }}
</SfButton>
Expand All @@ -91,11 +89,9 @@
required
class="form__element"
style="margin-top: 10px"
@keypress.enter="handleSubmit(submitForm(reset))"
/>
<SfButton
class="form__button"
@click="handleSubmit(submitForm(reset))"
>
{{ $t('Update personal data') }}
</SfButton>
Expand All @@ -114,8 +110,8 @@
import { defineComponent, ref } from '@nuxtjs/composition-api';
import { ValidationProvider, ValidationObserver, extend } from 'vee-validate';
import { email } from 'vee-validate/dist/rules';
import { userGetters } from '~/getters';
import { SfInput, SfButton, SfModal } from '@storefront-ui/vue';
import { userGetters } from '~/getters';
import { useUiNotification, useUser } from '~/composables';
extend('email', {
Expand Down Expand Up @@ -169,10 +165,15 @@ export default defineComponent({
resetValidationFn();
};
const onError = () => {
form.value = resetForm();
requirePassword.value = false;
currentPassword.value = '';
const onError = (msg) => {
sendNotification({
id: Symbol('user_updated'),
message: msg,
type: 'danger',
icon: 'cross',
persist: false,
title: 'User Account',
});
};
if (
Expand Down
11 changes: 10 additions & 1 deletion packages/theme/composables/useUser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export const useUser = (): UseUser => {
error.value = errorsFactory();
};

const updateCustomerEmail = async (credentials: { email: string, password: string }): Promise<void> => {
const { errors } = await app.context.$vsf.$magento.api.updateCustomerEmail(credentials);

if (errors) {
throw errors.map((e) => e.message).join(',');
}
};

// eslint-disable-next-line consistent-return
const updateUser = async ({ user: providedUser, customQuery }) => {
Logger.debug('[Magento] Update user information', { providedUser, customQuery });
Expand All @@ -45,7 +53,7 @@ export const useUser = (): UseUser => {
const userData = generateUserData(updateData);

if (email && email !== oldEmail) {
await app.context.$vsf.$magento.api.updateCustomerEmail({
await updateCustomerEmail({
email,
password,
});
Expand All @@ -57,6 +65,7 @@ export const useUser = (): UseUser => {
if (errors) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Logger.error(errors.map((e) => e.message).join(','));
error.value.updateUser = errors.map((e) => e.message).join(',');
}

customerStore.user = data?.updateCustomerV2?.customer || {};
Expand Down
5 changes: 2 additions & 3 deletions packages/theme/pages/MyAccount/MyProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import {
confirmed,
} from 'vee-validate/dist/rules';
import { SfTabs } from '@storefront-ui/vue';
import { onSSR } from '@vue-storefront/core';
import { defineComponent } from '@nuxtjs/composition-api';
import { defineComponent, useFetch } from '@nuxtjs/composition-api';
import { useUser } from '~/composables';
import ProfileUpdateForm from '~/components/MyAccount/ProfileUpdateForm.vue';
import PasswordResetForm from '~/components/MyAccount/PasswordResetForm.vue';
Expand Down Expand Up @@ -112,7 +111,7 @@ export default defineComponent({
new: form.value.newPassword,
}), onComplete, onError);
onSSR(async () => {
useFetch(async () => {
await load();
});
Expand Down

0 comments on commit d15e140

Please sign in to comment.