Skip to content

Commit

Permalink
Merge pull request #2457 from prefeiturasp/feature/124083-modifica-li…
Browse files Browse the repository at this point in the history
…nk-botao-acomp-pc-dre

feat(124083): Cria parâmetro acesso acompanhamento pc DRE
  • Loading branch information
mdiori authored Dec 27, 2024
2 parents 327cfbb + 7b775c1 commit 659cccd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/componentes/Globais/SidebarLeft/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,15 @@ export const SidebarLeft = () => {
visoesService.forcarNovoLogin();
const to = '/' + selected;
if (history.location.pathname !== to) {
if(sidebarStatus.irParaUrl){
history.push(to)
if (sidebarStatus.irParaUrl) {
if (selected === 'dre-dashboard') {
history.push({
pathname: to,
state: { acessadoPelaSidebar: true },
});
} else {
history.push(to);
}
}
}
}}
Expand Down
20 changes: 16 additions & 4 deletions src/componentes/dres/Dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from "react";
import {Redirect} from 'react-router-dom'
import {Redirect, useLocation} from 'react-router-dom'
import {getPeriodos, getItensDashboard} from "../../../services/dres/Dashboard.service";
import {SelectPeriodo} from "./SelectPeriodo";
import "./dashboard.scss"
Expand All @@ -15,22 +15,34 @@ export const DreDashboard = () => {
const [statusPrestacao, setStatusPrestacao] = useState(false);
const [loading, setLoading] = useState(false);

const location = useLocation();
const acessadoPelaSidebar = location.state?.acessadoPelaSidebar || false;

useEffect(() => {
carregaPeriodos();
}, []);

useEffect(() => {
carregaItensDashboard();
if (periodoEscolhido) {
localStorage.setItem('PERIODO_SELECIONADO_DRE_ACOMPANHAMENTO', periodoEscolhido);
}
}, [periodoEscolhido]);

const carregaPeriodos = async () => {
setLoading(true);
let periodos = await getPeriodos();
setPeriodos(periodos);

const storedPeriodo = localStorage.getItem('PERIODO_SELECIONADO_DRE_ACOMPANHAMENTO');
if (periodos && periodos.length > 0){
//Caso exista mais de um período seleciona por default o anterior ao corrente.
const periodoIndex = periodos.length > 1 ? 1 : 0;
setPeriodoEsolhido(periodos[periodoIndex].uuid)
if(storedPeriodo && !acessadoPelaSidebar) {
setPeriodoEsolhido(storedPeriodo);
} else {
//Caso exista mais de um período seleciona por default o anterior ao corrente.
const periodoIndex = periodos.length > 1 ? 1 : 0;
setPeriodoEsolhido(periodos[periodoIndex].uuid)
}
}
setLoading(false);
};
Expand Down

0 comments on commit 659cccd

Please sign in to comment.