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.
185 lines
No EOL
5.1 KiB
TypeScript
185 lines
No EOL
5.1 KiB
TypeScript
import type {
|
|
IAddToOrderResponse,
|
|
IBulkOrderResponse, IRemoveAllFromOrderResponse,
|
|
IRemoveFromOrderResponse, IRemoveKindFromOrderResponse,
|
|
} from "~/types";
|
|
import {
|
|
ADD_TO_CART,
|
|
BULK_CART,
|
|
REMOVE_ALL_FROM_CART,
|
|
REMOVE_FROM_CART,
|
|
REMOVE_KIND_FROM_CART
|
|
} from "~/graphql/mutations/cart";
|
|
import {useNotification} from "~/composables/notification";
|
|
import {isGraphQLError} from "~/utils/error";
|
|
|
|
interface IOverwriteOrderArguments {
|
|
type: string,
|
|
productUuid?: string,
|
|
productName?: string,
|
|
bulkAction?: string,
|
|
products?: {
|
|
uuid: string
|
|
}[]
|
|
}
|
|
|
|
export function useOrderOverwrite () {
|
|
const {t} = useI18n();
|
|
const cartStore = useCartStore();
|
|
const userStore = useUserStore();
|
|
|
|
const isAuthenticated = computed(() => userStore.isAuthenticated);
|
|
const orderUuid = computed(() => cartStore.currentOrder?.uuid);
|
|
|
|
const {
|
|
mutate: addMutate,
|
|
loading: addLoading,
|
|
error: addError
|
|
} = useMutation<IAddToOrderResponse>(ADD_TO_CART);
|
|
const {
|
|
mutate: removeMutate,
|
|
loading: removeLoading,
|
|
error: removedError
|
|
} = useMutation<IRemoveFromOrderResponse>(REMOVE_FROM_CART);
|
|
const {
|
|
mutate: removeKindMutate,
|
|
loading: removeKindLoading,
|
|
error: removedKindError
|
|
} = useMutation<IRemoveKindFromOrderResponse>(REMOVE_KIND_FROM_CART);
|
|
const {
|
|
mutate: removeAllMutate,
|
|
loading: removeAllLoading,
|
|
error: removedAllError
|
|
} = useMutation<IRemoveAllFromOrderResponse>(REMOVE_ALL_FROM_CART);
|
|
const {
|
|
mutate: bulkMutate,
|
|
loading: bulkLoading,
|
|
error: bulkError
|
|
} = useMutation<IBulkOrderResponse>(BULK_CART);
|
|
|
|
async function overwriteOrder (
|
|
args: IOverwriteOrderArguments
|
|
) {
|
|
if (isAuthenticated.value) {
|
|
switch (args.type) {
|
|
case "add":
|
|
const addResult = await addMutate({
|
|
orderUuid: orderUuid.value,
|
|
productUuid: args.productUuid
|
|
});
|
|
|
|
if (addResult?.data?.addOrderProduct?.order) {
|
|
cartStore.setCurrentOrders(addResult.data.addOrderProduct.order);
|
|
|
|
useNotification({
|
|
message: t('popup.success.addToCart', { product: args.productName }),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
const removeResult = await removeMutate({
|
|
orderUuid: orderUuid.value,
|
|
productUuid: args.productUuid
|
|
});
|
|
|
|
if (removeResult?.data?.removeOrderProduct?.order) {
|
|
cartStore.setCurrentOrders(removeResult.data.removeOrderProduct.order);
|
|
|
|
useNotification({
|
|
message: t('popup.success.removeFromCart', { product: args.productName }),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
case "removeKind":
|
|
const removeKindResult = await removeKindMutate({
|
|
orderUuid: orderUuid.value,
|
|
productUuid: args.productUuid
|
|
});
|
|
|
|
if (removeKindResult?.data?.removeOrderProductsOfAKind?.order) {
|
|
cartStore.setCurrentOrders(removeKindResult.data.removeOrderProductsOfAKind.order);
|
|
|
|
useNotification({
|
|
message: t('popup.success.removeFromCart', { product: args.productName }),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
case "removeAll":
|
|
const removeAllResult = await removeAllMutate({
|
|
orderUuid: orderUuid.value,
|
|
productUuid: args.productUuid
|
|
});
|
|
|
|
if (removeAllResult?.data?.removeAllOrderProducts?.order) {
|
|
cartStore.setCurrentOrders(removeAllResult.data.removeAllOrderProducts.order);
|
|
|
|
useNotification({
|
|
message: t('popup.success.removeAllFromCart', { product: args.productName }),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
case "bulk":
|
|
const bulkResult = await bulkMutate({
|
|
orderUuid: orderUuid.value,
|
|
action: args.bulkAction,
|
|
products: args.products
|
|
});
|
|
|
|
if (bulkResult?.data?.bulkOrderAction?.order) {
|
|
cartStore.setCurrentOrders(bulkResult.data.bulkOrderAction.order);
|
|
useNotification({
|
|
message: t('popup.success.bulkRemoveWishlist'),
|
|
type: 'success'
|
|
});
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
console.error('No type provided for overwriteOrder');
|
|
}
|
|
} else {
|
|
useNotification({
|
|
message: t('popup.errors.loginFirst'),
|
|
type: 'error'
|
|
});
|
|
}
|
|
}
|
|
|
|
watch(addError || removedError || removedKindError || removedAllError || bulkError, (err) => {
|
|
if (!err) return;
|
|
console.error('useOrderOverwrite 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,
|
|
removeKindLoading,
|
|
removeAllLoading,
|
|
bulkLoading,
|
|
overwriteOrder
|
|
};
|
|
} |