From 1f979845a8225ddc36871a1910cc6ca7583010d8 Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Fri, 24 Jun 2022 09:54:17 -0300 Subject: [PATCH 01/17] update --- src/pages/index.tsx | 2 +- src/pages/resumoOperacao.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 5e2d390..45e0d59 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -139,7 +139,7 @@ export default function Home() { setEmail(value.target.value) }}/> - Password + Senha Smart Energia - Resumo de Operação
- + -

Seletor Mês

+

Filtrar por Unidade e/ou Mês

Unidades From 020fe303144beba70d0efb8e5c270657bda8605a Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Fri, 24 Jun 2022 19:54:46 -0300 Subject: [PATCH 02/17] update Consumption --- package.json | 1 + src/components/banner/BannerView.ts | 6 +- src/pages/administrative/clients/index.tsx | 449 ++++++++++++------ src/pages/administrative/general.tsx | 19 + .../administrative/industryInfo/index.tsx | 27 +- src/pages/industryInfo.tsx | 2 +- src/pages/pld/index.tsx | 5 + src/styles/layouts/pld/PldView.ts | 4 + yarn.lock | 5 + 9 files changed, 356 insertions(+), 162 deletions(-) diff --git a/package.json b/package.json index c60b200..bfc4d50 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@mui/material": "^5.6.4", "@mui/x-data-grid": "^5.11.0", "@mui/x-date-pickers": "^5.0.0-alpha.3", + "@react-pdf-viewer/core": "^3.5.0", "@tinymce/tinymce-react": "^4.1.0", "@types/react-csv": "^1.1.2", "@types/yup": "^0.29.14", diff --git a/src/components/banner/BannerView.ts b/src/components/banner/BannerView.ts index 2598880..8b7d46c 100644 --- a/src/components/banner/BannerView.ts +++ b/src/components/banner/BannerView.ts @@ -23,9 +23,11 @@ export const BannerView = styled.div` } h1 { - font-size: 18px; + font-size: 1.3em; + } + .text { position: relative; margin: 0 0 0 20px; @@ -42,7 +44,7 @@ export const BannerView = styled.div` text-overflow: ellipsis; p { - font-size: 70%; + font-size: 19px; /* height: 43px; */ text-overflow: ellipsis; diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index 32ab35c..70b0b15 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -1,28 +1,28 @@ -import Box from '@mui/material/Box'; -import Modal from '@mui/material/Modal'; -import TextField from '@mui/material/TextField'; -import Typography from '@mui/material/Typography'; -import React, { useState } from 'react' - -import Snackbar from '@mui/material/Snackbar'; -import MuiAlert, { AlertProps } from '@mui/material/Alert'; -import ClientsTable from '../../../components/administrativeTables/ClientsTable'; +import Box from '@mui/material/Box' +import Modal from '@mui/material/Modal' +import TextField from '@mui/material/TextField' +import Typography from '@mui/material/Typography' +import React, { useState, useEffect } from 'react' +import Image from 'next/image' +import Snackbar from '@mui/material/Snackbar' +import MuiAlert, { AlertProps } from '@mui/material/Alert' +import ClientsTable from '../../../components/administrativeTables/ClientsTable' import BasicButton from '../../../components/buttons/basicButton/BasicButton' -import FaqButton1 from '../../../components/buttons/faqButton/FaqButton1'; -import FaqButton2 from '../../../components/buttons/faqButton/FaqButton2'; +import FaqButton1 from '../../../components/buttons/faqButton/FaqButton1' +import FaqButton2 from '../../../components/buttons/faqButton/FaqButton2' import Header from '../../../components/header/Header' -import InputUploadImg from '../../../components/inputUploadImg/inputUpload'; -import { ClientsView } from '../../../styles/layouts/clients/ClientsView'; -import PageTitle from '../../../components/pageTitle/PageTitle'; -import ConfirmModal from '../../../components/modal/ConfirmModal'; -import { ConfirmModalView } from '../../../styles/layouts/modals/confirmModalView'; -import { api } from '../../../services/api'; -import { parseCookies } from 'nookies'; -import { GetServerSideProps } from 'next'; -import getAPIClient from '../../../services/ssrApi'; -import FormData from 'form-data'; -import { InputUploadView } from '../../../components/inputUploadImg/inputUploadView'; +import { ClientsView } from '../../../styles/layouts/clients/ClientsView' +import PageTitle from '../../../components/pageTitle/PageTitle' +import ConfirmModal from '../../../components/modal/ConfirmModal' +import { ConfirmModalView } from '../../../styles/layouts/modals/confirmModalView' +import { api } from '../../../services/api' +import { parseCookies } from 'nookies' +import { GetServerSideProps } from 'next' +import getAPIClient from '../../../services/ssrApi' + +import FormData from 'form-data' +import { InputUploadView } from '../../../components/inputUploadImg/inputUploadView' const style = { position: 'absolute' as const, @@ -36,17 +36,17 @@ const style = { boxShadow: 24, p: 4, overflowY: 'scroll' -}; +} const Alert = React.forwardRef(function Alert( props, - ref, + ref ) { - return ; -}); + return +}) -export default function clients({clients, userName}) { - const formData = new FormData(); +export default function clients({ clients, userName }) { + const formData = new FormData() const [client, setClient] = useState({ name: String, @@ -55,44 +55,60 @@ export default function clients({clients, userName}) { password_confirmation: String, client_id: Number }) - const [logo, setLogo] = useState(false); + const [logo, setLogo] = useState(false) const [selectedClients, setSelectedClients] = useState([]) - const [open, setOpen] = useState(false); + const [imageURLS, setImageURLs] = useState([]) + const [images, setImages] = useState([] as any) + const [open, setOpen] = useState(false) const [openModalInativar, setOpenModalInativar] = useState(false) - const handleOpen = () => setOpen(true); - const handleClose = () => setOpen(false); + const handleOpen = () => setOpen(true) + const handleClose = () => setOpen(false) const [openModal, setOpenModal] = useState(false) - const [openSnackSuccess, setOpenSnackSuccess] = useState(false); - const [openSnackError, setOpenSnackError] = useState(false); - const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = useState(false); - const [openSnackErrorDelete, setOpenSnackErrorDelete] = useState(false); + const [openSnackSuccess, setOpenSnackSuccess] = useState(false) + const [openSnackError, setOpenSnackError] = useState(false) + const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = + useState(false) + const [openSnackErrorDelete, setOpenSnackErrorDelete] = + useState(false) - const handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => { + const handleCloseSnack = ( + event?: React.SyntheticEvent | Event, + reason?: string + ) => { if (reason === 'clickaway') { - return; + return } - setOpenSnackError(false); - setOpenSnackSuccess(false); - }; + setOpenSnackError(false) + setOpenSnackSuccess(false) + } - const handleCloseSnackDelete = (event?: React.SyntheticEvent | Event, reason?: string) => { + const handleCloseSnackDelete = ( + event?: React.SyntheticEvent | Event, + reason?: string + ) => { if (reason === 'clickaway') { - return; + return } - setOpenSnackErrorDelete(false); - setOpenSnackSuccessDelete(false); - }; + setOpenSnackErrorDelete(false) + setOpenSnackSuccessDelete(false) + } function onChange(e) { setLogo(e.target.files[0]) } - function handleCreateClient({name, email, password, password_confirmation, client_id}) { + function handleCreateClient({ + name, + email, + password, + password_confirmation, + client_id + }) { formData.append('name', name) formData.append('email', email) formData.append('password', password) @@ -100,134 +116,260 @@ export default function clients({clients, userName}) { formData.append('client_id', client_id) formData.append('profile_picture', logo) - api.post('/user', formData).then(res => { - setOpenSnackSuccess(true) - setOpenModalInativar(false) - window.location.reload() - }).catch(res => { - setOpenSnackError(true) - }) - } - async function handleDeleteClient(id: any) { - await id.map(client => { - api.delete(`/user/${client}`).then(res => { - setOpenSnackSuccessDelete(true) + api + .post('/user', formData) + .then((res) => { + setOpenSnackSuccess(true) setOpenModalInativar(false) window.location.reload() - }).catch(res => setOpenSnackErrorDelete(true)) + }) + .catch((res) => { + setOpenSnackError(true) + }) + } + async function handleDeleteClient(id: any) { + await id.map((client) => { + api + .delete(`/user/${client}`) + .then((res) => { + setOpenSnackSuccessDelete(true) + setOpenModalInativar(false) + window.location.reload() + }) + .catch((res) => setOpenSnackErrorDelete(true)) }) } + useEffect(() => { + if (images.length < 1) return + const newImageUrls: any = [] + images.forEach((image: any) => + newImageUrls.push(URL.createObjectURL(image)) + ) + setImageURLs(newImageUrls) + }, [images]) + + function onImageChange(e: any) { + setImages([...e.target.files]) + setLogo(e.target.files[0]) + // console.log(e); + } + return ( -
- - +
+ + Cliente cadastrada com Sucesso! - - + + Cliente não cadastrado! - - + + Cliente excluido com sucesso! - - + + Cliente não excluido! -
- -
- - +
+ +
+ +
- { - setSelectedClients(value) - }}/> + { + setSelectedClients(value) + }} + />
- -

Adicionar Cliente

- - Adicionar Cliente Smart Energia -
- { - setClient({ - ...client, - name: value.target.value - }) - }} variant="outlined" /> - { - setClient({ - ...client, - email: value.target.value.toLowerCase() - }) - }} variant="outlined" /> - { - setClient({ - ...client, - password: value.target.value - }) - }} variant="outlined" /> - { - setClient({ - ...client, - password_confirmation: value.target.value - }) - }} variant="outlined" /> - { - setClient({ - ...client, - client_id: value.target.value - }) - }} variant="outlined" /> - - -
-
- -
- -
- -
- -
-
- - -
-
-
- -
-

- setOpen(false)} /> - handleCreateClient(client)}/> -
+ +

Adicionar Cliente

+ + Adicionar Cliente Smart Energia + +
+ { + setClient({ + ...client, + name: value.target.value + }) + }} + variant="outlined" + /> + { + setClient({ + ...client, + email: value.target.value.toLowerCase() + }) + }} + variant="outlined" + /> + { + setClient({ + ...client, + password: value.target.value + }) + }} + variant="outlined" + /> + { + setClient({ + ...client, + password_confirmation: value.target.value + }) + }} + variant="outlined" + /> + { + setClient({ + ...client, + client_id: value.target.value + }) + }} + variant="outlined" + /> + +
+
+ {imageURLS.map((imageSrc, index) => ( + + ))} +
+
+
+
+
+ + +
+
+
+
+
+
+ setOpen(false)} /> + handleCreateClient(client)} + /> +
- {setOpenModalInativar(value)}}> - + { + setOpenModalInativar(value) + }} + > + - handleDeleteClient(selectedClients)}/> - setOpenModalInativar(false)}/> + handleDeleteClient(selectedClients)} + /> + setOpenModalInativar(false)} + />
@@ -238,15 +380,18 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) const { ['user-name']: userName } = parseCookies(ctx) - let clients = []; + let clients = [] - await apiClient.get('/user').then(res => { - // console.log(res) - clients = res.data.data - // console.log(clients) - }).catch(res => { - // console.log(res) - }) + await apiClient + .get('/user') + .then((res) => { + // console.log(res) + clients = res.data.data + // console.log(clients) + }) + .catch((res) => { + // console.log(res) + }) if (!token) { return { diff --git a/src/pages/administrative/general.tsx b/src/pages/administrative/general.tsx index 1d5b7bf..1ffacd2 100644 --- a/src/pages/administrative/general.tsx +++ b/src/pages/administrative/general.tsx @@ -8,10 +8,13 @@ import { GetServerSideProps } from 'next'; import { parseCookies } from 'nookies'; import React, { useRef, useState } from 'react' +import BasicButton from '../../components/buttons/basicButton/BasicButton'; import Header from '../../components/header/Header'; import PageTitle from '../../components/pageTitle/PageTitle'; +import { api } from '../../services/api'; import { GeneralView } from '../../styles/layouts/general/GeneralView' + export default function index({userName}: any) { const editorRef = useRef(null); const [text, setText] = useState(''); @@ -22,14 +25,28 @@ export default function index({userName}: any) { } }; + + const handleChange = (event: SelectChangeEvent) => { setText(event.target.value); }; + + async function handleRegisterAboutUs() { + await api.post('/aboutUs', { + about: editorRef.current.value + }).then(res => { + console.log(res) + + }).catch(res => console.log(res)) + } + return (
+ + handleRegisterAboutUs(editorRef)} title='Enviar'/>
editorRef.current = editor} @@ -70,6 +87,8 @@ export default function index({userName}: any) { content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }' }} /> + + ) } diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index 5cdf3bb..5ca5a7c 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -8,9 +8,12 @@ import PageTitle from '../../../components/pageTitle/PageTitle' import { IndustryInfoView } from '../../../styles/layouts/industryInfo/IndustryInfoView' import InputUploadPdf from '../../../components/inputUploadPdf/inputUpload'; import { api } from '../../../services/api' - +import { Viewer } from '@react-pdf-viewer/core'; +import '@react-pdf-viewer/core/lib/styles/index.css'; import FormData from 'form-data'; + + import Snackbar from '@mui/material/Snackbar'; import MuiAlert, { AlertProps } from '@mui/material/Alert'; import { InputUploadView } from '../../../components/inputUploadPdf/inputUploadView' @@ -23,12 +26,12 @@ const Alert = React.forwardRef(function Alert( }); export default function industryInfo({userName}: any) { - const formData = new FormData(); + const [url, setUrl] = React.useState(''); - const [pdf, setPdf] = useState(); - function onChange(e) { - setPdf(e.target.files[0]) - } + const onChange = (e: React.ChangeEvent) => { + const files = e.target.files; + files.length > 0 && setUrl(URL.createObjectURL(files[0])); + }; const [openSnackSuccess, setOpenSnackSuccess] = useState(false); const [openSnackError, setOpenSnackError] = useState(false); @@ -75,7 +78,8 @@ export default function industryInfo({userName}: any) {
- + {/* */} +
@@ -83,6 +87,15 @@ export default function industryInfo({userName}: any) { {/* */}
+
+
+
+ + +
+
+
+ handleCreateClient()} title='Atualizar'/> diff --git a/src/pages/industryInfo.tsx b/src/pages/industryInfo.tsx index c387fb4..21b569c 100644 --- a/src/pages/industryInfo.tsx +++ b/src/pages/industryInfo.tsx @@ -35,7 +35,7 @@ export default function industryInfo({userName}: any) { function handleDownloadPdf() { api.get('/download').then(res => { - router.replace(res.data.path); + window.open(res.data.path); console.log(res.data); setOpenSnackSuccess(true) }).catch(res => { diff --git a/src/pages/pld/index.tsx b/src/pages/pld/index.tsx index 79a547c..bafb8a1 100644 --- a/src/pages/pld/index.tsx +++ b/src/pages/pld/index.tsx @@ -10,6 +10,7 @@ import { parseCookies } from 'nookies'; import React, { useEffect, useState } from 'react' import BasicButton from '../../components/buttons/basicButton/BasicButton'; +import { BasicButtonView } from '../../components/buttons/basicButton/BasicButtonView'; import { LineBarChart } from '../../components/graph/LineBarChart'; import LineChart from '../../components/graph/LineChart'; import Header from '../../components/header/Header' @@ -206,7 +207,11 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN } +
+ +
+
setPage('perMouth')}>

Valores Diários

diff --git a/src/styles/layouts/pld/PldView.ts b/src/styles/layouts/pld/PldView.ts index 539ec3f..d9239cf 100644 --- a/src/styles/layouts/pld/PldView.ts +++ b/src/styles/layouts/pld/PldView.ts @@ -149,6 +149,10 @@ export const PldTableView = styled.main` margin: 20px; } } + + .btnDownload{ + margin-top:6px; + } ` export const PldGraphView = styled.main` diff --git a/yarn.lock b/yarn.lock index 388eeb8..664df8a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1390,6 +1390,11 @@ version "2.11.5" resolved "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz" +"@react-pdf-viewer/core@^3.5.0": + version "3.5.0" + resolved "https://registry.yarnpkg.com/@react-pdf-viewer/core/-/core-3.5.0.tgz#bb18b87330bfd01d5c31980b820ef58dc1c50a19" + integrity sha512-fu9vi8lzpFtQQqu8XUzSzp5aQYD5YxmJQ0CxOuRrANU7z1kft+TbdyiDOpWoeX2VC0/oyclBxUwleVYv+g1f1w== + "@rushstack/eslint-patch@^1.1.3": version "1.1.3" resolved "https://registry.npmjs.org/@rushstack/eslint-patch/-/eslint-patch-1.1.3.tgz" From 16b927b42bf691c0e94256690ee47a3824b742d4 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Fri, 24 Jun 2022 20:48:09 -0300 Subject: [PATCH 03/17] in a race against the clock --- src/components/graph/DemRegXDemConChart.tsx | 154 ++++++++++++++++++ .../graph/DiscretizedConsumptionChart.tsx | 93 +++++++++++ .../graph/DiscretizedConsumptionChartLine.tsx | 91 +++++++++++ src/components/graph/SingleBar.tsx | 5 +- src/components/graph/fatorPotenciaChart.tsx | 97 +++++++++++ src/components/sidebar/Sidebar.tsx | 5 +- src/contexts/AuthContext.tsx | 20 ++- src/pages/accumulatedSavings.tsx | 7 +- src/pages/administrative/faq/index.tsx | 4 +- src/pages/administrative/general.tsx | 11 +- src/pages/chartTelemetry.tsx | 105 ++++++++++-- src/pages/pld/index.tsx | 9 +- src/pages/telemetria.tsx | 75 +++------ .../layouts/Telemetria/TelemetriaView.ts | 15 ++ .../layouts/administerView/faq/faqView.ts | 17 ++ .../notification/notificationView.ts | 18 +- 16 files changed, 631 insertions(+), 95 deletions(-) create mode 100644 src/components/graph/DemRegXDemConChart.tsx create mode 100644 src/components/graph/DiscretizedConsumptionChart.tsx create mode 100644 src/components/graph/DiscretizedConsumptionChartLine.tsx create mode 100644 src/components/graph/fatorPotenciaChart.tsx diff --git a/src/components/graph/DemRegXDemConChart.tsx b/src/components/graph/DemRegXDemConChart.tsx new file mode 100644 index 0000000..127909d --- /dev/null +++ b/src/components/graph/DemRegXDemConChart.tsx @@ -0,0 +1,154 @@ +import React, { useRef, useEffect } from 'react'; +import { + Chart as ChartJS, + LinearScale, + CategoryScale, + BarElement, + PointElement, + LineElement, + Legend, + Tooltip, +} from 'chart.js'; +import { Chart } from 'react-chartjs-2'; +import faker from 'faker'; +import { ChartView } from './ChartView'; +import ChartTitle from './ChartTitle'; +import pattern from 'patternomaly' + +ChartJS.register( + LinearScale, + CategoryScale, + BarElement, + PointElement, + LineElement, + Legend, + Tooltip +); + +// function triggerTooltip(chart: ChartJS | null) { +// const tooltip = chart?.tooltip; + +// if (!tooltip) { +// return; +// } + +// if (tooltip.getActiveElements().length > 0) { +// tooltip.setActiveElements([], { x: 0, y: 0 }); +// } else { +// const { chartArea } = chart; + +// tooltip.setActiveElements( +// [ +// { +// datasetIndex: 0, +// index: 2, +// }, +// { +// datasetIndex: 1, +// index: 2, +// }, +// ], +// { +// x: (chartArea.left + chartArea.right) / 2, +// y: (chartArea.top + chartArea.bottom) / 2, +// } +// ); +// } + +// chart.update(); +// } + +interface LineBarChartInterface { + title: string, + subtitle: string, + data1: any, + data2?: any, + red?: any, + label: any, + dataset1?: string, + dataset2?: string, + dataset3?: string, + barLabel?: boolean | undefined, + hashurado?: boolean | undefined, + reais?: boolean | undefined +} + +export function DemRegXDemConChart({ + title, + subtitle, + data1, + data2, + label, + red, + dataset1, + dataset2, + dataset3, + barLabel + }: LineBarChartInterface) { + const chartRef = useRef(null); + + const currentTime = new Date(); + + const labels = label + + const options: any = { + responsive: true, + plugins: { + datalabels: { + display: true, + color: barLabel? 'black' : "rgba(255, 255, 255, 0)", + // backgroundColor: '#255488', + formatter: Math.round, + anchor: "end", + offset: -20, + align: "start", + font: { + size: 12 + } + }, + legend: { + position: 'bottom' as const, + }, + title: { + display: true, + text: '', + }, + }, + }; + + const data = { + labels, + datasets: [ + { + type: 'line' as const, + label: 'Demanda Contratada', + borderColor: red? + '#f00' : '#0c9200', + borderWidth: 2, + fill: false, + data: data1.map(value => value.dem_cont), + }, + { + type: 'bar' as const, + label: 'Demanda Registrada', + backgroundColor: '#255488', + data: data2.map(value => value.dem_reg), + }, + ], + }; + + useEffect(() => { + const chart = chartRef.current; + + // triggerTooltip(chart); + }, []); + + return ( + + +
+ +
+
+ ) +} diff --git a/src/components/graph/DiscretizedConsumptionChart.tsx b/src/components/graph/DiscretizedConsumptionChart.tsx new file mode 100644 index 0000000..210e868 --- /dev/null +++ b/src/components/graph/DiscretizedConsumptionChart.tsx @@ -0,0 +1,93 @@ +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 } from 'react-chartjs-2'; + +import ChartTitle from './ChartTitle'; +import { ChartView } from './ChartView'; + +ChartJS.register( + CategoryScale, + LinearScale, + BarElement, + Title, + Tooltip, + Legend, + ChartDataLabels +); + +interface SingleBarInterface{ + title: string, + subtitle: string, + dataProps: any, + label: Array, + dataset: string, + barLabel?: boolean | undefined, + year?: boolean | undefined, + month?: boolean | undefined, + dataset1?: string, +} + +export function DiscretizedConsumptionChart({ title, subtitle, dataProps, label, dataset, barLabel, year, month }: SingleBarInterface) { + const currentTime = new Date(); + + const options: object = { + responsive: true, + series: { + downsample: { + threshold: 1000 + } + }, + plugins: { + datalabels: { + formatter: (value, ctx) => { + let sum = 0; + const dataArr = ctx.chart.data.datasets[0].data; + dataArr.map(data => { + sum += data; + }); + const percentage = (dataProps[ctx.dataIndex].econ_percentual*100).toFixed(0)+"%"; + const result = `${parseFloat(value).toFixed(0)}\n ${percentage}` + + return value==null? null : result + }, + display: true, + color: barLabel? 'black' : "rgba(255, 255, 255, 0)", + anchor: "end", + offset: -40, + align: "start", + font: { + size: 10 + } + }, + legend: { + position: 'bottom' as const, + }, + title: { + display: false, + text: '', + }, + }, + }; + + const labels = label; + + const data: any = { + labels, + datasets: [ + { + label: dataset, + data: dataProps.map(value => value.consumo), + backgroundColor: '#255488' + }, + ], + } + + return ( + + + + + ) +} diff --git a/src/components/graph/DiscretizedConsumptionChartLine.tsx b/src/components/graph/DiscretizedConsumptionChartLine.tsx new file mode 100644 index 0000000..896a7dc --- /dev/null +++ b/src/components/graph/DiscretizedConsumptionChartLine.tsx @@ -0,0 +1,91 @@ +import React, { useState, useEffect } from 'react' + +import { Bar, Line } from 'react-chartjs-2'; + +import { ChartView } from './ChartView'; + +import { + Chart as ChartJS, + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend, + ScatterDataPoint, +} from 'chart.js'; +import ChartTitle from './ChartTitle'; + +ChartJS.register( + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend +); + + +interface ChartInterface { + title: string, + subtitle: string, + data1: any, + data2?: any, + data3?: any, + data4?: any, + label: any, + dataset1?: string, + dataset2?: string, + dataset3?: string, + dataset4?: string, + barLabel?: boolean | undefined +} + +export default function DiscretizedConsumptionChartLine({ title, subtitle, data1, data2, data3, data4, label, dataset1, dataset2, dataset3, dataset4, barLabel }: ChartInterface) { + const options: any = { + responsive: true, + plugins: { + datalabels: { + display: true, + color: barLabel? 'black' : "rgba(255, 255, 255, 0)", + formatter: Math.round, + anchor: "end", + offset: -20, + align: "start", + font: { + size: 12 + } + }, + legend: { + position: 'bottom' as const, + }, + title: { + display: true, + text: '', + }, + }, + }; + + const labels = label; + + const data = { + labels, + datasets: [ + { + label: dataset1, + data: data1.map(value => value.reativa), + borderColor: 'rgb(53, 162, 235)', + backgroundColor: 'rgba(53, 162, 235, 0)', + }, + ], + } + + return ( + + + + + ) +} diff --git a/src/components/graph/SingleBar.tsx b/src/components/graph/SingleBar.tsx index 8a48d33..ff71b3c 100644 --- a/src/components/graph/SingleBar.tsx +++ b/src/components/graph/SingleBar.tsx @@ -27,9 +27,6 @@ interface SingleBarInterface{ year?: boolean | undefined, month?: boolean | undefined, dataset1?: string, - - - } export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1, barLabel, year, month }: SingleBarInterface) { @@ -85,7 +82,7 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1 return parseFloat(value.economia_acumulada).toFixed(2) }), backgroundColor: (value, ctx) => { - return dataProps[value.dataIndex].dad_estimado == false ? '#255488' : '#C2d5fb' + return dataProps[value.dataIndex]?.dad_estimado == false ? '#255488' : '#C2d5fb' }, }, diff --git a/src/components/graph/fatorPotenciaChart.tsx b/src/components/graph/fatorPotenciaChart.tsx new file mode 100644 index 0000000..ce5af02 --- /dev/null +++ b/src/components/graph/fatorPotenciaChart.tsx @@ -0,0 +1,97 @@ +import React, { useState, useEffect } from 'react' + +import { Bar, Line } from 'react-chartjs-2'; + +import { ChartView } from './ChartView'; + +import { + Chart as ChartJS, + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend, + ScatterDataPoint, +} from 'chart.js'; +import ChartTitle from './ChartTitle'; + +ChartJS.register( + CategoryScale, + LinearScale, + PointElement, + LineElement, + Title, + Tooltip, + Legend +); + + +interface ChartInterface { + title: string, + subtitle: string, + data1: any, + data2?: any, + data3?: any, + data4?: any, + label: any, + dataset1?: string, + dataset2?: string, + dataset3?: string, + dataset4?: string, + barLabel?: boolean | undefined +} + +export default function FatorPotenciaChart({ title, subtitle, data1, data2, label, dataset1, dataset2, dataset3, dataset4, barLabel }: ChartInterface) { + const options: any = { + responsive: true, + plugins: { + datalabels: { + display: true, + color: barLabel? 'black' : "rgba(255, 255, 255, 0)", + formatter: Math.round, + anchor: "end", + offset: -20, + align: "start", + font: { + size: 12 + } + }, + legend: { + position: 'bottom' as const, + }, + title: { + display: true, + text: '', + }, + }, + }; + + const labels = label; + + const data = { + labels, + datasets: [ + { + label: dataset1? dataset1 : 'Dataset 1', + data: data1.map(value => value.fp), + borderColor: 'rgb(53, 162, 235)', + backgroundColor: 'rgba(53, 162, 235, 0)', + }, + { + label: dataset2? dataset2 : '', + data: data2.map(value => value.f_ref), + borderColor: 'rgb(0, 0, 0)' , + backgroundColor: 'rgba(255, 145, 0, 0)' , + }, + ], + } + + return ( + + + + + ) +} diff --git a/src/components/sidebar/Sidebar.tsx b/src/components/sidebar/Sidebar.tsx index d113e95..696ecde 100644 --- a/src/components/sidebar/Sidebar.tsx +++ b/src/components/sidebar/Sidebar.tsx @@ -67,7 +67,7 @@ export default function Sidebar() {
  • {'Sobre Nós'}
  • {'FAQ >'}
  • {'Notificações >'}
  • -
  • {'Info Setorial'}
  • +
  • {'Info Setorial'}
  • Deseja realmente sair ? - + @@ -90,6 +90,7 @@ export default function Sidebar() { +
    setViewModal(!viewModal)} > diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 74735b8..4dd6c8f 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -31,7 +31,17 @@ export function AuthProvider({children}: {children: React.ReactNode}) { const isAuthenticated = !!user + function signOut() { + destroyCookie(null, 'user-client_id') + destroyCookie(null, 'user-name') + destroyCookie(null, 'user-role') + destroyCookie(null, 'user-id') + destroyCookie(null, '@smartAuth-token') + } + async function signIn({email, password}: SignInData) { + await signOut() + const { token, user, exception }: any = await signInRequest({ email, password @@ -51,6 +61,9 @@ export function AuthProvider({children}: {children: React.ReactNode}) { if (user.name) setCookie(undefined, 'user-name', user.name) + if (user.client_id) + setCookie(undefined, 'user-client_id', user.client_id) + api.defaults.headers['Authorization'] = `Bearer ${token}` if (!exception) { @@ -65,13 +78,6 @@ export function AuthProvider({children}: {children: React.ReactNode}) { } } - function signOut() { - destroyCookie(null, 'user-name') - destroyCookie(null, 'user-role') - destroyCookie(null, 'user-id') - destroyCookie(null, '@smartAuth-token') - } - return ( {children} diff --git a/src/pages/accumulatedSavings.tsx b/src/pages/accumulatedSavings.tsx index 53467d9..7fffbce 100644 --- a/src/pages/accumulatedSavings.tsx +++ b/src/pages/accumulatedSavings.tsx @@ -22,7 +22,12 @@ export default function AccumulatedSavings({graphData, years, userName}: any) {
    { + if (parseFloat(a.mes.slice(0,2)) > parseFloat(b.mes.slice(1,2))) return 1 + if (parseFloat(a.mes.slice(0,2)) < parseFloat(b.mes.slice(1,2))) return -1 + + return 0 + })} label={years} barLabel month/>
    diff --git a/src/pages/administrative/faq/index.tsx b/src/pages/administrative/faq/index.tsx index b7e428d..ecb3093 100644 --- a/src/pages/administrative/faq/index.tsx +++ b/src/pages/administrative/faq/index.tsx @@ -66,7 +66,6 @@ export default function Sidebar({faqData, userName} : any ) { if (reason === 'clickaway') { return; } - setOpenSnackError(false); setOpenSnackSuccess(false); }; @@ -76,14 +75,13 @@ export default function Sidebar({faqData, userName} : any ) { if (reason === 'clickaway') { return; } - setOpenSnackErrorDelete(false); setOpenSnackSuccessDelete(false); }; async function handleDeleteNotification(id: any) { await id.map((value) => { - api.delete(`/faq/${value.id}`).then(res => { + api.delete(`/faq/${value}`).then(res => { setOpenSnackSuccessDelete(true) setOpenModalInativar(false) window.location.reload() diff --git a/src/pages/administrative/general.tsx b/src/pages/administrative/general.tsx index 1d5b7bf..caf890c 100644 --- a/src/pages/administrative/general.tsx +++ b/src/pages/administrative/general.tsx @@ -1,12 +1,9 @@ -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 TextField from '@mui/material/TextField'; +import { SelectChangeEvent } from '@mui/material/Select'; import { Editor } from '@tinymce/tinymce-react' import { GetServerSideProps } from 'next'; import { parseCookies } from 'nookies'; import React, { useRef, useState } from 'react' +import BasicButton from '../../components/buttons/basicButton/BasicButton'; import Header from '../../components/header/Header'; import PageTitle from '../../components/pageTitle/PageTitle'; @@ -30,7 +27,9 @@ export default function index({userName}: any) {
    -
    +
    + console.log()}/> +
    editorRef.current = editor} initialValue='

    A SMART ENERGIA é uma consultoria independente especializada em Gestão de Energia Elétrica, consolidada como uma das três maiores consultorias do Brasil. diff --git a/src/pages/chartTelemetry.tsx b/src/pages/chartTelemetry.tsx index 343af3f..41cda3b 100644 --- a/src/pages/chartTelemetry.tsx +++ b/src/pages/chartTelemetry.tsx @@ -1,7 +1,7 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { SingleBar } from '../components/graph/SingleBar' import { ChatTelemetryView } from '../styles/layouts/ChatTelemetry/ChatTelemetryView' -import { useRouter } from 'next/router' +// import router, { useRouter } from 'next/router' import { FatorPotencia } from '../services/fatorPotencia' import { ConsumoDecretizadoBar } from '../services/consumoDiscretizadoBar' @@ -18,6 +18,12 @@ import Typography from '@mui/material/Typography'; import Modal from '@mui/material/Modal'; import { GetServerSideProps } from 'next' import { parseCookies } from 'nookies' +import getAPIClient from '../services/ssrApi' +import { api } from '../services/api' +import FatorPotenciaChart from '../components/graph/fatorPotenciaChart' +import { DemRegXDemConChart } from '../components/graph/demRegXDemConChart' +import { DiscretizedConsumptionChart } from '../components/graph/DiscretizedConsumptionChart' +import DiscretizedConsumptionChartLine from '../components/graph/DiscretizedConsumptionChartLine' const style = { display: 'flex', @@ -45,6 +51,65 @@ export default function chartTelemetry({userName}) { const [openDemandaContratada, setOpenDemandaContratada] = useState(false); const handleCloseDemandaContratada = () => setOpenDemandaContratada(false); + const [fatorPotenciaData, setFatorPotenciaData] = useState([]); + const [demRegXDemCon, setDemRegXDemCon] = useState([]); + const [discretizedConsumptionData, setDiscretizedConsumptionData] = useState([]); + const [discretizedConsumptionDataReativa, setDiscretizedConsumptionDataReativa] = useState([]); + + const { ['user-cod_client']: cod_client } = parseCookies() + + async function getChartsData() { + await api.post('/telemetry/powerFactor', { + "filters": [ + {"type" : "=", "field": "med_5min.ponto", "value": "RSZFNAENTR101P"}, + {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + ] + }).then(res => { + setFatorPotenciaData(res.data.data) + }).catch(res => { + console.log(res) + }) + + await api.post('/telemetry/demand', { + "filters": [ + {"type" : "=", "field": "med_5min.ponto", "value": "RSZFNAENTR101P"}, + {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + ] + }).then(res => { + setDemRegXDemCon(res.data.data) + }).catch(res => { + console.log(res) + }) + + await api.post('/telemetry/discretization', { + "type": "5_min", + "filters": [ + {"type" : "=", "field": "med_5min.ponto", "value": "RSZFNAENTR101P"}, + {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + ] + }).then(res => { + setDiscretizedConsumptionData(res.data.data) + }).catch(res => { + console.log(res) + }) + + await api.post('/telemetry/discretization', { + "type": "5_min", + "filters": [ + {"type" : "=", "field": "med_5min.ponto", "value": "RSZFNAENTR101P"}, + {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + ] + }).then(res => { + setDiscretizedConsumptionDataReativa(res.data.data) + }).catch(res => { + console.log(res) + }) + } + + useEffect(() => { + getChartsData() + }, []) + return ( @@ -54,7 +119,7 @@ export default function chartTelemetry({userName}) {

    setOpenFatorPotencia(true)}> - + value.hora)} />
    - +
    setOpenConsumoDiscretizado1(true)}> - + parseFloat(data.reativa).toFixed(3))} />
    - + data.reativa)} />
    setOpenConsumoDiscretizado2(true)}> - + value.minut)} dataset={'Consumo'} dataset1='Estimado' month/>
    setOpenDemandaContratada(true)}> - + value.hora)} title='Demanda Contratada X Registrada' subtitle='' red/>
    - + value.hora)} title='Demanda Contratada X Registrada' subtitle='' red/>
    @@ -114,8 +179,26 @@ export default function chartTelemetry({userName}) { } export const getServerSideProps: GetServerSideProps = async (ctx) => { + const apiClient = getAPIClient(ctx) + const { ['@smartAuth-token']: token } = parseCookies(ctx) const { ['user-name']: userName } = parseCookies(ctx) + const { ['user-cod_client']: cod_client } = parseCookies(ctx) + + const fatorPotenciaChart = [] + + console.log('olha os query ai', ctx.query) + + // await apiClient.post('/telemetry/powerFactor', { + // "filters": [ + // {"type" : "=", "field": "med_5min.ponto", "value": cod_client}, + // {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + // ] + // }).then(res => { + // fatorPotenciaChart = res.data + // }).catch(res => { + // console.log(res) + // }) if (!token) { return { @@ -128,8 +211,8 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { - userName + userName, + fatorPotenciaChart } } } - diff --git a/src/pages/pld/index.tsx b/src/pages/pld/index.tsx index 79a547c..6c5ac02 100644 --- a/src/pages/pld/index.tsx +++ b/src/pages/pld/index.tsx @@ -127,6 +127,8 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN return 'dullRed' } + const dateFormated = new Date() + useEffect(() => { getDataByHour() getDataByDay() @@ -174,7 +176,7 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN if (index === 0) { return <> - Max + Máximo {parseFloat(data.nordeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.norte_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sudeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} @@ -184,7 +186,7 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN } else if (index===1) { return <> - Min + Mínimo {parseFloat(data.nordeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.norte_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} {parseFloat(data.sudeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})} @@ -288,7 +290,8 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN
    diff --git a/src/pages/telemetria.tsx b/src/pages/telemetria.tsx index 9a9adc8..c24a117 100644 --- a/src/pages/telemetria.tsx +++ b/src/pages/telemetria.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import { useRouter } from 'next/router' +import React, { useState } from 'react'; +import router, { useRouter } from 'next/router' import Banner from '../components/banner/Banner'; import { TelemetriaView, Buttons} from '../styles/layouts/Telemetria/TelemetriaView'; @@ -18,16 +18,15 @@ import RenderIf from '../utils/renderIf'; import { GetServerSideProps } from 'next'; import { parseCookies } from 'nookies'; - - - export default function Telemetria({userName}: any) { - const [unity, setUnity] = React.useState(''); - const [startDate, setStartDate] = React.useState(''); - const [endDate, setEndDate] = React.useState(''); - const [discretization, setDiscretization] = React.useState(''); + const [unity, setUnity] = useState(''); + const [startDate, setStartDate] = useState(''); + const [endDate, setEndDate] = useState(''); + const [discretization, setDiscretization] = useState(''); - const [showChart, setShowChart] = React.useState(false); + const [date, setDate] = useState(''); + + const [showChart, setShowChart] = useState(false); const handleChange = (event: SelectChangeEvent) => { // setAge(event.target.value); @@ -72,50 +71,13 @@ export default function Telemetria({userName}: any) {

    Data inicial

    - - Data Inicial - - + setStartDate(value.target.value)}/>
    -

    Data Final

    - - Data Final - - +

    Data final

    + + setEndDate(value.target.value)}/>
    @@ -133,10 +95,6 @@ export default function Telemetria({userName}: any) { Nenhum - 07/09/2021 - Filial 3 - Twenty - Thirty
    @@ -147,7 +105,12 @@ export default function Telemetria({userName}: any) { - + router.replace('/chartTelemetry', { query: { + startDate, + endDate, + discretization + }})}/> + router.replace('/chartTelemetry')}/> setShowChart(!showChart)} green /> diff --git a/src/styles/layouts/Telemetria/TelemetriaView.ts b/src/styles/layouts/Telemetria/TelemetriaView.ts index fb3f214..863e642 100644 --- a/src/styles/layouts/Telemetria/TelemetriaView.ts +++ b/src/styles/layouts/Telemetria/TelemetriaView.ts @@ -12,6 +12,21 @@ export const TelemetriaView = styled.main` margin: 0 0 0 10px; } + input { + width: 15rem; + height: 2.5rem; + + padding: 14px; + + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + font-weight: 400; + + border-radius: 6px; + border: solid gray 1px; + + background-color: #F9F9F9; + } + span { font-family: 'Inter'; font-style: normal; diff --git a/src/styles/layouts/administerView/faq/faqView.ts b/src/styles/layouts/administerView/faq/faqView.ts index 7680a37..5c2be1b 100644 --- a/src/styles/layouts/administerView/faq/faqView.ts +++ b/src/styles/layouts/administerView/faq/faqView.ts @@ -42,6 +42,23 @@ export const FaqView = styled.nav` margin-left: 19px; } + .MuiBox-root .css-4y2i0o { + :-webkit-scrollbar { + width: 15px!important; + } + :-webkit-scrollbar-track { + background-color: #EFEFEF!important; + } + :-webkit-scrollbar-thumb { + background-color: rgb(37,79,127)!important; + border: 3px solid #EFEFEF!important; + border-radius: 10px!important + } + :-webkit-scrollbar-thumb:hover { + background-color: #1d3e63!important; + } + } + /* .teste{ display: flex; diff --git a/src/styles/layouts/administerView/notification/notificationView.ts b/src/styles/layouts/administerView/notification/notificationView.ts index cc0aca2..b57f4d9 100644 --- a/src/styles/layouts/administerView/notification/notificationView.ts +++ b/src/styles/layouts/administerView/notification/notificationView.ts @@ -77,7 +77,21 @@ export const NotificationView = styled.nav` margin-left: 16px; } - - + .MuiBox-root .css-4y2i0o { + :-webkit-scrollbar { + width: 15px!important; + } + :-webkit-scrollbar-track { + background-color: #EFEFEF!important; + } + :-webkit-scrollbar-thumb { + background-color: rgb(37,79,127)!important; + border: 3px solid #EFEFEF!important; + border-radius: 10px!important + } + :-webkit-scrollbar-thumb:hover { + background-color: #1d3e63!important; + } + } ` From 7aff508092ff859097a3584e55d768d152ea727c Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Sun, 26 Jun 2022 12:23:26 -0300 Subject: [PATCH 04/17] resolv conflicts --- src/pages/administrative/general.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/pages/administrative/general.tsx b/src/pages/administrative/general.tsx index 1ffacd2..aa7950a 100644 --- a/src/pages/administrative/general.tsx +++ b/src/pages/administrative/general.tsx @@ -24,20 +24,14 @@ export default function index({userName}: any) { console.log(editorRef.current.getContent()); } }; - - - const handleChange = (event: SelectChangeEvent) => { setText(event.target.value); }; - - async function handleRegisterAboutUs() { await api.post('/aboutUs', { about: editorRef.current.value }).then(res => { console.log(res) - }).catch(res => console.log(res)) } From b731c80830209d1061009243fd53f2ccd81cac6d Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Mon, 27 Jun 2022 10:55:07 -0300 Subject: [PATCH 05/17] update Header --- src/components/header/Header.tsx | 42 +++++++++++++++++++--- src/pages/administrative/clients/index.tsx | 29 ++++++++++++--- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index 1fba829..b17d841 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -6,6 +6,8 @@ import TextField from '@mui/material/TextField'; import { HeaderView } from './HeaderView' import { parseCookies } from 'nookies'; +import { GetServerSideProps } from 'next'; +import getAPIClient from '../../services/ssrApi'; function stringToColor(string: string) { let hash = 0; @@ -37,20 +39,21 @@ function stringAvatar(name: string) { interface headerInterface { name: string, admin?: boolean | undefined + logo?: string } -export default function Header({ name, admin }: headerInterface) { +export default function Header({ name, admin, logo }: headerInterface) { return (
    - {/* { + { !admin? - + : null - } */} + }

    olá, {name} @@ -61,3 +64,34 @@ export default function Header({ name, admin }: headerInterface) { ) } + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const apiClient = getAPIClient(ctx) + const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) + + let userData = []; + + await apiClient.get('/user').then(res => { + userData = res.data.data + }).catch(res => { + // console.log(res) + }) + + if (!token) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + return { + props: { + userData, + userName + } + } +} + diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index 70b0b15..ae8490e 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -23,6 +23,7 @@ import getAPIClient from '../../../services/ssrApi' import FormData from 'form-data' import { InputUploadView } from '../../../components/inputUploadImg/inputUploadView' +import { FormControl, InputLabel, MenuItem, Select } from '@mui/material' const style = { position: 'absolute' as const, @@ -66,7 +67,7 @@ export default function clients({ clients, userName }) { const handleClose = () => setOpen(false) const [openModal, setOpenModal] = useState(false) - + const [nivelAcess, setnivelAcess] = useState(0); const [openSnackSuccess, setOpenSnackSuccess] = useState(false) const [openSnackError, setOpenSnackError] = useState(false) const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = @@ -115,7 +116,7 @@ export default function clients({ clients, userName }) { formData.append('password_confirmation', password_confirmation) formData.append('client_id', client_id) formData.append('profile_picture', logo) - + formData.append('role', 0) api .post('/user', formData) .then((res) => { @@ -127,6 +128,7 @@ export default function clients({ clients, userName }) { setOpenSnackError(true) }) } + async function handleDeleteClient(id: any) { await id.map((client) => { api @@ -341,8 +343,27 @@ export default function clients({ clients, userName }) {

    -
    -
    + + +
    + + + Nivel de acesso + + +
    + setOpen(false)} /> Date: Mon, 27 Jun 2022 11:14:22 -0300 Subject: [PATCH 06/17] add create client with role --- .../buttons/gradientButton/GradientButton.tsx | 12 ++--- .../gradientButton/GradientButtonView.ts | 2 - src/components/graph/SingleBar.tsx | 20 +++++-- src/components/header/Header.tsx | 3 +- src/pages/administrative/clients/index.tsx | 10 ++-- src/pages/chartTelemetry.tsx | 17 ++++-- src/pages/telemetria.tsx | 21 +++++--- .../layouts/Telemetria/TelemetriaView.ts | 52 +++++++++++++++++++ 8 files changed, 106 insertions(+), 31 deletions(-) diff --git a/src/components/buttons/gradientButton/GradientButton.tsx b/src/components/buttons/gradientButton/GradientButton.tsx index 9e8306f..78d9c53 100644 --- a/src/components/buttons/gradientButton/GradientButton.tsx +++ b/src/components/buttons/gradientButton/GradientButton.tsx @@ -14,15 +14,13 @@ interface GradientButtonInterface { onClick?: () => void } -export default function GradientButton({ title, description, orange, purple, green, link, onClick }: GradientButtonInterface) { - const router = useRouter() - - function handleClick() { - onClick() - } +export default function GradientButton({ title, description, orange, purple, green, onClick }: GradientButtonInterface) { + // function handleClick() { + // onClick() + // } return ( - link? router.push('/chartTelemetry') : handleClick()} > +

    {title}

    {description}

    diff --git a/src/components/buttons/gradientButton/GradientButtonView.ts b/src/components/buttons/gradientButton/GradientButtonView.ts index 4954b4f..c324f99 100644 --- a/src/components/buttons/gradientButton/GradientButtonView.ts +++ b/src/components/buttons/gradientButton/GradientButtonView.ts @@ -32,8 +32,6 @@ export const GradientButtonView = styled.button` border-style: none; - cursor: pointer; - * { margin: 0; padding: 0; diff --git a/src/components/graph/SingleBar.tsx b/src/components/graph/SingleBar.tsx index ff71b3c..f73e27d 100644 --- a/src/components/graph/SingleBar.tsx +++ b/src/components/graph/SingleBar.tsx @@ -24,12 +24,10 @@ interface SingleBarInterface{ label: Array, dataset: string, barLabel?: boolean | undefined, - year?: boolean | undefined, - month?: boolean | undefined, - dataset1?: string, + brutoAnual?: boolean | undefined, } -export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1, barLabel, year, month }: SingleBarInterface) { +export function SingleBar({ title, subtitle, dataProps, label, dataset, barLabel, brutoAnual }: SingleBarInterface) { const currentTime = new Date(); const options: object = { @@ -76,6 +74,11 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1 const data: any = { labels, datasets: [ + { + label: '', + data: [], + backgroundColor: 'transparent', + }, { label: dataset, data: dataProps.map((value, index) => { @@ -85,7 +88,14 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, dataset1 return dataProps[value.dataIndex]?.dad_estimado == false ? '#255488' : '#C2d5fb' }, }, - + { + label: '', + data: [dataProps[0]?.economia_acumulada?dataProps[0].economia_acumulada*1.1:1], + backgroundColor: 'transparent', + datalabels: { + display: false + } + }, ], } diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index b17d841..bcb8f28 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -50,7 +50,8 @@ export default function Header({ name, admin, logo }: headerInterface) {
    { !admin? - + // + null : null } diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index ae8490e..0bb0f38 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -67,7 +67,7 @@ export default function clients({ clients, userName }) { const handleClose = () => setOpen(false) const [openModal, setOpenModal] = useState(false) - const [nivelAcess, setnivelAcess] = useState(0); + const [nivelAcess, setnivelAcess] = useState(2); const [openSnackSuccess, setOpenSnackSuccess] = useState(false) const [openSnackError, setOpenSnackError] = useState(false) const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = @@ -116,9 +116,9 @@ export default function clients({ clients, userName }) { formData.append('password_confirmation', password_confirmation) formData.append('client_id', client_id) formData.append('profile_picture', logo) - formData.append('role', 0) - api - .post('/user', formData) + formData.append('role', nivelAcess) + + api.post('/user', formData) .then((res) => { setOpenSnackSuccess(true) setOpenModalInativar(false) @@ -358,7 +358,7 @@ export default function clients({ clients, userName }) { fullWidth > Administrador - Cliente + Cliente diff --git a/src/pages/chartTelemetry.tsx b/src/pages/chartTelemetry.tsx index 41cda3b..a3fc940 100644 --- a/src/pages/chartTelemetry.tsx +++ b/src/pages/chartTelemetry.tsx @@ -21,9 +21,11 @@ import { parseCookies } from 'nookies' import getAPIClient from '../services/ssrApi' import { api } from '../services/api' import FatorPotenciaChart from '../components/graph/fatorPotenciaChart' -import { DemRegXDemConChart } from '../components/graph/demRegXDemConChart' +// import { DemRegXDemConChart } from '../components/graph/demRegXDemConChart' import { DiscretizedConsumptionChart } from '../components/graph/DiscretizedConsumptionChart' import DiscretizedConsumptionChartLine from '../components/graph/DiscretizedConsumptionChartLine' +import router, { useRouter } from 'next/router' +import { DemRegXDemConChart } from '../components/graph/DemRegXDemConChart' const style = { display: 'flex', @@ -58,11 +60,16 @@ export default function chartTelemetry({userName}) { const { ['user-cod_client']: cod_client } = parseCookies() + const router = useRouter() + + const {startDate, endDate} = router.query + async function getChartsData() { + console.log(router.query) await api.post('/telemetry/powerFactor', { "filters": [ {"type" : "=", "field": "med_5min.ponto", "value": "RSZFNAENTR101P"}, - {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + {"type" : "between", "field": "dia_num", "value": [startDate, endDate]} ] }).then(res => { setFatorPotenciaData(res.data.data) @@ -73,7 +80,7 @@ export default function chartTelemetry({userName}) { await api.post('/telemetry/demand', { "filters": [ {"type" : "=", "field": "med_5min.ponto", "value": "RSZFNAENTR101P"}, - {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + {"type" : "between", "field": "dia_num", "value": [startDate, endDate]} ] }).then(res => { setDemRegXDemCon(res.data.data) @@ -85,7 +92,7 @@ export default function chartTelemetry({userName}) { "type": "5_min", "filters": [ {"type" : "=", "field": "med_5min.ponto", "value": "RSZFNAENTR101P"}, - {"type" : "between", "field": "dia_num", "value": ["2022-01-03", "2022-01-03"]} + {"type" : "between", "field": "dia_num", "value": [startDate, endDate]} ] }).then(res => { setDiscretizedConsumptionData(res.data.data) @@ -156,7 +163,7 @@ export default function chartTelemetry({userName}) { aria-describedby="modal-modal-description" > - + diff --git a/src/pages/telemetria.tsx b/src/pages/telemetria.tsx index c24a117..707ca85 100644 --- a/src/pages/telemetria.tsx +++ b/src/pages/telemetria.tsx @@ -105,12 +105,21 @@ export default function Telemetria({userName}: any) { - router.replace('/chartTelemetry', { query: { - startDate, - endDate, - discretization - }})}/> - router.replace('/chartTelemetry')}/> + + {/* */} + + + {/* router.replace('/chartTelemetry')}/> */} setShowChart(!showChart)} green /> diff --git a/src/styles/layouts/Telemetria/TelemetriaView.ts b/src/styles/layouts/Telemetria/TelemetriaView.ts index 863e642..77238d0 100644 --- a/src/styles/layouts/Telemetria/TelemetriaView.ts +++ b/src/styles/layouts/Telemetria/TelemetriaView.ts @@ -80,6 +80,58 @@ export const Buttons = styled.div` padding-left: 100px; padding-right: 100px; + button { + display: flex; + justify-content: center; + align-items: center; + + flex-direction: column; + border-radius: 2px; + + width: 30%; + min-width: 240px; + height: 110px; + min-height: 110px; + margin-bottom: 25px; + + font-family: 'Poppins'; + font-size: 10px; + + color: #FFFFFF; + + :first-child { + background: linear-gradient(200.86deg, #F48665 8.03%, #F48665 91.97%), #FFFFFF; + } + + box-shadow: 0.5px 3px 10px rgba(119, 119, 119, 0.1); + + border-style: none; + + * { + margin: 0; + padding: 0; + } + + p { + :first-child { + font-family: 'Poppins'; + font-style: normal; + font-weight: 700; + font-size: calc(20px); + + text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25); + } + :last-child { + font-family: 'Poppins'; + font-style: normal; + font-weight: 700; + font-size: 12; + + text-transform: uppercase; + } + } + } + @media (max-width: 942px) { align-items: center; justify-content: center; From e5bc75c60e3f5a194941932b013e199f95d757d1 Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Mon, 27 Jun 2022 14:57:03 -0300 Subject: [PATCH 07/17] update Header --- next.config.js | 4 ++++ src/components/header/Header.tsx | 20 +++++++++++++------- src/components/header/HeaderView.ts | 4 +--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/next.config.js b/next.config.js index 0c1f043..dee1618 100644 --- a/next.config.js +++ b/next.config.js @@ -4,6 +4,10 @@ const nextConfig = { compiler: { styledComponents: true, }, + images: { + domains: ["kluppdevelopment.s3.sa-east-1.amazonaws.com"] + } } module.exports = nextConfig + diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index bcb8f28..dba6dd7 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -27,22 +27,22 @@ function stringToColor(string: string) { return color; } -function stringAvatar(name: string) { +function stringAvatar(profile_picture: string) { return { - sx: { - bgcolor: stringToColor(name), - }, - children: `${name.split(' ')[0][0]}`, + + children: `${profile_picture}`, }; } + interface headerInterface { name: string, admin?: boolean | undefined logo?: string + profile_picture: string } -export default function Header({ name, admin, logo }: headerInterface) { +export default function Header({ name, admin, profile_picture }: headerInterface) { return (
    @@ -60,7 +60,13 @@ export default function Header({ name, admin, logo }: headerInterface) { olá, {name}

    - + { + !admin? + teste + : + null + } + ) diff --git a/src/components/header/HeaderView.ts b/src/components/header/HeaderView.ts index d123174..c3a4f2e 100644 --- a/src/components/header/HeaderView.ts +++ b/src/components/header/HeaderView.ts @@ -28,12 +28,10 @@ export const HeaderView = styled.header` min-width: 120px; height: 40px; - border-radius: 8px 0 0 8px; + border-radius: 8px; background-color: #254F7F; - transform: translateX(16px); - p{ color: white; margin-left: 15%; From 99f51b87cc5c3cdb5f9366e5a0591aee833e16a5 Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Mon, 27 Jun 2022 16:24:08 -0300 Subject: [PATCH 08/17] update --- src/components/graph/graphCard/ChartCard.tsx | 2 +- src/components/graph/graphCard/ChartCardView.ts | 5 +++++ src/components/header/Header.tsx | 3 ++- src/pages/administrative/industryInfo/index.tsx | 17 +++++++---------- src/pages/dashboard.tsx | 12 ++++++------ 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/components/graph/graphCard/ChartCard.tsx b/src/components/graph/graphCard/ChartCard.tsx index 96f2741..262e47e 100644 --- a/src/components/graph/graphCard/ChartCard.tsx +++ b/src/components/graph/graphCard/ChartCard.tsx @@ -70,7 +70,7 @@ export default function ChartCard({ title, subtitle, consumption, className, lin

    {title}

    - {subtitle} + {subtitle}
    {/* */}
    diff --git a/src/components/graph/graphCard/ChartCardView.ts b/src/components/graph/graphCard/ChartCardView.ts index 9ebabd2..752ebdb 100644 --- a/src/components/graph/graphCard/ChartCardView.ts +++ b/src/components/graph/graphCard/ChartCardView.ts @@ -37,6 +37,11 @@ export const ChartCardView = styled.article` color: #2F4CDD; } + span{ + display:block; + font-size: 12.8px; + } + .statusDot { max-width: 11px; max-height: 11px; diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index dba6dd7..7ac5ad2 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -62,7 +62,8 @@ export default function Header({ name, admin, profile_picture }: headerInterface { !admin? - teste + // teste + null : null } diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index 5ca5a7c..9d0f5b7 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -78,7 +78,7 @@ export default function industryInfo({userName}: any) {
    - {/* */} +
    @@ -87,16 +87,13 @@ export default function industryInfo({userName}: any) { {/* */} -
    -
    -
    - - -
    -
    -
    +
    + +
    - handleCreateClient()} title='Atualizar'/> + +
    + {/* handleCreateClient()} title='Atualizar'/> */} ) diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 3c234a4..db5750e 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -44,14 +44,14 @@ export default function Dashboard({grossAnualGraph, grossAnualYears, grossMensal
    - - + - + - + + title='' subtitle='' barLabel hashurado/> - value.mes.slice(3, 7).includes('2021')).sort((a, b) => { if (parseFloat(a.mes.slice(0,2)) > parseFloat(b.mes.slice(1,2))) return 1 if (parseFloat(a.mes.slice(0,2)) < parseFloat(b.mes.slice(1,2))) return -1 From 940c2f0a87d3a6c0d80b16a3ea83121538b8fd66 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Mon, 27 Jun 2022 16:47:26 -0300 Subject: [PATCH 09/17] fixing --- .vscode/settings.json | 3 ++ src/components/graph/SingleBar.tsx | 4 +- src/components/header/Header.tsx | 65 +++++++---------------------- src/components/header/HeaderView.ts | 18 ++------ src/contexts/AuthContext.tsx | 3 ++ src/pages/accumulatedSavings.tsx | 4 +- src/pages/costIndicator.tsx | 29 ------------- src/pages/estimatedCost.tsx | 4 +- src/pages/index.tsx | 2 +- src/pages/notifications.tsx | 2 +- src/pages/pld/index.tsx | 16 ++++--- src/pages/resumoOperacao.tsx | 2 +- src/services/auth.ts | 19 +++++---- 13 files changed, 54 insertions(+), 117 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7b6080f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.language": "pt-BR,en" +} diff --git a/src/components/graph/SingleBar.tsx b/src/components/graph/SingleBar.tsx index f73e27d..2fec803 100644 --- a/src/components/graph/SingleBar.tsx +++ b/src/components/graph/SingleBar.tsx @@ -75,9 +75,9 @@ export function SingleBar({ title, subtitle, dataProps, label, dataset, barLabel labels, datasets: [ { - label: '', + label: 'Estimado', data: [], - backgroundColor: 'transparent', + backgroundColor: '#C2d5fb', }, { label: dataset, diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index dba6dd7..c78683c 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -9,65 +9,28 @@ import { parseCookies } from 'nookies'; import { GetServerSideProps } from 'next'; import getAPIClient from '../../services/ssrApi'; -function stringToColor(string: string) { - let hash = 0; - let i; - - for (i = 0; i < string.length; i += 1) { - hash = string.charCodeAt(i) + ((hash << 5) - hash); - } - - let color = '#'; - - for (i = 0; i < 3; i += 1) { - const value = (hash >> (i * 8)) & 0xff; - color += `00${value.toString(16)}`.slice(-2); - } - - return color; -} - -function stringAvatar(profile_picture: string) { - return { - - children: `${profile_picture}`, - }; -} - - interface headerInterface { name: string, admin?: boolean | undefined logo?: string - profile_picture: string } -export default function Header({ name, admin, profile_picture }: headerInterface) { +export default function Header({name, admin}: headerInterface) { + const { ['user-profile_picture']: profile_picture } = parseCookies() + return ( -
    -
    -
    - { - !admin? - // - null - : - null - } -
    -

    - olá, {name} -

    -
    - { - !admin? - teste - : - null - } - -
    +
    +

    + olá, {name} +

    +
    + { + !admin? + + : + null + }
    ) } diff --git a/src/components/header/HeaderView.ts b/src/components/header/HeaderView.ts index c3a4f2e..bdeeb85 100644 --- a/src/components/header/HeaderView.ts +++ b/src/components/header/HeaderView.ts @@ -2,24 +2,10 @@ import styled from "styled-components"; export const HeaderView = styled.header` display: flex; - justify-content: space-between; - - margin: 0 0 75px 0; + justify-content: flex-end; width: 100%; - section { - width: 30%; - - :last-child { - display: flex; - justify-content: flex-end; - align-items: center; - - height: fit-content; - } - } - .icon { display: flex; align-items: center; @@ -32,6 +18,8 @@ export const HeaderView = styled.header` background-color: #254F7F; + margin-right: 20px; + p{ color: white; margin-left: 15%; diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 4dd6c8f..ab53abb 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -64,6 +64,9 @@ export function AuthProvider({children}: {children: React.ReactNode}) { if (user.client_id) setCookie(undefined, 'user-client_id', user.client_id) + if (user.profile_picture) + setCookie(undefined, 'user-profile_picture', user.profile_picture) + api.defaults.headers['Authorization'] = `Bearer ${token}` if (!exception) { diff --git a/src/pages/accumulatedSavings.tsx b/src/pages/accumulatedSavings.tsx index 7fffbce..894de4c 100644 --- a/src/pages/accumulatedSavings.tsx +++ b/src/pages/accumulatedSavings.tsx @@ -22,13 +22,13 @@ export default function AccumulatedSavings({graphData, years, userName}: any) {
    { + dataProps={graphData.sort((a, b) => { if (parseFloat(a.mes.slice(0,2)) > parseFloat(b.mes.slice(1,2))) return 1 if (parseFloat(a.mes.slice(0,2)) < parseFloat(b.mes.slice(1,2))) return -1 return 0 })} - label={years} barLabel month/> + label={years} barLabel/>
    ) diff --git a/src/pages/costIndicator.tsx b/src/pages/costIndicator.tsx index e3e2e6d..72cd245 100644 --- a/src/pages/costIndicator.tsx +++ b/src/pages/costIndicator.tsx @@ -4,41 +4,12 @@ import { parseCookies } from 'nookies' import React from 'react' import Chart from '../components/graph/Chart' -import { SingleBar } from '../components/graph/SingleBar' import Header from '../components/header/Header' import PageTitle from '../components/pageTitle/PageTitle' -import { dataEconomiaBruta } from '../services/economiaBruta' -import { dataEconomiaIndicador } from '../services/economiaIndicador' import getAPIClient from '../services/ssrApi' import { CostIndicatorView } from '../styles/layouts/economy/costIndicator/CostIndicatorView' -function verifyDataByYear(data) { - const currentYear = [] - const currentYearAux = data.filter(value => value.mes.slice(3, 7).includes('2021')) - console.log(currentYear.length) - console.log(currentYearAux.length) - - currentYearAux.sort((a, b) => { - if (parseFloat(a.mes.slice(0,2)) > parseFloat(b.mes.slice(1,2))) return 1 - if (parseFloat(a.mes.slice(0,2)) < parseFloat(b.mes.slice(1,2))) return -1 - - return 0 - }) - - // for (let i=0; currentYear.length <= currentYearAux.length; i++) { - // console.log(i, 'dentro do for') - // // console.log(currentYearAux.length, 'tamanho aux') - // if (currentYearAux[i].mes.slice(1,2)==i) { - // currentYear.push(currentYearAux[i]) - // console.log(currentYear.length, 'tamanho') - // } - // } - console.log(currentYearAux) -} - export default function CostIndicator({graphData, userName}: any) { - // console.log(graphData.filter((value, index) => value.mes.slice(3, 7).includes('2021')).map(value => value.custo_unit)) - return ( diff --git a/src/pages/estimatedCost.tsx b/src/pages/estimatedCost.tsx index e4915eb..7cc1d66 100644 --- a/src/pages/estimatedCost.tsx +++ b/src/pages/estimatedCost.tsx @@ -19,11 +19,11 @@ export default function EstimatedCost({graphData, userName}: any) { Smart Energia - Custos Estimados
    - +
    + label={ConsumoEstimado.label} title='' subtitle='' barLabel hashurado />
    ) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 981df29..09dd6e2 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -146,7 +146,7 @@ export default function Home() { } - label="Password" + label="Senha" /> Esqueceu a senha ? diff --git a/src/pages/notifications.tsx b/src/pages/notifications.tsx index 0871470..c9fa136 100644 --- a/src/pages/notifications.tsx +++ b/src/pages/notifications.tsx @@ -16,7 +16,7 @@ export default function Notifications({notificationData, userName}: any) { Smart Energia - Notificações
    - +
    { notificationData.map((value, index ) => { diff --git a/src/pages/pld/index.tsx b/src/pages/pld/index.tsx index 492e1d2..1fa7fc8 100644 --- a/src/pages/pld/index.tsx +++ b/src/pages/pld/index.tsx @@ -160,7 +160,12 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN { - tableData.data.map(data => { + tableData.data.sort((a, b) => { + if (parseFloat(a.year_month_formatted.slice(0,2)) > parseFloat(b.year_month_formatted.slice(1,2))) return 1 + if (parseFloat(a.year_month_formatted.slice(0,2)) < parseFloat(b.year_month_formatted.slice(1,2))) return -1 + + return 0 + }).map(data => { return <> {data.year_month_formatted} @@ -210,7 +215,7 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN
    - + console.log()} title='Download'/>
    @@ -251,9 +256,9 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN + width: '22%', + ml: 1 + }}> Mês -
    - {/* handleCreateClient()} title='Atualizar'/> */} + ) diff --git a/src/styles/layouts/industryInfo/IndustryInfoView.ts b/src/styles/layouts/industryInfo/IndustryInfoView.ts index 811d516..805dd85 100644 --- a/src/styles/layouts/industryInfo/IndustryInfoView.ts +++ b/src/styles/layouts/industryInfo/IndustryInfoView.ts @@ -26,4 +26,17 @@ export const IndustryInfoView = styled.main` color: #FFFFFF; } + .inputTeste{ + display: flex; + align-items: center; + margin-top:-10px; + width: 50%; + margin-bottom: 50px; + height: 50px; + background: white; + border: 3px solid #254F7F; + border-radius:10px; + } + + ` From c127735243e9e4f1f26a00253b370d5e1de85512 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Mon, 27 Jun 2022 21:21:44 -0300 Subject: [PATCH 11/17] fixing errors --- src/pages/administrative/industryInfo/index.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index 18a4297..70402dd 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -8,7 +8,7 @@ import PageTitle from '../../../components/pageTitle/PageTitle' import { IndustryInfoView } from '../../../styles/layouts/industryInfo/IndustryInfoView' import InputUploadPdf from '../../../components/inputUploadPdf/inputUpload'; import { api } from '../../../services/api' -import { Viewer } from '@react-pdf-viewer/core'; +// import { Viewer } from '@react-pdf-viewer/core'; import '@react-pdf-viewer/core/lib/styles/index.css'; import FormData from 'form-data'; import Snackbar from '@mui/material/Snackbar'; @@ -108,9 +108,7 @@ export default function industryInfo({userName}: any) { - - - + {/* handleCreateClient()} title='Atualizar'/> */} ) } From afe76104998315458c902385775dfda6e2c69a38 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Mon, 27 Jun 2022 21:32:24 -0300 Subject: [PATCH 12/17] fixing errors --- src/pages/dashboard.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index db5750e..7b2052e 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -46,17 +46,17 @@ export default function Dashboard({grossAnualGraph, grossAnualYears, grossMensal
    + label={grossAnualYears} barLabel/> + barLabel/> From c91f1cc218d7f689523038d7eca37c856b0dfd44 Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Tue, 28 Jun 2022 08:58:06 -0300 Subject: [PATCH 13/17] update upload --- .../administrative/industryInfo/index.tsx | 22 ++++++++++++++++++- .../layouts/industryInfo/IndustryInfoView.ts | 17 ++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index 18a4297..399e522 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -25,7 +25,6 @@ const Alert = React.forwardRef(function Alert( const formData = new FormData() - export default function industryInfo({userName}: any) { const [url, setUrl] = React.useState(''); @@ -105,8 +104,29 @@ export default function industryInfo({userName}: any) {
    +
    +
    +
    +
    +
    + + + + +
    +
    + + +
    +
    + + + + + + diff --git a/src/styles/layouts/industryInfo/IndustryInfoView.ts b/src/styles/layouts/industryInfo/IndustryInfoView.ts index 805dd85..6244637 100644 --- a/src/styles/layouts/industryInfo/IndustryInfoView.ts +++ b/src/styles/layouts/industryInfo/IndustryInfoView.ts @@ -39,4 +39,21 @@ export const IndustryInfoView = styled.main` } + input[type="file"] { + display: none; +} +label { + padding: 20px 10px; + width: 200px; + background-color: #333; + color: #FFF; + text-transform: uppercase; + text-align: center; + display: block; + margin-top: 10px; + cursor: pointer; +} + + + ` From d4e283cd159aa89e5974286fa7c574b2ebd7d081 Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Tue, 28 Jun 2022 09:08:37 -0300 Subject: [PATCH 14/17] update --- .../administrative/industryInfo/index.tsx | 80 +++++-------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index 5ea4b36..5cdf3bb 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -8,9 +8,9 @@ import PageTitle from '../../../components/pageTitle/PageTitle' import { IndustryInfoView } from '../../../styles/layouts/industryInfo/IndustryInfoView' import InputUploadPdf from '../../../components/inputUploadPdf/inputUpload'; import { api } from '../../../services/api' -// import { Viewer } from '@react-pdf-viewer/core'; -import '@react-pdf-viewer/core/lib/styles/index.css'; + import FormData from 'form-data'; + import Snackbar from '@mui/material/Snackbar'; import MuiAlert, { AlertProps } from '@mui/material/Alert'; import { InputUploadView } from '../../../components/inputUploadPdf/inputUploadView' @@ -22,16 +22,13 @@ const Alert = React.forwardRef(function Alert( return ; }); -const formData = new FormData() - - export default function industryInfo({userName}: any) { - const [url, setUrl] = React.useState(''); + const formData = new FormData(); - const onChange = (e: React.ChangeEvent) => { - const files = e.target.files; - files.length > 0 && setUrl(URL.createObjectURL(files[0])); - }; + const [pdf, setPdf] = useState(); + function onChange(e) { + setPdf(e.target.files[0]) + } const [openSnackSuccess, setOpenSnackSuccess] = useState(false); const [openSnackError, setOpenSnackError] = useState(false); @@ -45,32 +42,16 @@ export default function industryInfo({userName}: any) { setOpenSnackSuccess(false); }; - function handleCreateClient({ - pdf, - }) { + function handleCreateClient() { formData.append('file', pdf) - api.post('/updateFile', formData) - .then((res) => { - setOpenSnackSuccess(true) - window.location.reload() - }) - .catch((res) => { - setOpenSnackError(true) - }) + + api.post('/updateFile', formData).then(res => { + setOpenSnackSuccess(true) + }).catch(res => { + setOpenSnackError(true) + }) } - - // function handleCreateClient() { - // pdf, - // FormData.append('file', pdf) - - // api.post('/updateFile', FormData).then(res => { - // setOpenSnackSuccess(true) - // }).catch(res => { - // setOpenSnackError(true) - // }) - // } - return ( @@ -89,46 +70,21 @@ export default function industryInfo({userName}: any) {
    - {/* +
    - - +
    -
    */} +
    {/* */}
    -
    -
    -
    - - -
    -
    -
    + handleCreateClient()} title='Atualizar'/> - - - -
    -
    - - -
    -
    - - - - - - - - {/* handleCreateClient()} title='Atualizar'/> */} ) } From ad9e15ea21a8e7ca1e9cc0f378cfa5622eba0f0c Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Tue, 28 Jun 2022 09:33:03 -0300 Subject: [PATCH 15/17] fixing errors --- package.json | 1 + .../administrative/industryInfo/index.tsx | 7 +++- src/pages/index.tsx | 2 +- src/pages/pld/index.tsx | 38 ++++++++++++++++++- .../layouts/industryInfo/IndustryInfoView.ts | 17 ++++----- yarn.lock | 25 ++++++++++++ 6 files changed, 77 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index bfc4d50..ee05b14 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "react-hook-form": "^7.32.2", "react-icons": "^4.3.1", "react-input-mask": "^2.0.4", + "react-pdf-thumbnail": "^0.1.0", "styled-components": "^5.3.5", "tinymce": "^6.0.3", "yup": "^0.32.11" diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index 5cdf3bb..c5d0f71 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -8,6 +8,7 @@ import PageTitle from '../../../components/pageTitle/PageTitle' import { IndustryInfoView } from '../../../styles/layouts/industryInfo/IndustryInfoView' import InputUploadPdf from '../../../components/inputUploadPdf/inputUpload'; import { api } from '../../../services/api' +import PdfThumbnail from 'react-pdf-thumbnail'; import FormData from 'form-data'; @@ -74,10 +75,12 @@ export default function industryInfo({userName}: any) {
    - - + + + {/* */}
    +

    {pdf}

    {/* */} diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 09dd6e2..aee288f 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -36,10 +36,10 @@ export default function Home() { const [state, setstate] = useState(false); const [values, setValues] = useState({ - password: null, showPassword: false, }); + const [email, setEmail] = useState("") const [password, setPassword] = useState() diff --git a/src/pages/pld/index.tsx b/src/pages/pld/index.tsx index 1fa7fc8..66219bb 100644 --- a/src/pages/pld/index.tsx +++ b/src/pages/pld/index.tsx @@ -130,6 +130,39 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN const dateFormated = new Date() + function downloadCSVFile(csv, filename) { + const csv_file = new Blob([csv], {type: "text/csv"}); + + const download_link = document.createElement("a"); + + download_link.download = filename; + + download_link.href = window.URL.createObjectURL(csv_file); + + download_link.style.display = "none"; + + document.body.appendChild(download_link); + + download_link.click(); + } + + function htmlToCSV(html, filename) { + const data = []; + const rows = document.querySelectorAll("table tr"); + + for (let i = 0; i < rows.length; i++) { + const row = [], cols: any = rows[i].querySelectorAll("td, th"); + + for (let j = 0; j < cols.length; j++) { + row.push(cols[j].innerText); + } + + data.push(row.join(",")); + } + + downloadCSVFile(data.join("\n"), filename); + } + useEffect(() => { getDataByHour() getDataByDay() @@ -215,7 +248,10 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN
    - console.log()} title='Download'/> + { + const html = document.querySelector("table").outerHTML; + htmlToCSV(html, "tabela_PLD.csv"); + }} title='Download'/>
    diff --git a/src/styles/layouts/industryInfo/IndustryInfoView.ts b/src/styles/layouts/industryInfo/IndustryInfoView.ts index 6244637..89e98b7 100644 --- a/src/styles/layouts/industryInfo/IndustryInfoView.ts +++ b/src/styles/layouts/industryInfo/IndustryInfoView.ts @@ -29,21 +29,20 @@ export const IndustryInfoView = styled.main` .inputTeste{ display: flex; align-items: center; - margin-top:-10px; width: 50%; - margin-bottom: 50px; height: 50px; background: white; - border: 3px solid #254F7F; border-radius:10px; } - input[type="file"] { - display: none; -} -label { - padding: 20px 10px; + display: block; + } + + label { + display: flex; + justify-content: flex-start; + padding: 2px 10px; width: 200px; background-color: #333; color: #FFF; @@ -52,7 +51,7 @@ label { display: block; margin-top: 10px; cursor: pointer; -} + } diff --git a/yarn.lock b/yarn.lock index 664df8a..65ed182 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2245,6 +2245,11 @@ dom-helpers@^5.0.1: "@babel/runtime" "^7.8.7" csstype "^3.0.2" +dommatrix@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/dommatrix/-/dommatrix-1.0.3.tgz#e7c18e8d6f3abdd1fef3dd4aa74c4d2e620a0525" + integrity sha512-l32Xp/TLgWb8ReqbVJAFIvXmY7go4nTxxlWiAFyhoQw9RKEOHBZNnyGvJWqDVSPmq3Y9HlM4npqF/T6VMOXhww== + eastasianwidth@^0.2.0: version "0.2.0" resolved "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz" @@ -4006,6 +4011,14 @@ patternomaly@^1.3.2: version "1.3.2" resolved "https://registry.yarnpkg.com/patternomaly/-/patternomaly-1.3.2.tgz#70b8db17d7318ab1471cc43f94011bb866c54d09" +pdfjs-dist@^2.7.570: + version "2.14.305" + resolved "https://registry.yarnpkg.com/pdfjs-dist/-/pdfjs-dist-2.14.305.tgz#ed2ecb439ff8af5446c90a310ebd30bc1a91df62" + integrity sha512-5f7i25J1dKIBczhgfxEgNxfYNIxXEdxqo6Qb4ehY7Ja+p6AI4uUmk/OcVGXfRGm2ys5iaJJhJUwBFwv6Jl/Qww== + dependencies: + dommatrix "^1.0.1" + web-streams-polyfill "^3.2.1" + picocolors@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz" @@ -4145,6 +4158,13 @@ react-is@^16.13.1, react-is@^16.7.0: version "17.0.2" resolved "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz" +react-pdf-thumbnail@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/react-pdf-thumbnail/-/react-pdf-thumbnail-0.1.0.tgz#6b8ddf861252acb2b137dfd42007f545fde52ef9" + integrity sha512-VzkGUmgAheqxQsMTcUjOFrATtEdG2C9YRkMb0GFkf9JyfTDdBjkyu1/gVLk9CYVKWkgyNID34/G0TTX60XJuyA== + dependencies: + pdfjs-dist "^2.7.570" + react-transition-group@^4.4.0, react-transition-group@^4.4.2: version "4.4.2" resolved "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.2.tgz" @@ -4769,6 +4789,11 @@ wcwidth@^1.0.0: dependencies: defaults "^1.0.3" +web-streams-polyfill@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" + integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== + which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz" From 9143dc8bb17de71748796d2ce41a11e5677c62dc Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Tue, 28 Jun 2022 09:46:25 -0300 Subject: [PATCH 16/17] fixing errors --- .../administrative/industryInfo/index.tsx | 18 +++-------- .../layouts/industryInfo/IndustryInfoView.ts | 31 +++++++++++++++++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index c5d0f71..432fe3d 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -29,6 +29,7 @@ export default function industryInfo({userName}: any) { const [pdf, setPdf] = useState(); function onChange(e) { setPdf(e.target.files[0]) + console.log(pdf) } const [openSnackSuccess, setOpenSnackSuccess] = useState(false); @@ -71,19 +72,10 @@ export default function industryInfo({userName}: any) {
    - -
    -
    -
    - - - {/* */} -
    -
    -

    {pdf}

    -
    -
    - {/* */} +
    + + +
    handleCreateClient()} title='Atualizar'/> diff --git a/src/styles/layouts/industryInfo/IndustryInfoView.ts b/src/styles/layouts/industryInfo/IndustryInfoView.ts index 89e98b7..624cc92 100644 --- a/src/styles/layouts/industryInfo/IndustryInfoView.ts +++ b/src/styles/layouts/industryInfo/IndustryInfoView.ts @@ -26,7 +26,34 @@ export const IndustryInfoView = styled.main` color: #FFFFFF; } - .inputTeste{ + + form { + label { + display: flex; + align-items: center; + justify-content: center; + position: absolute; + width: 150px; + margin-left: 10px; + transform: translateY(20px); + background-color: #254F7F; + color: white; + border-radius: 8px; + } + } + + input[type="file"] { + padding-top: 20px; + padding-left: 41px; + width: 350px; + height: 60px; + border: 1px solid black; + border-radius: 6px; + } + label { + } + + /* .inputTeste{ display: flex; align-items: center; width: 50%; @@ -51,7 +78,7 @@ export const IndustryInfoView = styled.main` display: block; margin-top: 10px; cursor: pointer; - } + } */ From 0ba6332e416e51e2875e35bbcdee47312d47dd69 Mon Sep 17 00:00:00 2001 From: joseCorte-exe Date: Tue, 28 Jun 2022 09:48:13 -0300 Subject: [PATCH 17/17] fixing errors --- src/pages/dashboard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 7b2052e..c3bdc50 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -52,7 +52,7 @@ export default function Dashboard({grossAnualGraph, grossAnualYears, grossMensal -