Implemented billing and shipping address selection in the cart UI, along with improved promocode dropdown. Updated GraphQL mutation to accept new address fields for more comprehensive order handling. - Replaced the old promocode selection implementation with `el-select` components. - Introduced billing and shipping address fields with selectable options. - Enhanced form validation to ensure all required fields are populated before checkout. - Updated translations (`en-gb.json`, `ru-ru.json`) with new field labels. - Adjusted SCSS for consistent styling of dropdowns. Improves user experience by streamlining and enhancing the checkout process. No breaking changes introduced.
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import { BUY_CART } from '@graphql/mutations/cart';
|
|
import type { IBuyOrderResponse } from '@types';
|
|
|
|
interface IBuyOrderArguments {
|
|
promocodeUuid: string,
|
|
billingAddress: string,
|
|
shippingAddress: string
|
|
}
|
|
|
|
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(args: IBuyOrderArguments) {
|
|
const result = await mutate({
|
|
orderUuid: orderUuid.value,
|
|
forcePayment: true,
|
|
forceBalance: false,
|
|
promocodeUuid: args.promocodeUuid,
|
|
billingAddress: args.billingAddress,
|
|
shippingAddress: args.shippingAddress,
|
|
});
|
|
|
|
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,
|
|
};
|
|
}
|