-
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
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
editor.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/SubmissionForm.tsx
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,60 @@ | ||
import Typography from "@mui/material/Typography"; | ||
import { useFormik } from "formik"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import React, { ChangeEvent } from "react"; | ||
import InputLabel from "ui/editor/InputLabel"; | ||
import Input from "ui/shared/Input"; | ||
import * as Yup from "yup"; | ||
|
||
import { SettingsForm } from "../shared/SettingsForm"; | ||
import { FormProps } from "."; | ||
|
||
export default function SubmissionForm({ formikConfig, onSuccess }: FormProps) { | ||
const formSchema = Yup.object().shape({ | ||
submissionEmail: Yup.string().email("Enter a valid email address"), | ||
}); | ||
|
||
const formik = useFormik({ | ||
...formikConfig, | ||
validationSchema: formSchema, | ||
onSubmit: async (values, { resetForm }) => { | ||
const isSuccess = await useStore.getState().updateTeamSettings({ | ||
submissionEmail: values.submissionEmail, | ||
}); | ||
if (isSuccess) { | ||
onSuccess(); | ||
resetForm({ values }); | ||
} | ||
}, | ||
}); | ||
|
||
return ( | ||
<SettingsForm | ||
legend="Submission Information" | ||
formik={formik} | ||
description={ | ||
<> | ||
<Typography variant="body2"> | ||
The email address used by the Send component to send applications to | ||
your planning office. | ||
</Typography> | ||
</> | ||
} | ||
input={ | ||
<> | ||
<InputLabel label="Submission email" htmlFor="submissionEmail"> | ||
<Input | ||
name="submissionEmail" | ||
onChange={(event) => { | ||
formik.setFieldValue("submissionEmail", event.target.value); | ||
}} | ||
value={formik.values.submissionEmail ?? ""} | ||
errorMessage={formik.errors.submissionEmail} | ||
id="submissionEmail" | ||
/> | ||
</InputLabel> | ||
</> | ||
} | ||
/> | ||
); | ||
} |
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