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.
46 lines
1 KiB
TypeScript
46 lines
1 KiB
TypeScript
import { BUY_CART } from '@graphql/mutations/cart';
|
|
import type { IBuyOrderResponse } from '@types';
|
|
|
|
export function useOrderBuy() {
|
|
const { t } = useI18n();
|
|
const { $notify } = useNuxtApp();
|
|
const cartStore = useCartStore();
|
|
|
|
const orderUuid = computed(() => cartStore.currentOrder?.uuid);
|
|
|
|
const { mutate, loading, error } = useMutation<IBuyOrderResponse>(BUY_CART);
|
|
|
|
async function buyOrder() {
|
|
const result = await mutate({
|
|
orderUuid: orderUuid.value,
|
|
forcePayment: true,
|
|
});
|
|
|
|
if (result?.data?.buyOrder?.transaction?.process?.url) {
|
|
window.location.href = result.data.buyOrder.transaction.process.url;
|
|
} else {
|
|
console.log(result?.data);
|
|
}
|
|
}
|
|
|
|
watch(error, (err) => {
|
|
if (!err) return;
|
|
console.error('useOrderBuy 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 {
|
|
buyOrder,
|
|
loading,
|
|
};
|
|
}
|