Fixes: 1) Replace `ElNotification` with `useNotification` across all components and composables; 2) Add missing semicolons, consistent formatting, and type annotations in multiple files; 3) Resolve non-reactive elements in wishlist and cart state management; Extra: 1) Update i18n translations with new strings for promocodes, balance, authentication, and profile settings; 2) Refactor SCSS styles including variable additions and component-specific tweaks; 3) Remove redundant queries, unused imports, and `storePage.ts` file for cleanup.
161 lines
No EOL
4.4 KiB
TypeScript
161 lines
No EOL
4.4 KiB
TypeScript
import type {
|
|
IAddToWishlistResponse, IBulkWishlistResponse,
|
|
IRemoveAllFromWishlistResponse,
|
|
IRemoveFromWishlistResponse
|
|
} from "~/types";
|
|
import {
|
|
ADD_TO_WISHLIST,
|
|
BULK_WISHLIST,
|
|
REMOVE_ALL_FROM_WISHLIST,
|
|
REMOVE_FROM_WISHLIST
|
|
} from "~/graphql/mutations/wishlist";
|
|
import {isGraphQLError} from "~/utils/error";
|
|
import {useNotification} from "~/composables/notification";
|
|
|
|
interface IOverwriteWishlistArguments {
|
|
type: string,
|
|
productUuid?: string,
|
|
productName?: string,
|
|
bulkAction?: string,
|
|
products?: {
|
|
uuid: string
|
|
}[]
|
|
}
|
|
|
|
export function useWishlistOverwrite() {
|
|
const {t} = useI18n();
|
|
const wishlistStore = useWishlistStore();
|
|
const userStore = useUserStore();
|
|
|
|
const isAuthenticated = computed(() => userStore.isAuthenticated);
|
|
const wishlistUuid = computed(() => wishlistStore.wishlist?.uuid);
|
|
|
|
const {
|
|
mutate: addMutate,
|
|
loading: addLoading,
|
|
error: addError
|
|
} = useMutation<IAddToWishlistResponse>(ADD_TO_WISHLIST);
|
|
const {
|
|
mutate: removeMutate,
|
|
loading: removeLoading,
|
|
error: removedError
|
|
} = useMutation<IRemoveFromWishlistResponse>(REMOVE_FROM_WISHLIST);
|
|
const {
|
|
mutate: removeAllMutate,
|
|
loading: removeAllLoading,
|
|
error: removeAllError
|
|
} = useMutation<IRemoveAllFromWishlistResponse>(REMOVE_ALL_FROM_WISHLIST);
|
|
const {
|
|
mutate: bulkMutate,
|
|
loading: bulkLoading,
|
|
error: bulkError
|
|
} = useMutation<IBulkWishlistResponse>(BULK_WISHLIST);
|
|
|
|
async function overwriteWishlist (
|
|
args: IOverwriteWishlistArguments
|
|
) {
|
|
if (isAuthenticated.value) {
|
|
switch (args.type) {
|
|
case "add":
|
|
const addResult = await addMutate({
|
|
wishlistUuid: wishlistUuid.value,
|
|
productUuid: args.productUuid
|
|
});
|
|
|
|
if (addResult?.data?.addWishlistProduct?.wishlist) {
|
|
wishlistStore.setWishlist(addResult.data.addWishlistProduct.wishlist);
|
|
|
|
useNotification({
|
|
message: t('popup.success.addToWishlist', { product: args.productName }),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
const removeResult = await removeMutate({
|
|
wishlistUuid: wishlistUuid.value,
|
|
productUuid: args.productUuid
|
|
});
|
|
|
|
if (removeResult?.data?.removeWishlistProduct?.wishlist) {
|
|
wishlistStore.setWishlist(removeResult.data.removeWishlistProduct.wishlist);
|
|
|
|
useNotification({
|
|
message: t('popup.success.removeFromWishlist', { product: args.productName }),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
case "removeAll":
|
|
const removeAllResult = await removeAllMutate({
|
|
wishlistUuid: wishlistUuid.value,
|
|
productUuid: args.productUuid
|
|
});
|
|
|
|
if (removeAllResult?.data?.removeAllWishlistProducts?.wishlist) {
|
|
wishlistStore.setWishlist(removeAllResult.data.removeAllWishlistProducts.wishlist);
|
|
|
|
useNotification({
|
|
message: t('popup.success.removeAllFromWishlist'),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
case "bulk":
|
|
const bulkResult = await bulkMutate({
|
|
wishlistUuid: wishlistUuid.value,
|
|
action: args.bulkAction,
|
|
products: args.products
|
|
});
|
|
|
|
if (bulkResult?.data?.bulkWishlistAction?.wishlist) {
|
|
wishlistStore.setWishlist(bulkResult.data.bulkWishlistAction.wishlist);
|
|
useNotification({
|
|
message: t('popup.success.bulkRemoveWishlist'),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
console.error('No type provided for overwriteWishlist');
|
|
}
|
|
} else {
|
|
useNotification({
|
|
message: t('popup.errors.loginFirst'),
|
|
type: 'error'
|
|
});
|
|
}
|
|
}
|
|
|
|
watch(addError || removedError || removeAllError || bulkError, (err) => {
|
|
if (!err) return;
|
|
console.error('useWishlistOverwrite 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{
|
|
addLoading,
|
|
removeLoading,
|
|
removeAllLoading,
|
|
bulkLoading,
|
|
overwriteWishlist
|
|
};
|
|
} |