Skip to content

Commit 524c1a5

Browse files
author
Marcin Kwiatkowski
committed
refactor: added ui notifications to register form (#1127)
1 parent caf8c41 commit 524c1a5

File tree

1 file changed

+12
-6
lines changed
  • packages/theme/modules/customer/composables/useUser

1 file changed

+12
-6
lines changed

packages/theme/modules/customer/composables/useUser/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { Logger } from '~/helpers/logger';
1010
import { useCustomerStore } from '~/modules/customer/stores/customer';
1111
import { useCart } from '~/modules/checkout/composables/useCart';
1212
import { generateUserData } from '~/modules/customer/helpers/generateUserData';
13-
import { Customer } from '~/modules/GraphQL/types';
13+
import { useUiNotification } from '~/composables/useUiNotification';
14+
import type { Customer } from '~/modules/GraphQL/types';
1415
import type {
1516
UseUserInterface,
1617
UseUserErrors,
@@ -31,6 +32,7 @@ export function useUser(): UseUserInterface {
3132
const customerStore = useCustomerStore();
3233
const { app } = useContext();
3334
const { setCart } = useCart();
35+
const { send: sendNotification } = useUiNotification();
3436
const loading: Ref<boolean> = ref(false);
3537
const errorsFactory = () : UseUserErrors => ({
3638
updateUser: null,
@@ -240,12 +242,16 @@ export function useUser(): UseUserInterface {
240242

241243
Logger.debug('[Result]:', { data });
242244

243-
if (errors) {
245+
if (errors || !data || !data.createCustomerV2 || !data.createCustomerV2.customer) {
244246
Logger.error(errors.map((e) => e.message).join(','));
245-
}
246-
247-
if (!data || !data.createCustomerV2 || !data.createCustomerV2.customer) {
248-
Logger.error('Customer registration error'); // todo: handle errors in better way
247+
errors.map((registerError, i) => sendNotification({
248+
icon: 'error',
249+
id: Symbol(`registration_error-${i}`),
250+
message: registerError.message,
251+
persist: true,
252+
title: 'Registration error',
253+
type: 'danger',
254+
}));
249255
}
250256

251257
// if (recaptchaToken) { // todo: move recaptcha to separate module

0 commit comments

Comments
 (0)