From 8c1baca866bc1827eaeb5680f13af347183ed3d3 Mon Sep 17 00:00:00 2001 From: samoel-silva Date: Thu, 19 Sep 2024 17:31:07 -0300 Subject: [PATCH] Exercicio 39.3: Conecta action de listSecretarias a view do bloco --- .../Blocks/SecretariasBlock/View.jsx | 21 +++++++++++++++++-- .../src/reducers/secretarias/secretarias.js | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/frontend/packages/volto-portal-governo/src/components/Blocks/SecretariasBlock/View.jsx b/frontend/packages/volto-portal-governo/src/components/Blocks/SecretariasBlock/View.jsx index ba4ebe2..42642e3 100644 --- a/frontend/packages/volto-portal-governo/src/components/Blocks/SecretariasBlock/View.jsx +++ b/frontend/packages/volto-portal-governo/src/components/Blocks/SecretariasBlock/View.jsx @@ -1,10 +1,27 @@ -import React from 'react'; +import React, { useEffect } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; import { withBlockExtensions } from '@plone/volto/helpers'; +import { listSecretarias } from '../../../actions/secretarias/secretarias'; import SecretariasView from './DefaultView'; + const SecretariasBlockView = (props) => { const { data, isEditMode, className } = props; + const dispatch = useDispatch(); + const secretarias = useSelector((state) => state.secretarias?.data); + // Dispara chamada na criação da constante dispatch + + useEffect(() => { + dispatch(listSecretarias()); + }, [dispatch]); + return ( - + ); }; + export default withBlockExtensions(SecretariasBlockView); diff --git a/frontend/packages/volto-portal-governo/src/reducers/secretarias/secretarias.js b/frontend/packages/volto-portal-governo/src/reducers/secretarias/secretarias.js index b51ba67..22bfbb3 100644 --- a/frontend/packages/volto-portal-governo/src/reducers/secretarias/secretarias.js +++ b/frontend/packages/volto-portal-governo/src/reducers/secretarias/secretarias.js @@ -16,7 +16,7 @@ export default function secretarias(state = initialState, action = {}) { case `${LIST_SECRETARIAS}_SUCCESS`: return { ...state, - data: action.result, + data: action.result.items, error: null, }; case `${LIST_SECRETARIAS}_FAIL`: