Fixes: 1) Correct mutation name from `setlanguage` to `setLanguage` for consistency; 2) Improve product listing reactivity by addressing missing initialization in `useStore`; 3) Replace generic product queries with parametrized `useProducts` for modularity; 4) Resolve minor typos, missing semicolons, and code formatting inconsistencies. Extra: 1) Refactor feedback-related types, composables, and GraphQL utilities for modularity; 2) Update styles, Vue templates, and related scripts with enhanced formatting; 3) Remove unused methods like `getProducts`, standardizing query reactivity; 4) Cleanup and organize imports across multiple files.
74 lines
No EOL
1.7 KiB
TypeScript
74 lines
No EOL
1.7 KiB
TypeScript
import {useNotification} from "~/composables/notification";
|
|
import type {IFeedbackActionResponse} from "~/types";
|
|
import {MANAGE_FEEDBACK} from "~/graphql/mutations/feedbacks";
|
|
import {isGraphQLError} from "~/utils/error";
|
|
|
|
interface IFeedbackActionArguments {
|
|
action: string,
|
|
orderProductUuid: string,
|
|
comment?: string,
|
|
rating?: number
|
|
}
|
|
|
|
export function useFeedbackAction() {
|
|
const {t} = useI18n();
|
|
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, any> = {
|
|
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) {
|
|
useNotification({
|
|
message: t('popup.success.addFeedback'),
|
|
type: 'success'
|
|
});
|
|
}
|
|
} else {
|
|
useNotification({
|
|
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;
|
|
}
|
|
useNotification({
|
|
message,
|
|
type: 'error',
|
|
title: t('popup.errors.main')
|
|
});
|
|
});
|
|
|
|
return{
|
|
loading,
|
|
manageFeedback
|
|
};
|
|
} |