Skip to content

Commit

Permalink
Exercicio 36.2: Bloco Gestor
Browse files Browse the repository at this point in the history
  • Loading branch information
samoel-silva committed Sep 19, 2024
1 parent 5ed9166 commit 555215f
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<BlockDataForm
schema={schema}
title={schema.title}
onChangeField={onChangeField}
onChangeBlock={onChangeBlock}
formData={data}
block={block}
blocksConfig={blocksConfig}
navRoot={navRoot}
contentType={contentType}
/>
);
};
export default GestorBlockData;
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container narrow className={`block gestor`}>
<h2 className="headline">Secretário</h2>
<h2 className="headline">{data.headline}</h2>
<GestorCard content={content} />
</Container>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import React from 'react';
import View from './View';
import { withBlockExtensions } from '@plone/volto/helpers';

Check warning on line 2 in frontend/packages/volto-portal-governo/src/components/Blocks/GestorBlock/Edit.jsx

View workflow job for this annotation

GitHub Actions / code-analysis

'withBlockExtensions' is defined but never used
import { SidebarPortal } from '@plone/volto/components';

import GestorBlockData from './Data';
import GestorBlockView from './View';

const Edit = (props) => {
return <View {...props} />;
const { data, onChangeBlock, block, selected } = props;
return (
<>
<GestorBlockView {...props} isEditMode />
<SidebarPortal selected={selected}>
<GestorBlockData
data={data}
block={block}
onChangeBlock={onChangeBlock}
/>
</SidebarPortal>
</>
);
};

export default Edit;
Original file line number Diff line number Diff line change
@@ -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 <GestorView content={gestor} />;
return gestor ? (
<GestorView content={gestor} data={data} />
) : (
<Container narrow className={'block gestor empty'}>
{isEditMode && <span>Por favor selecione um gestor.</span>}
</Container>
);
};

export default View;
Original file line number Diff line number Diff line change
@@ -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'],
};
};
1 change: 1 addition & 0 deletions frontend/packages/volto-portal-governo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const applyConfig = (config) => {
icon: gestorSVG,
edit: GestorEdit,
view: GestorView,
sidebarTab: 1,
};

return config;
Expand Down

0 comments on commit 555215f

Please sign in to comment.