schon/storefront/app/composables/feedbacks/useFeedbackAction.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

71 lines
1.5 KiB
TypeScript

import { MANAGE_FEEDBACK } from '@graphql/mutations/feedbacks';
import type { IFeedbackActionResponse } from '@types';
interface IFeedbackActionArguments {
action: string;
orderProductUuid: string;
comment?: string;
rating?: number;
}
export function useFeedbackAction() {
const { t } = useI18n();
const { $notify } = useNuxtApp();
const userStore = useUserStore();
const isAuthenticated = computed(() => userStore.isAuthenticated);
const { mutate, loading, error } = useMutation<IFeedbackActionResponse>(MANAGE_FEEDBACK);
async function manageFeedback(args: IFeedbackActionArguments) {
if (isAuthenticated.value) {
const variables: Record<string> = {
action: args.action,
orderProductUuid: args.orderProductUuid,
};
if (args.comment) {
variables.comment = args.comment;
}
if (args.rating) {
variables.rating = args.rating;
}
const result = await mutate(variables);
if (result?.data?.feedback) {
$notify({
message: t('popup.success.addFeedback'),
type: 'success',
});
}
} else {
$notify({
message: t('popup.errors.loginFirst'),
type: 'error',
});
}
}
watch(error, (err) => {
if (!err) return;
console.error('useFeedbackAction 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 {
loading,
manageFeedback,
};
}