schon/storefront/app/composables/auth/useRegister.ts
Alexandr SaVBaD Waltz 8d7685ef67 feat(notification): integrate global notification plugin using ElNotification
Added a global `notify` method via Nuxt plugin to replace `useNotification`. Improved messaging structure by embedding progress bars and handled dynamic durations. Updated usage across composables and components for consistency.

- Replaced `useNotification` with `$notify` in all applicable files.
- Updated `app.config.ts` to support customizable notification positions.
- Refactored affected composables for simplified notification calls.
- Enhanced progress indicator display within notifications.

Breaking Changes:
`useNotification` is removed, requiring migration to the new `$notify` API.
2026-03-01 15:30:47 +03:00

83 lines
1.8 KiB
TypeScript

import { useMailClient } from '@composables/utils';
import { REGISTER } from '@graphql/mutations/auth.js';
import type { IRegisterResponse } from '@types';
interface IRegisterArguments {
firstName: string;
lastName: string;
phoneNumber: string;
email: string;
password: string;
confirmPassword: string;
referrer: string;
isSubscribed: boolean;
}
export function useRegister() {
const { t } = useI18n();
const { $notify } = useNuxtApp();
const appStore = useAppStore();
const { mailClientUrl, detectMailClient, openMailClient } = useMailClient();
const { mutate, loading, error } = useMutation<IRegisterResponse>(REGISTER);
async function register(payload: IRegisterArguments) {
const result = await mutate({
firstName: payload.firstName,
lastName: payload.lastName,
phoneNumber: payload.phoneNumber,
email: payload.email,
password: payload.password,
confirmPassword: payload.confirmPassword,
referrer: payload.referrer,
isSubscribed: payload.isSubscribed,
});
if (result?.data?.createUser?.success) {
detectMailClient(payload.email);
$notify({
message: h('div', [
h('p', t('popup.success.register')),
mailClientUrl.value
? h(
'button',
{
class: 'el-notification__button',
onClick: () => {
openMailClient();
},
},
t('buttons.goEmail'),
)
: '',
]),
type: 'success',
});
appStore.unsetActiveAuthState();
}
}
watch(error, (err) => {
if (!err) return;
console.error('useRegister error:', err);
let message = t('popup.errors.defaultError');
if (isGraphQLError(err)) {
message = err.graphQLErrors?.[0]?.message || message;
} else {
message = err.message;
}
$notify({
message,
type: 'error',
title: t('popup.errors.main'),
});
});
return {
register,
loading,
};
}