fix: promo code modal allowing white spaces
This commit is contained in:
parent
48eb658c20
commit
e57b40776c
1 changed files with 14 additions and 8 deletions
|
|
@ -21,7 +21,7 @@ const initialValues = {
|
|||
}
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
code: Yup.string().required().trim().max(25),
|
||||
code: Yup.string().required().trim().max(25).matches(/^\S*$/, 'No whitespace allowed'),
|
||||
discount: Yup.number().required().min(0).max(100)
|
||||
})
|
||||
|
||||
|
|
@ -50,6 +50,7 @@ const PromoCodesModal = ({ showModal, onClose, errorMsg, addCode }) => {
|
|||
onSubmit={({ code, discount }) => {
|
||||
handleAddCode(code, discount)
|
||||
}}>
|
||||
{({ errors }) => (
|
||||
<Form id="promo-form" className={classes.form}>
|
||||
<H3 className={classes.modalLabel1}>Promo code name</H3>
|
||||
<Field
|
||||
|
|
@ -91,7 +92,11 @@ const PromoCodesModal = ({ showModal, onClose, errorMsg, addCode }) => {
|
|||
</TL1>
|
||||
</div>
|
||||
<div className={classes.footer}>
|
||||
{errorMsg && <ErrorMessage>{errorMsg}</ErrorMessage>}
|
||||
{(errorMsg || !R.isEmpty(errors)) && (
|
||||
<ErrorMessage>
|
||||
{errorMsg || R.head(R.values(errors))}
|
||||
</ErrorMessage>
|
||||
)}
|
||||
<Button
|
||||
type="submit"
|
||||
form="promo-form"
|
||||
|
|
@ -100,6 +105,7 @@ const PromoCodesModal = ({ showModal, onClose, errorMsg, addCode }) => {
|
|||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</Modal>
|
||||
)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue