Skip to content

Commit

Permalink
Merge pull request #2407 from prefeiturasp/feature/33155-parametrizac…
Browse files Browse the repository at this point in the history
…oes-repasse-parte-2

feat(33155): Parametrizacoes repasse
  • Loading branch information
Lucas-Santos-Rocha-dev authored May 14, 2024
2 parents 0e6461c + bf43fc0 commit d2e5b59
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as yup from "yup";

export const YupSchemaRepasse = yup.object().shape({
associacao: yup.string().required("Unidade é obrigatório."),
conta_associacao: yup.string().required("Conta é obrigatório."),
acao_associacao: yup.string().required("Ação é obrigatório."),
periodo: yup.string().required("Período é obrigatório."),
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ import { getAssociacoes } from "../../../../../../services/sme/Parametrizacoes.s
import { useGetRepasses } from "../hooks/useGetRepasses";
import { usePostRepasse } from "../hooks/usePostRepasse";
import { usePatchRepasse } from "../hooks/usePatchRepasse";
import { useDeleteRepasse } from "../hooks/useDeleteRepasse";

import ReactTooltip from "react-tooltip";
import { round, trataNumericos } from "../../../../../../utils/ValidacoesAdicionaisFormularios";

import { faEdit } from "@fortawesome/free-solid-svg-icons";
import Loading from "../../../../../../utils/Loading";
import { ModalForm } from "./ModalForm";
import { ModalConfirmacaoExclusao } from "./ModalConfirmacaoExclusao";

export const Lista = () => {

const { setShowModalForm, stateFormModal, setStateFormModal, setBloquearBtnSalvarForm, showModalConfirmacaoExclusao } = useContext(RepassesContext)
const { setShowModalForm, stateFormModal, setStateFormModal, setBloquearBtnSalvarForm } = useContext(RepassesContext)
const { isLoading, data, count } = useGetRepasses()

const { mutationPost } = usePostRepasse();
const { mutationPatch } = usePatchRepasse();
const { mutationDelete } = useDeleteRepasse()

// Este trecho é responsável pelo auto complete de unidades
const [todasAsAssociacoesAutoComplete, setTodasAsAssociacoesAutoComplete] = useState([]);
Expand Down Expand Up @@ -107,6 +110,14 @@ export const Lista = () => {
}
};

const handleExcluirRepasse = async (uuid) => {
if (!uuid) {
console.log("Erro ao tentar excluir o repasse.")
} else {
mutationDelete.mutate(uuid)
}
}

const acoesTemplate = (rowData) => {
return (
<div>
Expand All @@ -124,15 +135,30 @@ export const Lista = () => {
};

const valorCapitalTemplate = (rowData) => {
return `R$ ${rowData.valor_capital}`
let valor_capital = rowData.valor_capital ? Number(rowData.valor_capital).toLocaleString('pt-BR', {
style: 'currency',
currency: 'BRL'
}) : ""

return valor_capital;
}

const valorCusteioTemplate = (rowData) => {
return `R$ ${rowData.valor_custeio}`
let valor_custeio = rowData.valor_custeio ? Number(rowData.valor_custeio).toLocaleString('pt-BR', {
style: 'currency',
currency: 'BRL'
}) : ""

return valor_custeio;
}

const valorLivreTemplate = (rowData) => {
return `R$ ${rowData.valor_livre}`
let valor_livre = rowData.valor_livre ? Number(rowData.valor_livre).toLocaleString('pt-BR', {
style: 'currency',
currency: 'BRL'
}) : ""

return valor_livre;
}

const statusTemplate = (rowData) => {
Expand Down Expand Up @@ -196,6 +222,12 @@ export const Lista = () => {
loadingAssociacoes={loadingAssociacoes}
/>
</section>

<section>
<ModalConfirmacaoExclusao
handleExcluirRepasse={handleExcluirRepasse}
/>
</section>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useContext } from "react";
import { ModalBootstrap } from "../../../../../Globais/ModalBootstrap";
import { RepassesContext } from "../context/Repasse";

export const ModalConfirmacaoExclusao = ({handleExcluirRepasse}) => {

const {showModalConfirmacaoExclusao, setShowModalConfirmacaoExclusao, stateFormModal} = useContext(RepassesContext)

return(
<ModalBootstrap
show={showModalConfirmacaoExclusao}
onHide={setShowModalConfirmacaoExclusao}
titulo="Excluir repasse"
bodyText="Deseja realmente excluir esse repasse?"
primeiroBotaoOnclick={() => setShowModalConfirmacaoExclusao(false)}
primeiroBotaoTexto="Voltar"
primeiroBotaoCss="outline-success"
segundoBotaoOnclick={()=> {
setShowModalConfirmacaoExclusao(false)
handleExcluirRepasse(stateFormModal.uuid)
}}
segundoBotaoCss="danger"
segundoBotaoTexto="Excluir"
/>
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ModalFormBodyText } from "../../../../../Globais/ModalBootstrap";
import { RepassesContext } from "../context/Repasse";
import { useGetTabelasRepasse } from "../hooks/useGetTabelasRepasse";
import { useGetTabelasPorAssociacao } from "../hooks/useGetTabelasPorAssociacao";
import { useGetUnidadesAutoComplete } from "../hooks/useGetUnidadesAutoComplete";
import ReactTooltip from "react-tooltip";

import { RetornaSeTemPermissaoEdicaoPainelParametrizacoes } from "../../../../Parametrizacoes/RetornaSeTemPermissaoEdicaoPainelParametrizacoes";
import { ReactNumberFormatInput as CurrencyInput } from "../../../../../Globais/ReactNumberFormatInput";
import { trataNumericos } from "../../../../../../utils/ValidacoesAdicionaisFormularios";
import Spinner from "../../../../../../assets/img/spinner.gif"
import AutoCompleteAssociacoes from "./AutoCompleteAssociacoes";
import { YupSchemaRepasse } from "../YupSchemaRepasse";

export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete, loadingAssociacoes}) => {
const TEM_PERMISSAO_EDICAO_PAINEL_PARAMETRIZACOES = RetornaSeTemPermissaoEdicaoPainelParametrizacoes()
Expand All @@ -20,12 +20,6 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
const { data: tabelas } = useGetTabelasRepasse();
const { data: tabelas_por_associacao } = useGetTabelasPorAssociacao();

const handleChangeFormModal = (name, value) => {
setStateFormModal({
...stateFormModal,
[name]: value,
});
};

const campo_editavel = (campo) => {
if(!TEM_PERMISSAO_EDICAO_PAINEL_PARAMETRIZACOES){
Expand All @@ -44,6 +38,7 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
<>
<Formik
initialValues={stateFormModal}
validationSchema={YupSchemaRepasse}
enableReinitialize={true}
validateOnChange={false}
validateOnBlur={false}
Expand All @@ -60,6 +55,7 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
{stateFormModal.uuid
?
<div className='form-group col-md-12'>
<p className='text-right mb-0'>* Preenchimento obrigatório</p>
<label htmlFor="unidade_educacional">Unidade Educacional *</label>
<input
value={values.nome_unidade}
Expand All @@ -73,6 +69,7 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
</div>
:
<div className="form-group col-md-12">
<p className='text-right mb-0'>* Preenchimento obrigatório</p>
<label htmlFor="unidade_educacional">Unidade Educacional *{loadingAssociacoes && <img alt="" src={Spinner} style={{height: "22px"}}/>}</label>
<AutoCompleteAssociacoes
todasAsAssociacoesAutoComplete={todasAsAssociacoesAutoComplete}
Expand All @@ -81,13 +78,14 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
loadingAssociacoes={loadingAssociacoes}

/>
{props.touched.associacao && props.errors.associacao && <span className="span_erro text-danger mt-1"> {props.errors.associacao}</span>}
</div>
}
</div>

<div className="form-row">
<div className="form-group col-md-4">
<label htmlFor="valor_capital">Valor capital</label>
<label htmlFor="valor_capital">Valor capital *</label>
<CurrencyInput
disabled={!campo_editavel("valor_capital")}
allowNegative={false}
Expand All @@ -107,7 +105,7 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
</div>

<div className="form-group col-md-4">
<label htmlFor="valor_custeio">Valor custeio</label>
<label htmlFor="valor_custeio">Valor custeio *</label>
<CurrencyInput
disabled={!campo_editavel("valor_custeio")}
allowNegative={false}
Expand All @@ -127,7 +125,7 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
</div>

<div className="form-group col-md-4">
<label htmlFor="valor_livre">Valor livre aplicação</label>
<label htmlFor="valor_livre">Valor livre aplicação *</label>
<CurrencyInput
disabled={!campo_editavel("valor_livre")}
allowNegative={false}
Expand All @@ -149,7 +147,7 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete

<div className="form-row">
<div className="form-group col-md-6">
<label htmlFor="conta_associacao">Conta</label>
<label htmlFor="conta_associacao">Conta *</label>
<select
disabled={!campo_editavel("campos_identificacao") || !stateFormModal.associacao}
value={values.conta_associacao}
Expand All @@ -163,10 +161,11 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
<option key={conta_associacao.uuid} value={conta_associacao.uuid}>{conta_associacao.nome}</option>
)}
</select>
{props.touched.conta_associacao && props.errors.conta_associacao && <span className="span_erro text-danger mt-1"> {props.errors.conta_associacao}</span>}
</div>

<div className="form-group col-md-6">
<label htmlFor="acao_associacao">Ação</label>
<label htmlFor="acao_associacao">Ação *</label>
<select
disabled={!campo_editavel("campos_identificacao") || !stateFormModal.associacao}
value={values.acao_associacao}
Expand All @@ -180,12 +179,13 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
<option key={acao_associacao.uuid} value={acao_associacao.uuid}>{acao_associacao.nome}</option>
)}
</select>
{props.touched.acao_associacao && props.errors.acao_associacao && <span className="span_erro text-danger mt-1"> {props.errors.acao_associacao}</span>}
</div>
</div>

<div className="form-row">
<div className="form-group col-md-6">
<label htmlFor="periodo">Período</label>
<label htmlFor="periodo">Período *</label>
<select
disabled={!campo_editavel("campos_identificacao")}
value={values.periodo}
Expand All @@ -199,10 +199,11 @@ export const ModalForm = ({handleSubmitFormModal, todasAsAssociacoesAutoComplete
<option key={periodo.uuid} value={periodo.uuid}>{periodo.referencia}</option>
)}
</select>
{props.touched.periodo && props.errors.periodo && <span className="span_erro text-danger mt-1"> {props.errors.periodo}</span>}
</div>

<div className="form-group col-md-6">
<label htmlFor="status">Status</label>
<label htmlFor="status">Status *</label>
<select
disabled={!campo_editavel("campos_identificacao")}
value={values.status}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const useDeleteRepasse = () => {
toastCustom.ToastCustomSuccess('Exclusão do repasse realizada com sucesso', `O repasse foi excluído com sucesso.`);
},
onError: (error) => {
toastCustom.ToastCustomError('Erro ao apagar o repasse', `Não foi possível apagar o repasse`)
let data = error.response.data
let mensagem = data.mensagem ? data.mensagem : 'Não foi possível apagar o repasse'
toastCustom.ToastCustomError('Erro ao apagar o repasse', mensagem)
console.log("Erro ao apagar o repasse", error.response);
},
onSettled: () => {
Expand Down

This file was deleted.

0 comments on commit d2e5b59

Please sign in to comment.