From 020fe303144beba70d0efb8e5c270657bda8605a Mon Sep 17 00:00:00 2001 From: Alex Santos Date: Fri, 24 Jun 2022 19:54:46 -0300 Subject: [PATCH] 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"