From 7db8830c433840a414a6ffe81830e1adae189a50 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Mon, 15 Aug 2022 18:34:23 -0300 Subject: [PATCH] fixing --- .../AccumulatedEconomyTitle.tsx | 2 +- .../graph/cativoXLivreChart/index.tsx | 58 +---------------- .../graph/costIndicatorChart/index.tsx | 10 +-- .../graph/grossAnualChart/GrossAnualChart.tsx | 2 +- .../grossMensalChart/GrossMensalChart.tsx | 63 ++----------------- src/pages/dashboard/index.tsx | 4 +- src/pages/economy/index.tsx | 8 ++- src/pages/index.tsx | 15 +++++ 8 files changed, 36 insertions(+), 126 deletions(-) diff --git a/src/components/accumulatedEconomyTitle/AccumulatedEconomyTitle.tsx b/src/components/accumulatedEconomyTitle/AccumulatedEconomyTitle.tsx index d6e74ba..a0ea411 100644 --- a/src/components/accumulatedEconomyTitle/AccumulatedEconomyTitle.tsx +++ b/src/components/accumulatedEconomyTitle/AccumulatedEconomyTitle.tsx @@ -2,5 +2,5 @@ import React from 'react' import { AccumulatedEconomyTitleView } from './AccumulatedEconomyTitleView' export default function AccumulatedEconomyTitle({value}: {value: string}) { - return Economia Acumulada:

R${value}

+ return Economia Acumulada:

R${parseFloat(value).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}

} diff --git a/src/components/graph/cativoXLivreChart/index.tsx b/src/components/graph/cativoXLivreChart/index.tsx index 087aeff..ebbc830 100644 --- a/src/components/graph/cativoXLivreChart/index.tsx +++ b/src/components/graph/cativoXLivreChart/index.tsx @@ -13,6 +13,7 @@ import { Chart } from 'react-chartjs-2'; import { CativoXLivreChartView } from './CativoXLivreChartView'; import ChartTitle from '../ChartTitle'; import pattern from 'patternomaly' +import { config } from '../config'; ChartJS.register( LinearScale, @@ -76,62 +77,7 @@ export function CativoXLivreChart({ title, subtitle, chartData, label, dataset1, const labels = label - const options: any = { - responsive: true, - scales: { - x: { - grid: { - display: false - }, - ticks: { - font: { - size: !miniature? window.innerWidth/90 : window.innerWidth/110 - } - }, - }, - y: { - grid: { - display: false - }, - ticks: { - font: { - size: !miniature? window.innerWidth/90 : window.innerWidth/110 - } - }, - }, - }, - plugins: { - datalabels: { - display: true, - color: '#255488', - // backgroundColor: '#255488', - anchor: "end", - offset: -20, - align: "start", - font: { - weight: 'bold', - size: !miniature? window.innerWidth/80 : window.innerWidth/105 - }, - formatter: (value, ctx) => { - let sum = 0; - const dataArr = ctx.chart.data.datasets[0].data; - dataArr.map(data => { - sum += data; - }); - const result = `${(parseInt(value)).toLocaleString('pt-br')}` - - return value==null? null : result - } - }, - legend: { - position: 'bottom' as const, - }, - title: { - display: true, - text: '', - }, - }, - }; + const options: any = config(miniature) const data: any = { labels, diff --git a/src/components/graph/costIndicatorChart/index.tsx b/src/components/graph/costIndicatorChart/index.tsx index bb5d02b..a1c7ed8 100644 --- a/src/components/graph/costIndicatorChart/index.tsx +++ b/src/components/graph/costIndicatorChart/index.tsx @@ -15,7 +15,6 @@ import { import { CostIndicatorChartView } from './CostIndicatorChartView'; import ChartTitle from '../ChartTitle'; -import { Stack } from '@mui/material'; import { config } from '../config'; ChartJS.register( @@ -43,7 +42,8 @@ export default function CostIndicatorChart({ title, data1, data2, label, subtitl const options: any = config(miniature) - console.log(data1?.map(value => value)) + console.log(data1) + console.log(data2) const data = { labels, @@ -51,7 +51,7 @@ export default function CostIndicatorChart({ title, data1, data2, label, subtitl { label: '2021', data: data1?.map(value => value), - skipNull: true, + skipNull: data2?.map(value => value)?.includes(null), borderRadius: 8, datalabels: { backgroundColor: 'white', @@ -68,8 +68,8 @@ export default function CostIndicatorChart({ title, data1, data2, label, subtitl }, { label: '2022', - data: data2?.map(value => value?.custo_unit), - skipNull: true, + data: data2?.map(value => value), + skipNull: data1?.map(value => value)?.includes(null), borderRadius: 8, backgroundColor: (value, ctx) => { if (value?.dad_estimado) diff --git a/src/components/graph/grossAnualChart/GrossAnualChart.tsx b/src/components/graph/grossAnualChart/GrossAnualChart.tsx index a2899ff..dcf360a 100644 --- a/src/components/graph/grossAnualChart/GrossAnualChart.tsx +++ b/src/components/graph/grossAnualChart/GrossAnualChart.tsx @@ -86,7 +86,7 @@ export function GrossAnualChart({ title, subtitle, dataProps, label, dataset, ba align: "start", font: { weight: 'bold', - size: !miniature? window.innerWidth/70 : window.innerWidth/90, + size: !miniature? window.innerWidth/80 : window.innerWidth/105, }, color: (value) => { return value.dataset.label==='Consolidada'? '#fff' : '#255488' diff --git a/src/components/graph/grossMensalChart/GrossMensalChart.tsx b/src/components/graph/grossMensalChart/GrossMensalChart.tsx index 31dc901..ca611be 100644 --- a/src/components/graph/grossMensalChart/GrossMensalChart.tsx +++ b/src/components/graph/grossMensalChart/GrossMensalChart.tsx @@ -17,6 +17,7 @@ import { draw, generate } from 'patternomaly' import { GrossMensalChartView } from './GrossMensalChartView'; import ChartTitle from '../ChartTitle'; +import { config } from '../config'; // import { data } from './LineBarChart'; ChartJS.register( @@ -58,71 +59,16 @@ export default function GrossMensalChart({ title, data1, data2, label, subtitle, } }, [data1]) - const options: any = { - responsive: true, - scales: { - x: { - grid: { - display: false - }, - ticks: { - font: { - size: !miniature? window.innerWidth/90 : window.innerWidth/110 - } - }, - }, - y: { - grid: { - display: false - }, - ticks: { - font: { - size: !miniature? window.innerWidth/90 : window.innerWidth/110 - } - }, - }, - }, - plugins: { - datalabels: { - display: true, - color: '#255488', - formatter: (value, ctx) => { - let sum = 0; - const dataArr = ctx.chart.data.datasets[0].data; - dataArr.map(data => { - sum += data; - }); - const percentage = data1[ctx.dataIndex]?.econ_percentual? (data1[ctx.dataIndex].econ_percentual*100).toFixed(0)+"%" : ''; - const result = `${spacement(parseInt(value+3).toLocaleString('pt-br'))}${parseInt(value)!=0? percentage : ''}\n${parseInt(value)!=0? parseInt(value).toLocaleString('pt-br') : ''}` - - return value==null? null : result - }, - anchor: "end", - offset: 0, - align: "end", - font: { - weight: 'bold', - size: !miniature? window.innerWidth/80 : window.innerWidth/120, - } - }, - legend: { - position: 'bottom' as const, - - }, - title: { - display: true, - text: '' - }, - }, - }; + const options: any = config(miniature) const data: any = { - labels: data1.map(value => value.mes), + labels: label, datasets: [ { type: 'bar', label: 'Consolidado', data: data1.map(value => !value.dad_estimado? value?.economia_acumulada : null), + skipNull: true, borderRadius: 8, backgroundColor: '#255488', stack: '0' @@ -131,6 +77,7 @@ export default function GrossMensalChart({ title, data1, data2, label, subtitle, type: 'bar', label: 'Estimado', data: data2.map(value => value.dad_estimado? value?.economia_acumulada : null), + skipNull: true, borderRadius: 8, backgroundColor: draw('diagonal-right-left', '#C2d5fb'), stack: '0' diff --git a/src/pages/dashboard/index.tsx b/src/pages/dashboard/index.tsx index e622c77..8b78a6a 100644 --- a/src/pages/dashboard/index.tsx +++ b/src/pages/dashboard/index.tsx @@ -105,9 +105,9 @@ export default function Dashboard({grossAnualGraph, grossAnualYears, grossMensal value?.mes.slice(0, 4).includes('2021')).map(value => value?.custo_unit? value.custo_unit : null)} + data1={costIndicator?.filter((value, index) => value?.mes.slice(0, 4).includes('2021')).map(value => value?.custo_unit && !!parseInt(value?.custo_unit)? value.custo_unit : null)} // data1={graphData} - data2={costIndicator?.filter((value, index) => value?.mes.slice(0, 4).includes('2022'))} + data2={costIndicator?.filter((value, index) => value?.mes.slice(0, 4).includes('2022')).map(value => value?.custo_unit && !!parseInt(value?.custo_unit)? value.custo_unit : null)} label={months} miniature /> diff --git a/src/pages/economy/index.tsx b/src/pages/economy/index.tsx index 3034819..7d6fa37 100644 --- a/src/pages/economy/index.tsx +++ b/src/pages/economy/index.tsx @@ -33,6 +33,9 @@ export default function economy({userName, anual, years, brutaMensal, catLiv, cl const [catLivDataState, setCatLivDataState] = useState(null); const [indicatorDataState, setIndicatorDataState] = useState(null); + const currentYear = new Date().getUTCFullYear() + const previousYear = new Date().getUTCFullYear()-1 + const months = [ 'Jan', 'Fev', @@ -159,7 +162,6 @@ export default function economy({userName, anual, years, brutaMensal, catLiv, cl fullWidth > Todas - {/* RSZFNAENTR101P !!OPÇAO COM DADOS TESTES!! */} { clients.map((value) => { return {value.unidade} @@ -200,8 +202,8 @@ export default function economy({userName, anual, years, brutaMensal, catLiv, cl
value.mes.slice(0, 4).includes('2021'))} - data2={indicatorDataState?.filter((value, index) => value.mes.slice(0, 4).includes('2022'))} + data1={indicatorDataState?.filter(value => value?.mes.slice(0, 4).includes(previousYear)).map(value => value?.custo_unit && !!parseInt(value?.custo_unit)? value.custo_unit : null)} + data2={indicatorDataState?.filter(value => value?.mes.slice(0, 4).includes(currentYear)).map(value => value?.custo_unit && !!parseInt(value?.custo_unit)? value.custo_unit : null)} label={months} />
diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 2457994..f4b9f15 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -19,6 +19,8 @@ import { api } from '../services/api'; import { LoginContainer, LoginView } from '../styles/layouts/login/LoginView'; import Dashboard from './dashboard'; import MuiAlert, { AlertProps } from '@mui/material/Alert'; +import { GetServerSideProps } from 'next'; +import { parseCookies } from 'nookies'; const Alert = React.forwardRef(function Alert( props, @@ -165,3 +167,16 @@ export default function Home() { ) } + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const { ['@smartAuth-token']: token } = parseCookies(ctx) + + if (token) { + return { + redirect: { + destination: '/dashboard', + permanent: false + } + } + } +}