schon/storefront/app/composables/contact/useContactUs.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

63 lines
1.3 KiB
TypeScript

import { CONTACT_US } from '@graphql/mutations/contact';
import type { IContactUsResponse } from '@types';
interface IContactUsArguments {
name: string;
email: string;
phoneNumber?: string;
subject?: string;
message: string;
}
export function useContactUs() {
const { t } = useI18n();
const { $notify } = useNuxtApp();
const { mutate, loading, error } = useMutation<IContactUsResponse>(CONTACT_US);
async function contactUs(args: IContactUsArguments) {
const variables: Record<string> = {
name: args.name,
email: args.email,
message: args.message,
};
if (args.phoneNumber) {
variables.phoneNumber = args.phoneNumber;
}
if (args.subject) {
variables.subject = args.subject;
}
const result = await mutate(variables);
if (result?.data?.contactUs.received) {
$notify({
message: t('popup.success.contactUs'),
type: 'success',
});
}
}
watch(error, (err) => {
if (!err) return;
console.error('useContactUs 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 {
contactUs,
loading,
};
}