-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fd2bd3
commit acb0aaf
Showing
11 changed files
with
367 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from "react"; | ||
import { Formik, Field, Form, ErrorMessage } from "formik"; | ||
import * as yup from "yup"; | ||
|
||
import FormError from "./elements/FormError"; | ||
|
||
import { SHEET_IDENTIFIER_ID, SHEET_IDENTIFIER_TITLE } from "../../constants"; | ||
|
||
type CouponSheetProcessFormProps = { | ||
onSubmit: Function, | ||
}; | ||
|
||
const couponValidations = yup.object().shape({ | ||
sheet_identifier_value: yup | ||
.string() | ||
.required("Sheet ID or Title is required") | ||
.matches( | ||
/^[\w\n ]+$/, | ||
"Only letters, numbers, spaces, and underscores allowed" | ||
), | ||
}); | ||
|
||
export const CouponSheetProcessForm = ({ onSubmit }: CouponSheetProcessFormProps) => { | ||
return ( | ||
<Formik | ||
onSubmit={onSubmit} | ||
validationSchema={couponValidations} | ||
initialValues={{ | ||
sheet_identifier_value: "", | ||
sheet_identifier_type: SHEET_IDENTIFIER_ID, | ||
}} | ||
render={({ isSubmitting, setFieldValue, values }) => ( | ||
<Form className="coupon-form"> | ||
<div> | ||
<div className="flex" style={{ marginBottom: "10px" }}> | ||
<label className="flex"> | ||
<Field | ||
type="radio" | ||
name="sheet_identifier_type" | ||
value={SHEET_IDENTIFIER_ID} | ||
onClick={() => setFieldValue("sheet_identifier_type", SHEET_IDENTIFIER_ID)} | ||
checked={values.sheet_identifier_type===SHEET_IDENTIFIER_ID} | ||
/> | ||
Use Sheet ID | ||
</label> | ||
|
||
<label className="flex"> | ||
<Field | ||
type="radio" | ||
name="sheet_identifier_type" | ||
value={SHEET_IDENTIFIER_TITLE} | ||
onClick={() => setFieldValue("sheet_identifier_type", SHEET_IDENTIFIER_TITLE)} | ||
checked={values.sheet_identifier_type===SHEET_IDENTIFIER_TITLE} | ||
/> | ||
Use Sheet Title | ||
</label> | ||
</div> | ||
|
||
<div className="block text-area-div"> | ||
<label htmlFor="sheet_identifier_value"> | ||
{values.sheet_identifier_type===SHEET_IDENTIFIER_ID ? "Sheet ID*" : "Sheet Title*"} | ||
<Field name="sheet_identifier_value" component="textarea" rows="2" cols="20" /> | ||
</label> | ||
<ErrorMessage name="sheet_identifier_value" component={FormError} /> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<button type="submit" disabled={isSubmitting}> | ||
Process Coupon Sheet | ||
</button> | ||
</div> | ||
</Form> | ||
)} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.