added new special code discount input
This commit is contained in:
@@ -27,9 +27,11 @@ const { mutateAsync: submitDiscountCode, isPending: submitDiscountCodeIsPending
|
||||
|
||||
const { mutateAsync: deleteDiscountCode, isPending: deleteDiscountCodeIsPending } = useDeleteDiscountCode();
|
||||
|
||||
const { mutateAsync: submitSpecialDiscountCode, isPending: submitSpecialDiscountCodeIsPending } = useSubmitSpecialDiscountCode();
|
||||
const { mutateAsync: submitSpecialDiscountCode, isPending: submitSpecialDiscountCodeIsPending } =
|
||||
useSubmitSpecialDiscountCode();
|
||||
|
||||
const { mutateAsync: deleteSpecialDiscountCode, isPending: deleteSpecialDiscountCodeIsPending } = useDeleteSpecialDiscountCode();
|
||||
const { mutateAsync: deleteSpecialDiscountCode, isPending: deleteSpecialDiscountCodeIsPending } =
|
||||
useDeleteSpecialDiscountCode();
|
||||
|
||||
const { mutateAsync: pay, isPending: paymentIsPending } = usePayOrder();
|
||||
|
||||
@@ -37,49 +39,49 @@ const { mutateAsync: pay, isPending: paymentIsPending } = usePayOrder();
|
||||
|
||||
const nextPage = computed(() => route.meta.nextPage as { name: string; label: string; query?: string } | undefined);
|
||||
|
||||
const hasSubmittedDiscountCode = computed(() => !!cart.value?.discount_code);
|
||||
// const hasSubmittedDiscountCode = computed(() => !!cart.value?.discount_code);
|
||||
|
||||
const hasSubmittedSpecialDiscountCode = computed(() => !!cart.value?.special_discount_code);
|
||||
|
||||
// methods
|
||||
|
||||
const handleSubmitDiscountCode = () => {
|
||||
submitDiscountCode(
|
||||
{ code: discountCode.value },
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.cart] });
|
||||
},
|
||||
onError: () => {
|
||||
addToast({
|
||||
message: "خطایی در ثبت کد تخفیف رخ داد",
|
||||
options: {
|
||||
status: "error",
|
||||
},
|
||||
});
|
||||
discountCode.value = "";
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
// const handleSubmitDiscountCode = () => {
|
||||
// submitDiscountCode(
|
||||
// { code: discountCode.value },
|
||||
// {
|
||||
// onSuccess: () => {
|
||||
// queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.cart] });
|
||||
// },
|
||||
// onError: () => {
|
||||
// addToast({
|
||||
// message: "خطایی در ثبت کد تخفیف رخ داد",
|
||||
// options: {
|
||||
// status: "error",
|
||||
// },
|
||||
// });
|
||||
// discountCode.value = "";
|
||||
// },
|
||||
// }
|
||||
// );
|
||||
// };
|
||||
|
||||
const handleDeleteDiscountCode = () => {
|
||||
deleteDiscountCode(undefined, {
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.cart] });
|
||||
discountCode.value = "";
|
||||
},
|
||||
onError: () => {
|
||||
addToast({
|
||||
message: "خطایی در حذف کد تخفیف رخ داد",
|
||||
options: {
|
||||
status: "error",
|
||||
},
|
||||
});
|
||||
discountCode.value = "";
|
||||
},
|
||||
});
|
||||
};
|
||||
// const handleDeleteDiscountCode = () => {
|
||||
// deleteDiscountCode(undefined, {
|
||||
// onSuccess: () => {
|
||||
// queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.cart] });
|
||||
// discountCode.value = "";
|
||||
// },
|
||||
// onError: () => {
|
||||
// addToast({
|
||||
// message: "خطایی در حذف کد تخفیف رخ داد",
|
||||
// options: {
|
||||
// status: "error",
|
||||
// },
|
||||
// });
|
||||
// discountCode.value = "";
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
|
||||
const handleSubmitSpecialDiscountCode = () => {
|
||||
submitSpecialDiscountCode(
|
||||
@@ -204,9 +206,7 @@ watch(
|
||||
{{ cart?.cart_total }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="flex items-center justify-between w-full text-gray-500"
|
||||
>
|
||||
<div class="flex items-center justify-between w-full text-gray-500">
|
||||
<span class="max-w-1/2 text-sm"> تخفیف کلی محصولات: </span>
|
||||
|
||||
<span class="max-w-1/2 text-sm">
|
||||
@@ -214,19 +214,19 @@ watch(
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="hasSubmittedDiscountCode"
|
||||
<!-- <div
|
||||
v-if="hasSubmittedSpecialDiscountCode"
|
||||
class="flex items-center justify-between w-full text-status-error-primary text-red-700"
|
||||
>
|
||||
<span class="max-w-1/2 text-sm"> تخفیف: </span>
|
||||
|
||||
<span class="max-w-1/2 text-sm">
|
||||
{{ cart?.discount_code.amount }}
|
||||
{{ cart?.special_discount_total }}
|
||||
</span>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div
|
||||
v-if="cart?.special_discount_total && cart.special_discount_total !== '0 تومان'"
|
||||
v-if="!!cart?.special_discount_code"
|
||||
class="flex items-center justify-between w-full text-green-700"
|
||||
>
|
||||
<span class="max-w-1/2 text-sm"> تخفیف ویژه: </span>
|
||||
@@ -242,7 +242,6 @@ watch(
|
||||
<span class="max-w-1/2 text-sm"> {{ cart?.tax_amount }} </span>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="flex items-center justify-between w-full text-slate-900">
|
||||
<span class="max-w-1/2 text-sm"> جمع کل: </span>
|
||||
|
||||
@@ -253,13 +252,17 @@ watch(
|
||||
|
||||
<div class="w-full flex justify-between">
|
||||
<Input
|
||||
v-model="discountCode"
|
||||
v-model="specialDiscountCode"
|
||||
placeholder="کد تخفیف"
|
||||
class="!py-3 !pe-2 ps-2.5 w-full !rounded-none !border-e-[0px] !rounded-s-100"
|
||||
:disabled="hasSubmittedDiscountCode"
|
||||
:disabled="hasSubmittedSpecialDiscountCode"
|
||||
/>
|
||||
<button
|
||||
@click="hasSubmittedDiscountCode ? handleDeleteDiscountCode() : handleSubmitDiscountCode()"
|
||||
@click="
|
||||
hasSubmittedSpecialDiscountCode
|
||||
? handleDeleteSpecialDiscountCode()
|
||||
: handleSubmitSpecialDiscountCode()
|
||||
"
|
||||
class="text-xs px-5 rounded-e-100 py-1.5 text-white bg-black hover:bg-transparent hover:text-black border-[1.5px] border-black hover:border-black transition-all disabled:cursor-not-allowed"
|
||||
:disabled="!discountCode.length || submitDiscountCodeIsPending || deleteDiscountCodeIsPending"
|
||||
>
|
||||
@@ -270,12 +273,12 @@ watch(
|
||||
class="**:fill-white"
|
||||
/>
|
||||
<span v-else>
|
||||
{{ hasSubmittedDiscountCode ? "حذف" : "ثبت" }}
|
||||
{{ hasSubmittedSpecialDiscountCode ? "حذف" : "ثبت" }}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex justify-between">
|
||||
<!-- <div class="w-full flex justify-between">
|
||||
<Input
|
||||
v-model="specialDiscountCode"
|
||||
placeholder="کد تخفیف ویژه"
|
||||
@@ -297,7 +300,7 @@ watch(
|
||||
{{ hasSubmittedSpecialDiscountCode ? "حذف" : "ثبت" }}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<Button
|
||||
v-if="nextPage?.name == 'payment'"
|
||||
|
||||
Reference in New Issue
Block a user