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: Team Settings Editor Form UI Changes #3305

Merged
merged 22 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
575b581
init editor changes to plan ui additions
RODO94 Jun 20, 2024
4b6c683
continue layout and small form additions
RODO94 Jun 20, 2024
15e5e08
changes made to general settings
RODO94 Jun 21, 2024
26a7640
update SettingsForm to make formik optional and add inputs for contac…
RODO94 Jun 21, 2024
1df271e
add homepage and planning portal form
RODO94 Jun 21, 2024
3ccff1f
rename to general settings
RODO94 Jun 21, 2024
f29a19c
nit: change boundary input label
RODO94 Jun 21, 2024
ae06ade
initial wiring of formik config
RODO94 Jun 24, 2024
63ca171
add validation to isPlanningDataCollected bool
RODO94 Jun 24, 2024
3f980d6
remove optional operator from settingsForm type
RODO94 Jun 24, 2024
32c93e0
add error validation as schema to test formik error handling
RODO94 Jun 24, 2024
ca7ec39
nit: remove full width from input label and switch bool default value
RODO94 Jun 24, 2024
3cc93cc
delete temp settings form component
RODO94 Jun 24, 2024
329fec4
remove redundant variable
RODO94 Jun 24, 2024
52a56c0
made changes to comments from Daf@
RODO94 Jun 24, 2024
9c4b56d
remove optional operand from return comp of settingsForm
RODO94 Jun 24, 2024
2f58c27
remove optional operand from return comp of settingsForm
RODO94 Jun 24, 2024
97f6064
revert changes to settingsForm
RODO94 Jun 24, 2024
a0eaeaa
revert changes to store file
RODO94 Jun 24, 2024
0946197
revert changes to store file
RODO94 Jun 24, 2024
8b3c4b7
remove homepage and planning form and move homepage field to contact …
RODO94 Jun 24, 2024
6499098
remove commented out code in route view
RODO94 Jun 24, 2024
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
@@ -0,0 +1,59 @@
import { useFormik } from "formik";
import React, { ChangeEvent } from "react";
import InputDescription from "ui/editor/InputDescription";
import Input from "ui/shared/Input";
import InputRow from "ui/shared/InputRow";
import InputRowLabel from "ui/shared/InputRowLabel";

import { SettingsForm } from "../shared/SettingsForm";
import { FormProps } from ".";

export default function BoundaryForm({ formikConfig, onSuccess }: FormProps) {
const formik = useFormik({
...formikConfig,
onSubmit(values, { resetForm }) {
onSuccess();
resetForm({ values });
},
});

return (
<SettingsForm
formik={formik}
legend="Boundary"
description={
<InputDescription>
The boundary URL is used to retrieve the outer boundary of your
council area. This can then help users define whether they are within
your council area.
<br />
<br />
The boundary should be given as a link from:{" "}
<a
href="https://www.planning.data.gov.uk/"
target="_blank"
rel="noopener noreferrer"
>
https://www.planning.data.gov.uk/
</a>
</InputDescription>
}
input={
<>
<InputRow>
<InputRowLabel>
Boundary URL
<Input
name="boundary"
value={formik.values.boundaryUrl}
onChange={(ev: ChangeEvent<HTMLInputElement>) => {
formik.setFieldValue("boundaryUrl", ev.target.value);
}}
/>
</InputRowLabel>
</InputRow>
</>
}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { useFormik } from "formik";
import React, { ChangeEvent } from "react";
import InputDescription from "ui/editor/InputDescription";
import Input from "ui/shared/Input";
import InputRow from "ui/shared/InputRow";
import InputRowLabel from "ui/shared/InputRowLabel";
import * as Yup from "yup";

import { SettingsForm } from "../shared/SettingsForm";
import { FormProps } from ".";

export default function ContactForm({ formikConfig, onSuccess }: FormProps) {
const formSchema = Yup.object().shape({
helpEmail: Yup.string()
.email("Please enter valid email")
.required("Help Email is required"),
helpPhone: Yup.string().required("Help Phone is required"),
helpOpeningHours: Yup.string(),
homepage: Yup.string().url("Please enter a valid URL for the homepage"),
});

const formik = useFormik({
...formikConfig,
validationSchema: formSchema,
onSubmit(values, { resetForm }) {
onSuccess();
resetForm({ values });
},
});

const onChangeFn = (type: string, event: ChangeEvent<HTMLInputElement>) =>
formik.setFieldValue(type, event.target.value);

return (
<SettingsForm
legend="Contact Information"
formik={formik}
description={
<InputDescription>
Details to help direct different messages, feedback, and enquiries
from users.
</InputDescription>
}
input={
<>
<InputRow>
<InputRowLabel>
Homepage URL
<Input
name="homepage"
onChange={(event) => {
onChangeFn("homepage", event);
}}
/>
</InputRowLabel>
</InputRow>
<InputRow>
<InputRowLabel>
Contact email address
<Input
name="helpEmail"
onChange={(event) => {
onChangeFn("helpEmail", event);
}}
/>
</InputRowLabel>
</InputRow>
<InputRow>
<InputRowLabel>
Phone number
<Input
name="helpPhone"
onChange={(event) => {
onChangeFn("helpPhone", event);
}}
/>
</InputRowLabel>
</InputRow>
<InputRow>
<InputRowLabel>
Opening hours
<Input
multiline
name="helpOpeningHours"
onChange={(event) => {
onChangeFn("helpOpeningHours", event);
}}
/>
</InputRowLabel>
</InputRow>
</>
}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import Alert from "@mui/material/Alert";
import Box from "@mui/material/Box";
import Snackbar from "@mui/material/Snackbar";
import Typography from "@mui/material/Typography";
import { FormikConfig } from "formik";
import React, { useEffect, useState } from "react";
import EditorRow from "ui/editor/EditorRow";

import BoundaryForm from "./BoundaryForm";
import ContactForm from "./ContactForm";

export interface GeneralSettings {
boundaryUrl: string;
helpEmail: string;
helpPhone: string;
helpOpeningHours: string;
homepage: string;
isPlanningDataCollected: boolean;
portalName: string;
portalUrl: string;
}

export interface FormProps {
formikConfig: FormikConfig<GeneralSettings>;
onSuccess: () => void;
}

const GeneralSettings: React.FC = () => {
const [formikConfig, setFormikConfig] = useState<
FormikConfig<GeneralSettings> | undefined
>(undefined);

const initialValues = {
boundaryUrl: "",
helpEmail: "",
helpPhone: "",
helpOpeningHours: "",
homepage: "",
isPlanningDataCollected: true,
portalName: "",
portalUrl: "",
};

useEffect(() => {
const fetchTeam = async () => {
try {
setFormikConfig({
initialValues: initialValues,
onSubmit: () => {},
validateOnBlur: false,
validateOnChange: false,
enableReinitialize: true,
});
} catch (error) {
console.error("Error fetching team:", error);
}
};

fetchTeam();
}, []);

const [open, setOpen] = useState(false);
const [updateMessage, setUpdateMessage] = useState("Setting Updated");

const handleClose = (
_event?: React.SyntheticEvent | Event,
reason?: string,
) => {
if (reason === "clickaway") {
return;
}

setOpen(false);
};

const onSuccess = () => setOpen(true);

return (
<Box maxWidth="formWrap" mx="auto">
<EditorRow>
<Typography variant="h2" component="h3" gutterBottom>
General
</Typography>
<Typography variant="body1">
Important links and settings for how your users connect with you
</Typography>
</EditorRow>
{formikConfig && (
<>
<ContactForm formikConfig={formikConfig} onSuccess={onSuccess} />
<BoundaryForm formikConfig={formikConfig} onSuccess={onSuccess} />
</>
)}
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
<Alert onClose={handleClose} severity="success" sx={{ width: "100%" }}>
{updateMessage}
</Alert>
</Snackbar>
</Box>
);
};

export default GeneralSettings;
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ export const SettingsForm = <TFormikValues,>({
</form>
</EditorRow>
);
};
};
7 changes: 7 additions & 0 deletions editor.planx.uk/src/routes/teamSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
withData,
} from "navi";
import DesignSettings from "pages/FlowEditor/components/Settings/DesignSettings";
import GeneralSettings from "pages/FlowEditor/components/Settings/GeneralSettings";
import TeamSettings from "pages/FlowEditor/components/Settings/TeamSettings";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
Expand All @@ -24,6 +25,7 @@ const teamSettingsRoutes = compose(
"/": redirect("./team"),
"/:tab": map(async (req) => {
const isAuthorised = useStore.getState().canUserEditTeam(req.params.team);

if (!isAuthorised)
throw new NotFoundError(
`User does not have access to ${req.originalUrl}`,
Expand All @@ -45,6 +47,11 @@ const teamSettingsRoutes = compose(
route: "design",
Component: DesignSettings,
},
{
name: "General",
route: "general",
Component: GeneralSettings,
},
]}
/>
),
Expand Down
Loading