From 3e8c5a70f24c17c8f518fa1e85880d44022af813 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Thu, 14 Jul 2022 09:12:51 -0300 Subject: [PATCH] mores fixes --- .../graph/grossAnualChart/GrossAnualChart.tsx | 33 ++++++++----------- src/contexts/AuthContext.tsx | 4 ++- src/services/auth.ts | 13 +++++--- src/styles/layouts/economy/economy.ts | 6 +++- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/components/graph/grossAnualChart/GrossAnualChart.tsx b/src/components/graph/grossAnualChart/GrossAnualChart.tsx index 0d974ba..734a93b 100644 --- a/src/components/graph/grossAnualChart/GrossAnualChart.tsx +++ b/src/components/graph/grossAnualChart/GrossAnualChart.tsx @@ -1,12 +1,11 @@ import { BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, Title, Tooltip } from 'chart.js'; import ChartDataLabels from 'chartjs-plugin-datalabels'; -import { draw, generate } from 'patternomaly' -import React from 'react'; -import { Bar, Chart } from 'react-chartjs-2'; +import { draw } from 'patternomaly' +import React, { useEffect } from 'react'; +import { Chart } from 'react-chartjs-2'; import { GrossAnualChartView } from './GrossAnualChartView'; import ChartTitle from '../ChartTitle'; -import { blue } from '@mui/material/colors'; ChartJS.register( CategoryScale, @@ -40,10 +39,9 @@ export function GrossAnualChart({ title, subtitle, dataProps, label, dataset, ba const options: any = { responsive: true, - is3D: true, scales: { x: { - grouped: false, + stacked: true, font: { size: 20 }, @@ -52,6 +50,7 @@ export function GrossAnualChart({ title, subtitle, dataProps, label, dataset, ba } }, y: { + stacked: true, grid: { display: false } @@ -78,7 +77,7 @@ export function GrossAnualChart({ title, subtitle, dataProps, label, dataset, ba display: true, color: '#255488', anchor: "end", - offset: !miniature? -60 : -30, + offset: !miniature? -55 : -30, align: "start", font: { size: !miniature? 22 : 10, @@ -101,7 +100,7 @@ export function GrossAnualChart({ title, subtitle, dataProps, label, dataset, ba let labels: string[]; if (bruta) { - labels = label.map(value => value.replace('2021', 'Até 2021')) + labels = [`Até ${new Date().getFullYear()-1}`, `${new Date().getFullYear()}`] } else { labels = label } @@ -113,26 +112,20 @@ export function GrossAnualChart({ title, subtitle, dataProps, label, dataset, ba type: 'bar', label: dataset, stacked: true, - - data: dataProps.map((value, index) => { - if (!value.dad_estimado) - return parseFloat(value.economia_acumulada).toFixed(2) + data: dataProps.filter(value => value.dad_estimado === false).map((value, index) => { + return parseFloat(value.economia_acumulada) }), - backgroundColor: (value, ctx) => { - return '#255488' - }, + backgroundColor: '#255488' }, { type: 'bar', stacked: true, label: 'Estimado', - data: dataProps.map((value, index) => { + data: dataProps.filter(value => value.ano === '2022').map((value, index) => { if (value.dad_estimado) - return parseFloat(value.economia_acumulada).toFixed(2) + return parseFloat(value.economia_acumulada) }), - backgroundColor: (value, ctx) => { - return draw('diagonal-right-left', '#C2d5fb'); - }, + backgroundColor: draw('diagonal-right-left', '#C2d5fb'), }, ], } diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 84aaaeb..677e7da 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -3,7 +3,7 @@ import Router from 'next/router' import { destroyCookie, setCookie } from "nookies"; -import { signInRequest } from "../services/auth"; +import { logout, signInRequest } from "../services/auth"; import { api } from "../services/api"; type UserType = { @@ -37,6 +37,8 @@ export function AuthProvider({children}: {children: React.ReactNode}) { destroyCookie(null, 'user-role') destroyCookie(null, 'user-id') destroyCookie(null, '@smartAuth-token') + + logout() } async function signIn({email, password}: SignInData) { diff --git a/src/services/auth.ts b/src/services/auth.ts index 3da9188..51231fb 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -2,10 +2,6 @@ import { api } from "./api"; export const TOKEN_KEY = "@smartAuth-token"; -export const logout = () => { - localStorage.removeItem(TOKEN_KEY); -}; - interface SignInRequestData { email: string, password: string @@ -81,3 +77,12 @@ export default async function recoverUserInformation(id) { } } } + +export async function logout() { + await api.post('/auth/logout', {}) + // eslint-disable-next-line @typescript-eslint/no-empty-function + .then(res => {}) + .catch(res => { + console.log(res) + }) +} diff --git a/src/styles/layouts/economy/economy.ts b/src/styles/layouts/economy/economy.ts index a3fd2df..3e9e035 100644 --- a/src/styles/layouts/economy/economy.ts +++ b/src/styles/layouts/economy/economy.ts @@ -1,5 +1,9 @@ import styled from 'styled-components' export const EconomyView = styled.main` - + section { + display: flex; + justify-content: center; + align-items: center; + } `