-
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.
chore: Make
SettingsForm
shared and generic (#3308)
- Loading branch information
1 parent
fd6112e
commit 0cb8424
Showing
6 changed files
with
78 additions
and
69 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
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
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
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
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
65 changes: 65 additions & 0 deletions
65
editor.planx.uk/src/pages/FlowEditor/components/Settings/shared/SettingsForm.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,65 @@ | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import Typography from "@mui/material/Typography"; | ||
import { FormikProps } from "formik"; | ||
import React from "react"; | ||
import EditorRow from "ui/editor/EditorRow"; | ||
import InputGroup from "ui/editor/InputGroup"; | ||
import InputLegend from "ui/editor/InputLegend"; | ||
import ErrorWrapper from "ui/shared/ErrorWrapper"; | ||
|
||
type SettingsFormProps<TFormikValues> = { | ||
legend: string; | ||
description: React.ReactElement; | ||
input: React.ReactElement; | ||
formik: FormikProps<TFormikValues>; | ||
preview?: React.ReactElement; | ||
}; | ||
|
||
export const SettingsForm = <TFormikValues,>({ | ||
formik, | ||
legend, | ||
description, | ||
input, | ||
preview, | ||
}: SettingsFormProps<TFormikValues>) => { | ||
return ( | ||
<EditorRow background> | ||
<form onSubmit={formik.handleSubmit}> | ||
<InputGroup flowSpacing> | ||
<InputLegend>{legend}</InputLegend> | ||
{description} | ||
{input} | ||
</InputGroup> | ||
{preview && ( | ||
<Box> | ||
<Typography variant="h4" my={1}> | ||
Preview: | ||
</Typography> | ||
{preview} | ||
</Box> | ||
)} | ||
<ErrorWrapper | ||
error={Object.values(formik.errors).join(", ")} | ||
id="settings-error" | ||
> | ||
<Box> | ||
<Button type="submit" variant="contained" disabled={!formik.dirty}> | ||
Save | ||
</Button> | ||
<Button | ||
onClick={() => formik.resetForm()} | ||
type="reset" | ||
variant="contained" | ||
disabled={!formik.dirty} | ||
color="secondary" | ||
sx={{ ml: 1.5 }} | ||
> | ||
Reset changes | ||
</Button> | ||
</Box> | ||
</ErrorWrapper> | ||
</form> | ||
</EditorRow> | ||
); | ||
}; |