Skip to content

Commit cd51cd9

Browse files
committed
fix(payments-ui): Do not display stale coupon error message before actual error
This pull request: - Updates to pass in the correct/latest error message managed in `errorMessage` into CouponError component, instead of error (not the source of truth) Closes: - PAY-3419
1 parent cb7473a commit cd51cd9

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

libs/payments/ui/src/lib/actions/applyCoupon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const applyCouponAction = async (
4444
case 'CouponErrorLimitReached':
4545
response = CouponErrorMessageType.LimitReached;
4646
break;
47-
case 'CouponErrorInvalid':
47+
case 'CouponErrorInvalidCode':
4848
default:
4949
response = CouponErrorMessageType.Invalid;
5050
}

libs/payments/ui/src/lib/client/components/CouponForm/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const CouponInput = forwardRef<HTMLInputElement, CouponInputProps>(
118118
}
119119
);
120120

121-
const CouponError = ({ error }: { error: string | null }) => {
121+
const CouponError = ({ error }: { error: CouponErrorMessageType | null }) => {
122122
const { pending } = useFormStatus();
123123

124124
if (!error || pending) {
@@ -157,7 +157,7 @@ const WithoutCoupon = ({
157157
return result;
158158
}
159159
const routeCoupon = useSearchParams().get('coupon') || undefined;
160-
const [error, formAction] = useFormState(applyCoupon, null);
160+
const [, formAction] = useFormState(applyCoupon, null);
161161
useEffect(() => {
162162
if (routeCoupon) {
163163
const formData = new FormData();
@@ -206,7 +206,7 @@ const WithoutCoupon = ({
206206
</Form.Submit>
207207
</div>
208208

209-
{errorMessage && error && <CouponError error={error} />}
209+
{errorMessage && <CouponError error={errorMessage} />}
210210
</Form.Field>
211211
</Form.Root>
212212
</section>

0 commit comments

Comments
 (0)