-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add reference code field to team settings #3431
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import SettingsSection from "ui/editor/SettingsSection"; | |
|
||
import BoundaryForm from "./BoundaryForm"; | ||
import ContactForm from "./ContactForm"; | ||
import ReferenceCodeForm from "./ReferenceCodeForm"; | ||
|
||
export interface FormProps { | ||
formikConfig: FormikConfig<TeamSettings>; | ||
|
@@ -62,7 +63,7 @@ const GeneralSettings: React.FC = () => { | |
<Container maxWidth="formWrap"> | ||
<SettingsSection> | ||
<Typography variant="h2" component="h3" gutterBottom> | ||
General | ||
Settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now matches the new Editor menu. |
||
</Typography> | ||
<Typography variant="body1"> | ||
Important links and settings for how your users connect with you. | ||
|
@@ -72,6 +73,10 @@ const GeneralSettings: React.FC = () => { | |
<> | ||
<ContactForm formikConfig={formikConfig} onSuccess={onSuccess} /> | ||
<BoundaryForm formikConfig={formikConfig} onSuccess={onSuccess} /> | ||
<ReferenceCodeForm | ||
formikConfig={formikConfig} | ||
onSuccess={onSuccess} | ||
/> | ||
</> | ||
)} | ||
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Homepage is nullable, this resolves a Formik warning.