Skip to content

Commit 3c5d447

Browse files
authored
Create pizzaLayout.tsx
1 parent e797464 commit 3c5d447

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, { useEffect } from "react";
2+
import { plugins } from "@webiny/plugins";
3+
import type { CmsContentFormRendererPlugin } from "@webiny/app-headless-cms/types";
4+
import { Alert } from '@webiny/ui/Alert'
5+
import { Grid, Cell } from "@webiny/ui/Grid";
6+
import { Tabs, Tab } from "@webiny/ui/Tabs";
7+
8+
interface LayoutProps {
9+
fields: Record<string, JSX.Element>;
10+
data: Record<string, any>
11+
}
12+
13+
const PizzaLayout = ({ fields, data }: LayoutProps) => {
14+
const priceTooLow = data['price'] < 20 && data['numberOfIngredients'] > 6
15+
16+
return (
17+
<Tabs>
18+
19+
<Tab label="General">
20+
{priceTooLow && (
21+
<Grid>
22+
<Cell span={12}>
23+
<Alert type={'warning'} title={'Please double-check your input'}>
24+
The price of <strong>{data['price']}</strong> seems too low for a pizza with over{' '}
25+
<strong>6</strong> ingredients.
26+
</Alert>
27+
</Cell>
28+
</Grid>
29+
)}
30+
<Grid>
31+
<Cell span={12}>{fields['name']}</Cell>
32+
</Grid>
33+
<Grid>
34+
<Cell span={6}>{fields['price']}</Cell>
35+
<Cell span={6}>{fields['numberOfIngredients']}</Cell>
36+
</Grid>
37+
</Tab>
38+
39+
<Tab label="Recipe">
40+
<Grid>
41+
<Cell span={12}>{fields['recipe']}</Cell>
42+
</Grid>
43+
</Tab>
44+
45+
<Tab label="History">
46+
<Grid>
47+
<Cell span={12}>{fields['history']}</Cell>
48+
</Grid>
49+
</Tab>
50+
</Tabs>
51+
);
52+
};
53+
54+
export const Extension = () => {
55+
useEffect(() => {
56+
const layoutPlugin: CmsContentFormRendererPlugin = {
57+
type: "cms-content-form-renderer",
58+
modelId: "pizza",
59+
render(props) {
60+
return <PizzaLayout {...props} />;
61+
},
62+
};
63+
64+
plugins.register(layoutPlugin);
65+
}, []);
66+
67+
return null;
68+
};

0 commit comments

Comments
 (0)