diff --git a/src/components/administrativeTables/FaqTable.tsx b/src/components/administrativeTables/FaqTable.tsx index cc0b09e..a7014bb 100644 --- a/src/components/administrativeTables/FaqTable.tsx +++ b/src/components/administrativeTables/FaqTable.tsx @@ -45,15 +45,6 @@ function createData( }; } -const rows = [ - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), - createData('Como usar o sistema', 'Você deve usar assim... e assado...', 'ativo'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'inativo'), -]; - function descendingComparator(a: T, b: T, orderBy: keyof T) { if (b[orderBy] < a[orderBy]) { return -1; @@ -183,8 +174,6 @@ export default function FaqTable({questionData, onChange}: FaqTableInterface) { const [dense, setDense] = useState(false); const [rowsPerPage, setRowsPerPage] = useState(5); - console.table(questionData) - console.table(rows) const handleRequestSort = ( event: React.MouseEvent, property: keyof Data, @@ -240,7 +229,7 @@ export default function FaqTable({questionData, onChange}: FaqTableInterface) { // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = - page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; + page > 0 ? Math.max(0, (1 + page) * rowsPerPage - questionData.length) : 0; return ( @@ -313,7 +302,7 @@ export default function FaqTable({questionData, onChange}: FaqTableInterface) { value), + data: data1.map(value => value.economia_mensal), }, { type: 'bar' as const, label: dataset2? dataset2 : 'Dataset 2', backgroundColor: (value, ctx) => { - return hashurado? parseInt(value.dataIndex+1) <= currentTime.getMonth()? '#C2D5FB' : pattern.draw('diagonal', '#C2D5FB') : '#C2D5FB' + return hashurado? data1[value.dataIndex].dad_estimado == false? '#C2D5FB' : pattern.draw('diagonal', '#C2D5FB') : '#C2D5FB' }, - data: data3.map(value => value), + data: data3.map(value => value.custo_cativo), }, { type: 'bar' as const, label: dataset3? dataset3 : 'Dataset 2', // backgroundColor: '#255488', backgroundColor: (value, ctx) => { - return hashurado? parseInt(value.dataIndex+1) <= currentTime.getMonth()? '#255488' : pattern.draw('diagonal', '#255488') : '#255488' + return hashurado? data1[value.dataIndex].dad_estimado == false? '#255488' : pattern.draw('diagonal', '#255488') : '#255488' }, - data: data2.map(value => value), + data: data2.map(value => value.custo_livre), }, ], } : { diff --git a/src/components/graph/SingleBar.tsx b/src/components/graph/SingleBar.tsx index 1bb3815..b1b858f 100644 --- a/src/components/graph/SingleBar.tsx +++ b/src/components/graph/SingleBar.tsx @@ -50,8 +50,8 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1 dataArr.map(data => { sum += data; }); - const percentage = (value*100 / sum).toFixed(0)+"%"; - const result = `${value}\n ${percentage}` + const percentage = (dataProps[ctx.dataIndex].econ_percentual*100).toFixed(0)+"%"; + const result = `${value}\n ${percentage}` return value==null? null : result }, @@ -82,10 +82,9 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1 { label: dataset, data: dataProps.map((value, index) => { - return value.economia_acumulada + return parseFloat(value.economia_acumulada).toFixed(2) }), backgroundColor: (value, ctx) => { - console.log(dataProps[value.dataIndex]) return dataProps[value.dataIndex].dad_estimado == false ? '#255488' : '#C2d5fb' }, }, diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index 22fa066..1beb9a8 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -1,9 +1,11 @@ +import React, { useContext, useEffect, useState } from 'react' +import Image from 'next/image'; + import Avatar from '@mui/material/Avatar'; import TextField from '@mui/material/TextField'; -import Image from 'next/image'; -import React from 'react' import { HeaderView } from './HeaderView' +import { parseCookies } from 'nookies'; function stringToColor(string: string) { let hash = 0; @@ -28,7 +30,7 @@ function stringAvatar(name: string) { sx: { bgcolor: stringToColor(name), }, - children: `${name.split(' ')[0][0]}${name.split(' ')[1][0]}`, + children: `${name.split(' ')[0][0]}`, }; } @@ -52,10 +54,10 @@ export default function Header({ name }: headerInterface) {

- olá, {'josé'} + olá, {name}

- + ) diff --git a/src/components/mapCard/MapCard.tsx b/src/components/mapCard/MapCard.tsx index 10085d5..b1c5c06 100644 --- a/src/components/mapCard/MapCard.tsx +++ b/src/components/mapCard/MapCard.tsx @@ -15,9 +15,11 @@ export default function MapCard({ title, subtitle, statistic, imgSource, date }: return ( - +
-

{title}

+

{ + subtitle==='SUL'? 'S' : subtitle==='NORTE'? 'N' : subtitle==='NORDESTE'? 'NE' : subtitle==='SUDESTE'? 'SE/CO' : title + }

{subtitle} { date? diff --git a/src/components/sidebar/Sidebar.tsx b/src/components/sidebar/Sidebar.tsx index 271bf62..48df240 100644 --- a/src/components/sidebar/Sidebar.tsx +++ b/src/components/sidebar/Sidebar.tsx @@ -55,7 +55,7 @@ export default function Sidebar() {
  • {'Clientes >'}
  • -
  • {'Visão Geral'}
  • +
  • {'Sobre Nós'}
  • {'FAQ >'}
  • {'Notificações >'}

    25

  • diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index c422e20..f335f00 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -36,15 +36,21 @@ export function AuthProvider({children}: {children: React.ReactNode}) { password }) - if (token) { + if (token) setCookie(undefined, '@smartAuth-token', token, { maxAge: 60 * 60 * 1, // 1 hour }) - } - if (user.role) { + if (user.role) setCookie(undefined, 'user-role', user.role) - } + + if (user.id) + setCookie(undefined, 'user-id', user.id) + + if (user.name) + setCookie(undefined, 'user-name', user.name) + + api.defaults.headers['Authorization'] = `Bearer ${token}` if (!exception) { if (user.role == 2) { @@ -56,10 +62,6 @@ export function AuthProvider({children}: {children: React.ReactNode}) { } else { return } - - api.defaults.headers['Authorization'] = `Bearer ${token}` - - setUser(user) } return ( diff --git a/src/pages/aboutUs.tsx b/src/pages/aboutUs.tsx index c4697fb..d0eb0a0 100644 --- a/src/pages/aboutUs.tsx +++ b/src/pages/aboutUs.tsx @@ -1,17 +1,19 @@ +import { GetServerSideProps } from 'next' import Head from 'next/head' import Image from 'next/image' +import { parseCookies } from 'nookies' import React from 'react' import Banner from '../components/banner/Banner' import Header from '../components/header/Header' import { AboutUsView } from '../styles/layouts/aboutUs/AboutUsView' -export default function aboutUs() { +export default function aboutUs({userName}) { return ( Smart Energia - About Us -
    +
    @@ -50,3 +52,24 @@ export default function aboutUs() { ) } + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) + + if (!token) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + return { + props: { + userName + } + } +} + diff --git a/src/pages/accumulatedSavings.tsx b/src/pages/accumulatedSavings.tsx index 6131c3f..bce6a4c 100644 --- a/src/pages/accumulatedSavings.tsx +++ b/src/pages/accumulatedSavings.tsx @@ -12,13 +12,13 @@ import { dataEconomiaBruta } from '../services/economiaBruta' import getAPIClient from '../services/ssrApi' import { AccumulatedSavingsView } from '../styles/layouts/economy/accumulatedSavings/AccumulatedSavingsView' -export default function AccumulatedSavings({graphData, years}: any) { +export default function AccumulatedSavings({graphData, years, userName}: any) { return ( Smart Energia - Economia Acumulada -
    +
    { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) + let graphData = []; await apiClient.post('/economy/grossMonthly').then(res => { graphData = res.data.data - console.log(graphData[0].mes) + // console.log(graphData[0].mes) }).catch(res => { console.log(res) }) @@ -53,11 +55,11 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { } } - return { props: { graphData, years, + userName } } } diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index 7a612e6..6d3d430 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -43,7 +43,7 @@ const Alert = React.forwardRef(function Alert( return ; }); -export default function clients({clients}) { +export default function clients({clients, userName}) { const [client, setClient] = useState({ name: String, email: String, @@ -114,28 +114,28 @@ export default function clients({clients}) {
    - notificação cadastrada com sucesso! + Usuario cadastrada com sucesso! - Notificação não cadastrada! + Usuario não cadastrada! - notificação excluida com sucesso! + Usuario excluida com sucesso! - Notificação não excluida! + Usuario não excluida! -
    +
    @@ -209,13 +209,14 @@ export default function clients({clients}) { export const getServerSideProps: GetServerSideProps = async (ctx) => { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) let clients = []; await apiClient.get('/user').then(res => { - console.log(res) + // console.log(res) clients = res.data.data - console.log(clients) + // console.log(clients) }).catch(res => { // console.log(res) }) @@ -232,6 +233,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { clients, + userName } } } diff --git a/src/pages/administrative/faq/index.tsx b/src/pages/administrative/faq/index.tsx index 592ac3a..0b057d2 100644 --- a/src/pages/administrative/faq/index.tsx +++ b/src/pages/administrative/faq/index.tsx @@ -51,11 +51,9 @@ const Alert = React.forwardRef(function Alert( type FaqInterface = { question: string; answer: string; - } -export default function Sidebar({faqData} : any ) { - +export default function Sidebar({faqData, userName} : any ) { const [openModalInativar, setOpenModalInativar] = useState(false) const [openSnackSuccess, setOpenSnackSuccess] = useState(false); const [openSnackError, setOpenSnackError] = useState(false); @@ -85,7 +83,7 @@ export default function Sidebar({faqData} : any ) { async function handleDeleteNotification(id: any) { await id.map((value) => { - api.delete(`/faq/${value}`).then(res => { + api.delete(`/faq/${value.id}`).then(res => { setOpenSnackSuccessDelete(true) setOpenModalInativar(false) window.location.reload() @@ -93,12 +91,9 @@ export default function Sidebar({faqData} : any ) { }) } - - const [faq, setFaq] = useState({ question: '', answer : '', - }) const [selectedfaq, setSelectedfaq] = useState([]) @@ -107,13 +102,12 @@ export default function Sidebar({faqData} : any ) { await api.post('/faq', { "question": question, "answer": answer, - - }).then(res => console.log(res.data)) + }).then(res => { + setOpenSnackSuccess(true) + window.location.reload() + }).catch(res => setOpenSnackError(true)) } - - - const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); @@ -121,29 +115,29 @@ export default function Sidebar({faqData} : any ) { return ( <> -
    +
    - Notificação cadastrada com sucesso! + Pergunta cadastrada com sucesso! - Notificação não cadastrada! + Pergunta não cadastrada! - notificação excluida com sucesso! + Pergunta excluida com sucesso! - Notificação não excluida! + Pergunta não excluida! @@ -197,6 +191,7 @@ export default function Sidebar({faqData} : any ) { export const getServerSideProps: GetServerSideProps = async (ctx) => { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) let faqData = []; @@ -217,7 +212,8 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { - faqData + faqData, + userName } } } diff --git a/src/pages/administrative/general.tsx b/src/pages/administrative/general.tsx index b45eead..ec52d81 100644 --- a/src/pages/administrative/general.tsx +++ b/src/pages/administrative/general.tsx @@ -4,12 +4,15 @@ import MenuItem from '@mui/material/MenuItem'; import Select, { SelectChangeEvent } from '@mui/material/Select'; import TextField from '@mui/material/TextField'; import { Editor } from '@tinymce/tinymce-react' +import { GetServerSideProps } from 'next'; +import { parseCookies } from 'nookies'; import React, { useRef, useState } from 'react' import Header from '../../components/header/Header'; +import PageTitle from '../../components/pageTitle/PageTitle'; import { GeneralView } from '../../styles/layouts/general/GeneralView' -export default function index() { +export default function index({userName}: any) { const editorRef = useRef(null); const [text, setText] = useState(''); @@ -25,7 +28,8 @@ export default function index() { return ( -
    +
    +
    - Norte - Nordeste - Sul - Sudeste - + + Região + +
    - + + Dia + +
    - setPage('table')}>{'< voltar para tabela PLD'} + setPage('table')}>{'< Voltar para tabela PLD'}
    setDate(value.target.value)}/> - console.log()}/> + {/* console.log()}/> */}
    { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) + let tableData = []; @@ -315,6 +329,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { tableData, + userName } } } diff --git a/src/pages/resumoOperacao.tsx b/src/pages/resumoOperacao.tsx index 43eadd5..03a4e57 100644 --- a/src/pages/resumoOperacao.tsx +++ b/src/pages/resumoOperacao.tsx @@ -3,8 +3,10 @@ import FormControl from '@mui/material/FormControl'; import InputLabel from '@mui/material/InputLabel'; import MenuItem from '@mui/material/MenuItem'; import Select, { SelectChangeEvent } from '@mui/material/Select'; +import { GetServerSideProps } from 'next'; import Head from 'next/head'; -import React, { useEffect } from 'react'; +import { parseCookies } from 'nookies'; +import React, { useEffect, useState } from 'react'; // import Teste from '../files/teste.csv'; import { CSVDownload, CSVLink } from "react-csv"; @@ -12,30 +14,18 @@ import BasicButton from '../components/buttons/basicButton/BasicButton'; import Header from '../components/header/Header'; import PageTitle from '../components/pageTitle/PageTitle'; import Sidebar from '../components/sidebar/Sidebar'; +import { api } from '../services/api'; // import { dados } from '../services/DadosTabelaResumoOperacao'; import data from '../services/dados.json' +import getAPIClient from '../services/ssrApi'; import { Pagination, TableView } from '../styles/layouts/ResumoOperacao/ResumoOperacaoView'; -export default function ResumoOperacao() { - const csvData = [ - // ["firstname", "lastname", "email"], - // ["Ahmed", "Tomi", "ah@smthing.co.com"], - // ["Raed", "Labes", "rl@smthing.co.com"], - // ["Yezzi", "Min l3b", "ymin@cocococo.com"], +export default function ResumoOperacao({tableData, userName}: any) { + const csvData = tableData; - - - [ "value", "unidade1", "name", "Unidade-1", "operacao", "Compra", "montante", "130,00", "contraparte", "cOPEL COM I5", "preco", "234,67", "valorNF", "38.257,15" ], - [ "value", "unidade2", "name", "Unidade-2", "operacao", "Compra", "montante", "20,00", "contraparte", "EMEWE I5", "preco", "234,67", "valorNF", "38.257,15"], - [ "value", "unidade3", "name", "Unidade-3", "operacao", "Compra", "montante", "30,00", "contraparte", "EMEWE I5", "preco", "234,67", "valorNF", "38.257,15" ], - [ "value", "unidade4", "name", "Unidade-4", "operacao", "Compra", "montante", "40,00", "contraparte", "COPEL COM I5", "preco", "234,67", "valorNF", "38.257,15" ], - [ "value", "unidade5", "name", "Unidade-5", "operacao", "Compra", "montante", "500,00","contraparte", "COPEL COM I5", "preco", "234,67", "valorNF", "38.257,15" ], - [ "value", "unidade6", "name", "Unidade-6", "operacao", "Compra", "montante", "300,00", "contraparte", "COPEL COM I5", "preco","234,67", "valorNF", "965,95" ] - - ]; - - const [month, setMonth] = React.useState(''); - const [unidade, setUnidade] = React.useState(''); + const [month, setMonth] = useState(''); + const [unidade, setUnidade] = useState(''); + const [tableDataState, setTableDataState] = useState([]); const handleChangeMonth = (event: SelectChangeEvent) => { setMonth(event.target.value); @@ -45,20 +35,29 @@ export default function ResumoOperacao() { }; useEffect(() => { - // console.log(data.unidades) - // data.unidades.map((value) => { - // console.log(`olha o valor ${value.name}`) - // }) - // console.log(unidade) - console.log(data.unidades.filter((value, index)=> value.value.includes(unidade))) + if (unidade!=='' || month!==''){ + api.post('/operation', { + "filters": [ + {"type" : "=", "field": "mes", "value": `${month}/2022`}, + {"type" : "=", "field": "dados_te.cod_smart_unidade", "value": unidade} + ] + }).then(res => { + setTableDataState(res.data.data) + }).catch(res => { + console.log(res) + }) + } else { + setTableDataState(tableData) + } + }, [month, unidade]) - return( + return ( Smart Energia - Resumo de Operação -
    +

    Seletor Mês

    @@ -72,10 +71,10 @@ export default function ResumoOperacao() { label="Unidade" onChange={handleChangeUnidade} > - + Nenhum { - data.unidades.map((value) => { - return {value.name} + tableData.map((value) => { + return {value.cod_smart_unidade} }) } @@ -90,19 +89,19 @@ export default function ResumoOperacao() { label="Month" onChange={handleChangeMonth} > - Janeiro - Fevereiro - Março - Abril - Março - Maio - Junho - Julho - Agosto - Setembro - Outubro - Novembro - Dezembro + Nenhum + Janeiro + Fevereiro + Março + Abril + Maio + Junho + Julho + Agosto + Setembro + Outubro + Novembro + Dezembro @@ -119,26 +118,17 @@ export default function ResumoOperacao() { { - data.unidades.filter((value, index)=> value.value.includes(unidade)).map((value, index) => { - if (index%2===0) { - return - {value.name} - {value.operacao} - {value.montante} - {value.contraparte} - {value.preco} - {value.valorNF} - - } else { - return - {value.name} - {value.operacao} - {value.montante} - {value.contraparte} - {value.preco} - {value.valorNF} - - } + tableDataState.map((value, index) => { + return <> + + {value.cod_smart_unidade} + {value.operacao} + {value.montante_nf} + {value.contraparte} + {value.nf_c_icms} + {value.preco_nf} + + }) } @@ -152,3 +142,39 @@ export default function ResumoOperacao() { ) } + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const apiClient = getAPIClient(ctx) + const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-id']: id } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) + + let tableData = []; + + await apiClient.post('/operation', { + "filters": [] + }).then(res => { + console.log(res.data.data) + tableData = res.data.data + }).catch(res => { + console.log(res) + }) + + console.log(tableData) + + if (!token) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + return { + props: { + tableData, + userName + } + } +} diff --git a/src/pages/telemetria.tsx b/src/pages/telemetria.tsx index c20530f..9a9adc8 100644 --- a/src/pages/telemetria.tsx +++ b/src/pages/telemetria.tsx @@ -15,11 +15,13 @@ import { start } from 'nprogress'; import LineChart from '../components/graph/LineChart'; import { FatorPotencia } from '../services/fatorPotencia'; import RenderIf from '../utils/renderIf'; +import { GetServerSideProps } from 'next'; +import { parseCookies } from 'nookies'; -export default function Telemetria() { +export default function Telemetria({userName}: any) { const [unity, setUnity] = React.useState(''); const [startDate, setStartDate] = React.useState(''); const [endDate, setEndDate] = React.useState(''); @@ -36,7 +38,7 @@ export default function Telemetria() { Smart Energia - Telemetria -
    +