fix(CheckoutModal): no submit if invalid form
This commit is contained in:
parent
6d0a62ec21
commit
6940fab53a
1 changed files with 11 additions and 1 deletions
|
@ -30,6 +30,9 @@ export const CheckoutBookModal = ({
|
||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = useCallback(
|
||||||
async (data: Partial<BookCheckoutForm>) => {
|
async (data: Partial<BookCheckoutForm>) => {
|
||||||
|
if (!formState.isValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!data.checkoutBy) {
|
if (!data.checkoutBy) {
|
||||||
setError("checkoutBy", {
|
setError("checkoutBy", {
|
||||||
message: `please enter ${
|
message: `please enter ${
|
||||||
|
@ -61,7 +64,7 @@ export const CheckoutBookModal = ({
|
||||||
setFailed(await res.text());
|
setFailed(await res.text());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[uuid, onClose, setError, isChechout]
|
[formState.isValid, isChechout, uuid, setError, onClose]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -116,6 +119,12 @@ export const CheckoutBookModal = ({
|
||||||
"'null' is not a valid nickname"
|
"'null' is not a valid nickname"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
notUndefinedString: (value) => {
|
||||||
|
return (
|
||||||
|
value?.toLocaleLowerCase() !== "undefined" ||
|
||||||
|
"'undefined' is not a valid nickname"
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})}
|
})}
|
||||||
isInvalid={!!formState.errors.checkoutBy}
|
isInvalid={!!formState.errors.checkoutBy}
|
||||||
|
@ -184,6 +193,7 @@ export const CheckoutBookModal = ({
|
||||||
marginLeft: "auto",
|
marginLeft: "auto",
|
||||||
marginRight: "10px",
|
marginRight: "10px",
|
||||||
}}
|
}}
|
||||||
|
disabled={!formState.isValid}
|
||||||
onClick={() => onSubmit(values)}
|
onClick={() => onSubmit(values)}
|
||||||
>
|
>
|
||||||
{`${isChechout ? "Checkout" : "Return"} book`}
|
{`${isChechout ? "Checkout" : "Return"} book`}
|
||||||
|
|
Loading…
Reference in a new issue