Skip to content

Commit cf05804

Browse files
committed
fix: update example
1 parent ad1cdcb commit cf05804

File tree

5 files changed

+82
-71
lines changed

5 files changed

+82
-71
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "custom-cms-entry-form-layout",
3+
"main": "src/index.tsx",
4+
"version": "1.0.0",
5+
"keywords": [
6+
"webiny-extension",
7+
"webiny-extension-type:admin"
8+
],
9+
"dependencies": {
10+
"@webiny/app-serverless-cms": "0.0.0",
11+
"@webiny/app-headless-cms": "0.0.0",
12+
"@webiny/ui": "0.0.0",
13+
"react": "18.2.0"
14+
}
15+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from "react";
2+
import { useSecurity } from "@webiny/app-serverless-cms";
3+
import { CmsContentFormRendererPlugin } from "@webiny/app-headless-cms";
4+
import { Grid, Cell } from "@webiny/ui/Grid";
5+
import { Tabs, Tab } from "@webiny/ui/Tabs";
6+
import { Alert } from "@webiny/ui/Alert";
7+
8+
type CmsContentFormRendererProps = React.ComponentProps<typeof CmsContentFormRendererPlugin>;
9+
10+
const PizzaLayout: CmsContentFormRendererProps["render"] = ({ fields, data }) => {
11+
// Access security identity.
12+
const { getPermission } = useSecurity();
13+
14+
// Get the necessary permission.
15+
const bakeryPermission = getPermission("bakery");
16+
17+
// Check if the user has the permission to edit a recipe.
18+
const canEditRecipe = bakeryPermission && bakeryPermission["canEditRecipe"] === true;
19+
20+
const priceTooLow = data["price"] < 20 && data["numberOfIngredients"] > 6;
21+
22+
return (
23+
<Tabs>
24+
<Tab label="General">
25+
{priceTooLow && (
26+
<Grid>
27+
<Cell span={12}>
28+
<Alert type={"warning"} title={"Please double-check your input"}>
29+
The price of <strong>{data["price"]}</strong> seems too low for a
30+
pizza with over <strong>6</strong> ingredients.
31+
</Alert>
32+
</Cell>
33+
</Grid>
34+
)}
35+
36+
<Grid>
37+
<Cell span={12}>{fields["name"]}</Cell>
38+
</Grid>
39+
<Grid>
40+
<Cell span={6}>{fields["price"]}</Cell>
41+
<Cell span={6}>{fields["numberOfIngredients"]}</Cell>
42+
</Grid>
43+
</Tab>
44+
{/* Hide the Recipe tab if the user doesn't have the required permission. */}
45+
{canEditRecipe && (
46+
<Tab label="Recipe">
47+
<Grid>
48+
<Cell span={12}>{fields["recipe"]}</Cell>
49+
</Grid>
50+
</Tab>
51+
)}
52+
<Tab label="History">
53+
<Grid>
54+
<Cell span={12}>{fields["history"]}</Cell>
55+
</Grid>
56+
</Tab>
57+
</Tabs>
58+
);
59+
};
60+
61+
export const Extension = () => {
62+
return (
63+
<>
64+
<CmsContentFormRendererPlugin modelId="pizza" render={PizzaLayout} />
65+
</>
66+
);
67+
};

custom-cms-entry-form-layout/extensions/customCmsEntryFormLayout/package.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

custom-cms-entry-form-layout/extensions/customCmsEntryFormLayout/src/index.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)