Skip to content

Commit

Permalink
Use new field components (#157)
Browse files Browse the repository at this point in the history
Use new field components to simplify forms

---------

Co-authored-by: Julia Wegmayr <julia.wegmayr@vivid-planet.com>
  • Loading branch information
juliawegmayr and juliawegmayr authored Feb 13, 2024
1 parent a395cc9 commit c072ada
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
28 changes: 12 additions & 16 deletions admin/src/common/blocks/HeadlineBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, FinalFormSelect } from "@comet/admin";
import { SelectField } from "@comet/admin";
import { BlockCategory, BlocksFinalForm, createCompositeBlock, createCompositeSetting } from "@comet/blocks-admin";
import { createRichTextBlock } from "@comet/cms-admin";
import { MenuItem } from "@mui/material";
Expand Down Expand Up @@ -32,21 +32,17 @@ export const HeadlineBlock = createCompositeBlock({
defaultValue: "header-one",
AdminComponent: ({ state, updateState }) => (
<BlocksFinalForm<Pick<HeadlineBlockData, "level">> onSubmit={({ level }) => updateState(level)} initialValues={{ level: state }}>
<Field name="level" label={<FormattedMessage id="headlineBlock.level" defaultMessage="Level" />} fullWidth>
{(props) => (
<FinalFormSelect {...props}>
<MenuItem value="header-one">
<FormattedMessage id="headlineBlock.headerOne" defaultMessage="Header One" />
</MenuItem>
<MenuItem value="header-two">
<FormattedMessage id="headlineBlock.headerTwo" defaultMessage="Header Two" />
</MenuItem>
<MenuItem value="header-three">
<FormattedMessage id="headlineBlock.headerThree" defaultMessage="Header Three" />
</MenuItem>
</FinalFormSelect>
)}
</Field>
<SelectField name="level" label={<FormattedMessage id="headlineBlock.level" defaultMessage="Level" />} fullWidth>
<MenuItem value="header-one">
<FormattedMessage id="headlineBlock.headerOne" defaultMessage="Header One" />
</MenuItem>
<MenuItem value="header-two">
<FormattedMessage id="headlineBlock.headerTwo" defaultMessage="Header Two" />
</MenuItem>
<MenuItem value="header-three">
<FormattedMessage id="headlineBlock.headerThree" defaultMessage="Header Three" />
</MenuItem>
</SelectField>
</BlocksFinalForm>
),
}),
Expand Down
17 changes: 4 additions & 13 deletions admin/src/products/ProductForm.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useMutation, useQuery } from "@apollo/client";
import {
Field,
FinalForm,
FinalFormInput,
FinalFormSaveSplitButton,
Loading,
MainContent,
TextAreaField,
TextField,
Toolbar,
ToolbarActions,
ToolbarBackButton,
Expand Down Expand Up @@ -77,20 +77,11 @@ export function ProductForm({ id }: FormProps): React.ReactElement {
<MainContent>
<Card>
<CardContent>
<Field
<TextField required fullWidth name="name" label={intl.formatMessage({ id: "products.name", defaultMessage: "Name" })} />
<TextAreaField
required
fullWidth
name="name"
component={FinalFormInput}
label={intl.formatMessage({ id: "products.name", defaultMessage: "Name" })}
/>
<Field
required
fullWidth
multiline
rows={5}
name="description"
component={FinalFormInput}
label={intl.formatMessage({ id: "products.description", defaultMessage: "Description" })}
/>
</CardContent>
Expand Down

0 comments on commit c072ada

Please sign in to comment.