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(page): Editor modal #3676

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
86 changes: 83 additions & 3 deletions editor.planx.uk/src/@planx/components/Page/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
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 } from "../ui";
import { EditorProps, ICONS, InternalNotes, MoreInformation } from "../ui";
import { Page, parsePage } from "./model";
import { ProposedAdvertisements } from "./schema/AdvertConsent";

type Props = EditorProps<TYPES.Page, Page>;

export default PageComponent;
export const PAGE_SCHEMAS = [
{ name: "Advert consent", schema: ProposedAdvertisements },
] as const;

function PageComponent(props: Props) {
const formik = useFormik({
Expand All @@ -22,7 +34,75 @@ function PageComponent(props: Props) {

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;
19 changes: 18 additions & 1 deletion editor.planx.uk/src/@planx/components/Page/model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +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;
}
Comment on lines +7 to +10
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 enforces that Pages can only have one item, whilst allowing us to re-use all logic from useSchema()


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 || "",
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 editor.planx.uk/src/@planx/components/Page/schema/AdvertConsent.ts
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;
Loading