From 6940fab53a5c1902f698b48050e15ddd3207967d Mon Sep 17 00:00:00 2001 From: 0ry5 Date: Fri, 13 Sep 2024 19:46:16 +0200 Subject: [PATCH] fix(CheckoutModal): no submit if invalid form --- .../src/shared/components/modals/CheckoutModal.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/shared/components/modals/CheckoutModal.tsx b/frontend/src/shared/components/modals/CheckoutModal.tsx index 79d69ac..d3eb42c 100644 --- a/frontend/src/shared/components/modals/CheckoutModal.tsx +++ b/frontend/src/shared/components/modals/CheckoutModal.tsx @@ -30,6 +30,9 @@ export const CheckoutBookModal = ({ const onSubmit = useCallback( async (data: Partial) => { + if (!formState.isValid) { + return; + } if (!data.checkoutBy) { setError("checkoutBy", { message: `please enter ${ @@ -61,7 +64,7 @@ export const CheckoutBookModal = ({ setFailed(await res.text()); } }, - [uuid, onClose, setError, isChechout] + [formState.isValid, isChechout, uuid, setError, onClose] ); return ( @@ -116,6 +119,12 @@ export const CheckoutBookModal = ({ "'null' is not a valid nickname" ); }, + notUndefinedString: (value) => { + return ( + value?.toLocaleLowerCase() !== "undefined" || + "'undefined' is not a valid nickname" + ); + }, }, })} isInvalid={!!formState.errors.checkoutBy} @@ -184,6 +193,7 @@ export const CheckoutBookModal = ({ marginLeft: "auto", marginRight: "10px", }} + disabled={!formState.isValid} onClick={() => onSubmit(values)} > {`${isChechout ? "Checkout" : "Return"} book`}