-
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.
feat: Add refernce code field to team settings
- Loading branch information
1 parent
32b3b81
commit f66baf2
Showing
3 changed files
with
87 additions
and
3 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
80 changes: 80 additions & 0 deletions
80
...r.planx.uk/src/pages/FlowEditor/components/Settings/GeneralSettings/ReferenceCodeForm.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,80 @@ | ||
import Link from "@mui/material/Link"; | ||
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 ReferenceCodeForm({ | ||
formikConfig, | ||
onSuccess, | ||
}: FormProps) { | ||
const formSchema = Yup.object().shape({ | ||
referenceCode: Yup.string() | ||
.min(3, "Code must be 3 characters long") | ||
.max(3, "Code must be 3 characters long") | ||
.required("Enter a reference code"), | ||
}); | ||
|
||
const formik = useFormik({ | ||
...formikConfig, | ||
validationSchema: formSchema, | ||
onSubmit: async (values, { resetForm }) => { | ||
const isSuccess = await useStore.getState().updateTeamSettings({ | ||
referenceCode: values.referenceCode, | ||
}); | ||
if (isSuccess) { | ||
onSuccess(); | ||
resetForm({ values }); | ||
} | ||
}, | ||
}); | ||
|
||
const onChangeFn = (type: string, event: ChangeEvent<HTMLInputElement>) => | ||
formik.setFieldValue(type, event.target.value.toUpperCase()); | ||
|
||
return ( | ||
<SettingsForm | ||
legend="Local authority reference code" | ||
formik={formik} | ||
description={ | ||
<> | ||
<Typography variant="body2"> | ||
Your local authority reference code is required for submissions. | ||
This is a unique three-letter code per local authority. | ||
</Typography> | ||
<Typography variant="body2"> | ||
The reference code can be found from Planning Data at:{" "} | ||
<Link | ||
href="https://www.planning.data.gov.uk/entity/?dataset=local-authority" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
https://www.planning.data.gov.uk/entity/?dataset=local-authority | ||
</Link> | ||
</Typography> | ||
</> | ||
} | ||
input={ | ||
<> | ||
<InputLabel label="Reference code" htmlFor="referenceCode"> | ||
<Input | ||
name="referenceCode" | ||
onChange={(event) => { | ||
onChangeFn("referenceCode", event); | ||
}} | ||
value={formik.values.referenceCode ?? ""} | ||
errorMessage={formik.errors.referenceCode} | ||
id="homepage" | ||
/> | ||
</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