From 555215ff58257bbf8bed6fcad0c84241a8bcb774 Mon Sep 17 00:00:00 2001 From: samoel-silva Date: Thu, 19 Sep 2024 14:34:57 -0300 Subject: [PATCH] Exercicio 36.2: Bloco Gestor --- .../components/Blocks/GestorBlock/Data.jsx | 30 +++++++++++++++++++ .../Blocks/GestorBlock/DefaultView.jsx | 4 +-- .../components/Blocks/GestorBlock/Edit.jsx | 20 +++++++++++-- .../components/Blocks/GestorBlock/View.jsx | 11 +++++-- .../components/Blocks/GestorBlock/schema.js | 19 ++++++++++++ .../volto-portal-governo/src/index.js | 1 + 6 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Data.jsx create mode 100644 frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/schema.js diff --git a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Data.jsx b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Data.jsx new file mode 100644 index 0000000..4dbfccb --- /dev/null +++ b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Data.jsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { BlockDataForm } from '@plone/volto/components'; +import { gestorSchema } from './schema'; +import { useIntl } from 'react-intl'; +const GestorBlockData = (props) => { + const { data, block, onChangeBlock, blocksConfig, navRoot, contentType } = + props; + const intl = useIntl(); + const schema = gestorSchema({ ...props, intl }); + const onChangeField = (id, value) => { + onChangeBlock(block, { + ...data, + [id]: value, + }); + }; + return ( + + ); +}; +export default GestorBlockData; diff --git a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/DefaultView.jsx b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/DefaultView.jsx index c1d5f94..676e362 100644 --- a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/DefaultView.jsx +++ b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/DefaultView.jsx @@ -2,10 +2,10 @@ import React from 'react'; import { Container } from '@plone/components'; import GestorCard from '../../Gestor/GestorCard'; -const GestorView = ({ content }) => { +const GestorView = ({ content, data }) => { return ( -

Secretário

+

{data.headline}

); diff --git a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Edit.jsx b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Edit.jsx index 1191e69..af0313b 100644 --- a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Edit.jsx +++ b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Edit.jsx @@ -1,8 +1,24 @@ import React from 'react'; -import View from './View'; +import { withBlockExtensions } from '@plone/volto/helpers'; +import { SidebarPortal } from '@plone/volto/components'; + +import GestorBlockData from './Data'; +import GestorBlockView from './View'; const Edit = (props) => { - return ; + const { data, onChangeBlock, block, selected } = props; + return ( + <> + + + + + + ); }; export default Edit; diff --git a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/View.jsx b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/View.jsx index 918ae78..f8b1c85 100644 --- a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/View.jsx +++ b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/View.jsx @@ -1,10 +1,17 @@ import React from 'react'; +import { Container } from '@plone/components'; import GestorView from './DefaultView'; const View = (props) => { - const { properties } = props; + const { data, isEditMode, properties } = props; const gestor = properties.gestor; - return ; + return gestor ? ( + + ) : ( + + {isEditMode && Por favor selecione um gestor.} + + ); }; export default View; diff --git a/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/schema.js b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/schema.js new file mode 100644 index 0000000..ce8dd75 --- /dev/null +++ b/frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/schema.js @@ -0,0 +1,19 @@ +export const gestorSchema = (props) => { + return { + title: 'Bloco do Gestor', + fieldsets: [ + { + id: 'default', + title: 'Default', + fields: ['headline'], + }, + ], + properties: { + headline: { + title: 'Chamada do bloco', + default: 'Secretário', + }, + }, + required: ['headline'], + }; +}; diff --git a/frontend/packages/volto-portal-governo/src/index.js b/frontend/packages/volto-portal-governo/src/index.js index 4c77a2c..422da67 100644 --- a/frontend/packages/volto-portal-governo/src/index.js +++ b/frontend/packages/volto-portal-governo/src/index.js @@ -37,6 +37,7 @@ const applyConfig = (config) => { icon: gestorSVG, edit: GestorEdit, view: GestorView, + sidebarTab: 1, }; return config;