Skip to content
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 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function ContactForm({ formikConfig, onSuccess }: FormProps) {
onChange={(event) => {
onChangeFn("homepage", event);
}}
value={formik.values.homepage}
value={formik.values.homepage ?? ""}
Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Jul 16, 2024

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.

image

errorMessage={formik.errors.homepage}
id="homepage"
/>
Expand Down Expand Up @@ -91,7 +91,6 @@ export default function ContactForm({ formikConfig, onSuccess }: FormProps) {
</InputLabel>
<InputLabel label="Opening hours" htmlFor="helpOpeningHours">
<Input
multiline
name="helpOpeningHours"
value={formik.values.helpOpeningHours}
errorMessage={formik.errors.helpOpeningHours}
Expand Down
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>
</>
}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -62,7 +63,7 @@ const GeneralSettings: React.FC = () => {
<Container maxWidth="formWrap">
<SettingsSection>
<Typography variant="h2" component="h3" gutterBottom>
General
Settings
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Expand All @@ -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}>
Expand Down
Loading