-
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(page): Initial setup of Page component (#3675)
- Loading branch information
1 parent
da9aa94
commit 8be0bb9
Showing
15 changed files
with
239 additions
and
7 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,108 @@ | ||
import MenuItem from "@mui/material/MenuItem"; | ||
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types"; | ||
import { useFormik } from "formik"; | ||
import React from "react"; | ||
import ModalSection from "ui/editor/ModalSection"; | ||
import ModalSectionContent from "ui/editor/ModalSectionContent"; | ||
import RichTextInput from "ui/editor/RichTextInput"; | ||
import SelectInput from "ui/editor/SelectInput"; | ||
import Input from "ui/shared/Input"; | ||
import InputRow from "ui/shared/InputRow"; | ||
import InputRowItem from "ui/shared/InputRowItem"; | ||
import InputRowLabel from "ui/shared/InputRowLabel"; | ||
|
||
import { EditorProps, ICONS, InternalNotes, MoreInformation } from "../ui"; | ||
import { Page, parsePage } from "./model"; | ||
import { ProposedAdvertisements } from "./schema/AdvertConsent"; | ||
|
||
type Props = EditorProps<TYPES.Page, Page>; | ||
|
||
export const PAGE_SCHEMAS = [ | ||
{ name: "Advert consent", schema: ProposedAdvertisements }, | ||
] as const; | ||
|
||
function PageComponent(props: Props) { | ||
const formik = useFormik({ | ||
initialValues: parsePage(props.node?.data), | ||
onSubmit: (newValues) => { | ||
props.handleSubmit?.({ | ||
type: TYPES.Page, | ||
data: newValues, | ||
}); | ||
}, | ||
}); | ||
|
||
return ( | ||
<form onSubmit={formik.handleSubmit} id="modal"> | ||
<ModalSection> | ||
<ModalSectionContent title="Page" Icon={ICONS[TYPES.Page]}> | ||
<InputRow> | ||
<Input | ||
format="large" | ||
name="title" | ||
value={formik.values.title} | ||
placeholder="Title" | ||
onChange={formik.handleChange} | ||
required | ||
/> | ||
</InputRow> | ||
<InputRow> | ||
<RichTextInput | ||
placeholder="Description" | ||
name="description" | ||
value={formik.values.description} | ||
onChange={formik.handleChange} | ||
/> | ||
</InputRow> | ||
<InputRow> | ||
<Input | ||
format="data" | ||
name="fn" | ||
value={formik.values.fn} | ||
placeholder="Data Field" | ||
onChange={formik.handleChange} | ||
required | ||
/> | ||
</InputRow> | ||
<InputRow> | ||
<InputRowLabel>Schema</InputRowLabel> | ||
<InputRowItem> | ||
<SelectInput | ||
value={formik.values.schemaName} | ||
onChange={(e) => { | ||
formik.setFieldValue("schemaName", e.target.value); | ||
formik.setFieldValue( | ||
"schema", | ||
PAGE_SCHEMAS.find( | ||
({ name }) => name === (e.target.value as string), | ||
)?.schema, | ||
); | ||
}} | ||
> | ||
{PAGE_SCHEMAS.map(({ name }) => ( | ||
<MenuItem key={name} value={name}> | ||
{name} | ||
</MenuItem> | ||
))} | ||
</SelectInput> | ||
</InputRowItem> | ||
</InputRow> | ||
</ModalSectionContent> | ||
</ModalSection> | ||
<MoreInformation | ||
changeField={formik.handleChange} | ||
definitionImg={formik.values.definitionImg} | ||
howMeasured={formik.values.howMeasured} | ||
policyRef={formik.values.policyRef} | ||
info={formik.values.info} | ||
/> | ||
<InternalNotes | ||
name="notes" | ||
value={formik.values.notes} | ||
onChange={formik.handleChange} | ||
/> | ||
</form> | ||
); | ||
} | ||
|
||
export default PageComponent; |
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 @@ | ||
test.todo("coming soon!"); |
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,41 @@ | ||
import { PublicProps } from "@planx/components/ui"; | ||
import { useFormik } from "formik"; | ||
import React from "react"; | ||
|
||
import Card from "../shared/Preview/Card"; | ||
import CardHeader from "../shared/Preview/CardHeader"; | ||
import { useSchema } from "../shared/Schema/hook"; | ||
import { SchemaFields } from "../shared/Schema/SchemaFields"; | ||
import { getPreviouslySubmittedData } from "../shared/utils"; | ||
import { Page } from "./model"; | ||
|
||
type Props = PublicProps<Page>; | ||
|
||
function PageComponent(props: Props) { | ||
const { formikConfig } = useSchema({ | ||
schema: props.schema, | ||
previousValues: getPreviouslySubmittedData(props), | ||
}); | ||
|
||
const formik = useFormik({ | ||
...formikConfig, | ||
onSubmit: (data) => console.log({ data }), | ||
}); | ||
|
||
return ( | ||
<Card handleSubmit={formik.handleSubmit} isValid> | ||
<CardHeader {...props} /> | ||
<SchemaFields | ||
formik={formik} | ||
schema={props.schema} | ||
sx={(theme) => ({ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: theme.spacing(2), | ||
})} | ||
/> | ||
</Card> | ||
); | ||
} | ||
|
||
export default PageComponent; |
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,27 @@ | ||
import { cloneDeep } from "lodash"; | ||
|
||
import { MoreInformation, parseMoreInformation } from "../shared"; | ||
import { Schema } from "../shared/Schema/model"; | ||
import { PAGE_SCHEMAS } from "./Editor"; | ||
|
||
export interface PageSchema extends Schema { | ||
min: 1; | ||
max: 1; | ||
} | ||
|
||
export interface Page extends MoreInformation { | ||
fn: string; | ||
title: string; | ||
description?: string; | ||
schemaName: string; | ||
schema: PageSchema; | ||
} | ||
|
||
export const parsePage = (data: Record<string, any> | undefined): Page => ({ | ||
fn: data?.fn, | ||
title: data?.title, | ||
description: data?.description, | ||
schemaName: data?.schemaName || PAGE_SCHEMAS[0].name, | ||
schema: cloneDeep(data?.schema) || PAGE_SCHEMAS[0].schema, | ||
...parseMoreInformation(data), | ||
}); |
41 changes: 41 additions & 0 deletions
41
editor.planx.uk/src/@planx/components/Page/schema/AdvertConsent.ts
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,41 @@ | ||
import { PageSchema } from "../model"; | ||
|
||
export const ProposedAdvertisements: PageSchema = { | ||
type: "Proposed advertisements", | ||
fields: [ | ||
{ | ||
type: "number", | ||
data: { | ||
title: "How many fascia signs are you applying for?", | ||
fn: "fascia", | ||
allowNegatives: false, | ||
}, | ||
}, | ||
{ | ||
type: "number", | ||
data: { | ||
title: "How many projecting or hanging signs are you applying for?", | ||
fn: "projecting", | ||
allowNegatives: false, | ||
}, | ||
}, | ||
{ | ||
type: "number", | ||
data: { | ||
title: "How many hoardings are you applying for?", | ||
fn: "hoarding", | ||
allowNegatives: false, | ||
}, | ||
}, | ||
{ | ||
type: "number", | ||
data: { | ||
title: "How many other advertisements are you applying for?", | ||
fn: "other", | ||
allowNegatives: false, | ||
}, | ||
}, | ||
], | ||
min: 1, | ||
max: 1, | ||
} as const; |
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
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