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