-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e797464
commit 3c5d447
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
headless-cms/partner-eval-guide/customLayoutExample/pizzaLayout.tsx
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,68 @@ | ||
import React, { useEffect } from "react"; | ||
import { plugins } from "@webiny/plugins"; | ||
import type { CmsContentFormRendererPlugin } from "@webiny/app-headless-cms/types"; | ||
import { Alert } from '@webiny/ui/Alert' | ||
import { Grid, Cell } from "@webiny/ui/Grid"; | ||
import { Tabs, Tab } from "@webiny/ui/Tabs"; | ||
|
||
interface LayoutProps { | ||
fields: Record<string, JSX.Element>; | ||
data: Record<string, any> | ||
} | ||
|
||
const PizzaLayout = ({ fields, data }: LayoutProps) => { | ||
const priceTooLow = data['price'] < 20 && data['numberOfIngredients'] > 6 | ||
|
||
return ( | ||
<Tabs> | ||
|
||
<Tab label="General"> | ||
{priceTooLow && ( | ||
<Grid> | ||
<Cell span={12}> | ||
<Alert type={'warning'} title={'Please double-check your input'}> | ||
The price of <strong>{data['price']}</strong> seems too low for a pizza with over{' '} | ||
<strong>6</strong> ingredients. | ||
</Alert> | ||
</Cell> | ||
</Grid> | ||
)} | ||
<Grid> | ||
<Cell span={12}>{fields['name']}</Cell> | ||
</Grid> | ||
<Grid> | ||
<Cell span={6}>{fields['price']}</Cell> | ||
<Cell span={6}>{fields['numberOfIngredients']}</Cell> | ||
</Grid> | ||
</Tab> | ||
|
||
<Tab label="Recipe"> | ||
<Grid> | ||
<Cell span={12}>{fields['recipe']}</Cell> | ||
</Grid> | ||
</Tab> | ||
|
||
<Tab label="History"> | ||
<Grid> | ||
<Cell span={12}>{fields['history']}</Cell> | ||
</Grid> | ||
</Tab> | ||
</Tabs> | ||
); | ||
}; | ||
|
||
export const Extension = () => { | ||
useEffect(() => { | ||
const layoutPlugin: CmsContentFormRendererPlugin = { | ||
type: "cms-content-form-renderer", | ||
modelId: "pizza", | ||
render(props) { | ||
return <PizzaLayout {...props} />; | ||
}, | ||
}; | ||
|
||
plugins.register(layoutPlugin); | ||
}, []); | ||
|
||
return null; | ||
}; |