feat(MED-98): disable discount button while loading
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useFormContext } from 'react-hook-form';
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
|
||||||
import { convertToLocale } from '@lib/util/money';
|
import { convertToLocale } from '@lib/util/money';
|
||||||
@@ -31,6 +31,8 @@ export default function DiscountCode({
|
|||||||
|
|
||||||
const { promotions = [] } = cart;
|
const { promotions = [] } = cart;
|
||||||
|
|
||||||
|
const [isAddingPromotionCode, setIsAddingPromotionCode] = useState(false);
|
||||||
|
|
||||||
const removePromotionCode = async (code: string) => {
|
const removePromotionCode = async (code: string) => {
|
||||||
const appliedCodes = promotions
|
const appliedCodes = promotions
|
||||||
.filter((p) => p.code !== undefined)
|
.filter((p) => p.code !== undefined)
|
||||||
@@ -53,6 +55,7 @@ export default function DiscountCode({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsAddingPromotionCode(true);
|
||||||
const loading = toast.loading(t('cart:discountCode.addLoading'));
|
const loading = toast.loading(t('cart:discountCode.addLoading'));
|
||||||
const result = await addPromotionCodeAction(code);
|
const result = await addPromotionCodeAction(code);
|
||||||
|
|
||||||
@@ -63,6 +66,7 @@ export default function DiscountCode({
|
|||||||
} else {
|
} else {
|
||||||
toast.error(t('cart:discountCode.addError'));
|
toast.error(t('cart:discountCode.addError'));
|
||||||
}
|
}
|
||||||
|
setIsAddingPromotionCode(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -87,7 +91,13 @@ export default function DiscountCode({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button type="button" variant="secondary" className="h-min" onClick={() => addPromotionCode(currentValue)}>
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
className="h-min"
|
||||||
|
onClick={() => addPromotionCode(currentValue)}
|
||||||
|
disabled={isAddingPromotionCode}
|
||||||
|
>
|
||||||
<Trans i18nKey={'cart:discountCode.apply'} />
|
<Trans i18nKey={'cart:discountCode.apply'} />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user