diff --git a/src/components/sidebar/Sidebar.tsx b/src/components/sidebar/Sidebar.tsx index 3e777ff..d8aaa02 100644 --- a/src/components/sidebar/Sidebar.tsx +++ b/src/components/sidebar/Sidebar.tsx @@ -9,6 +9,7 @@ import { useRouter } from 'next/router' import { parseCookies } from 'nookies'; import React, { useContext, useEffect, useState } from 'react' import { AuthContext } from '../../contexts/AuthContext'; +import { api } from '../../services/api'; import RenderIf from '../../utils/renderIf'; import { SidebarView } from './SidebarView' @@ -33,6 +34,7 @@ export default function Sidebar() { const { signOut } = useContext(AuthContext) const [ economiaDrawer, setEconomiaDrawer ] = useState(false) + const [ notificationsCount, setNotificationsCount ] = useState() const [ viewModal, setViewModal ] = useState(false) @@ -44,6 +46,12 @@ export default function Sidebar() { setViewModal(false) }, [router.pathname]) + useEffect(() => { + api.post('/notify').then(res => { + setNotificationsCount(res.data) + }).catch(res => console.log(res)) + }, []) + return ( <> @@ -105,7 +113,7 @@ export default function Sidebar() {
  • {'PLD >'}
  • {'Info Setorial >'}
  • {/*
  • {'Consumo'}
  • */} -
  • {'Notificações >'}

    25

  • +
  • {'Notificações >'}

    {notificationsCount}

  • {'Sobre Nós >'}
  • {'FAQ >'}
  • diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 9a5ef4a..3636835 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -19,10 +19,12 @@ import { GetServerSideProps } from 'next' import { parseCookies } from 'nookies' import getAPIClient from '../services/ssrApi' -function MyApp({ Component, pageProps }: AppProps) { +export function MyApp({ Component, pageProps, notificationsCount }: AppProps | any) { const router = useRouter() const rota = router.pathname + console.log('notifications: ', notificationsCount) + useEffect(() => { const handleStart = (url) => { console.log(`Loading: ${url}`) @@ -69,3 +71,29 @@ function MyApp({ Component, pageProps }: AppProps) { } export default MyApp; + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const apiClient = getAPIClient(ctx) + const { ['@smartAuth-token']: token } = parseCookies(ctx) + + let notificationsCount + + await apiClient.post('/download').then(res => { + console.log(res) + }).catch(res => console.log(res)) + + if (!token) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + return { + props: { + notificationsCount + } + } +} diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index d1a0fc2..a9ebdf0 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -132,12 +132,12 @@ export default function clients({clients, userName}) { - Cliente excluido com sucesso! + Cliente excluido com sucesso! - Cliente não excluido! + Cliente não excluido! diff --git a/src/pages/administrative/industryInfo/index.tsx b/src/pages/administrative/industryInfo/index.tsx index 82b55c6..b095c98 100644 --- a/src/pages/administrative/industryInfo/index.tsx +++ b/src/pages/administrative/industryInfo/index.tsx @@ -1,26 +1,79 @@ import { GetServerSideProps } from 'next' import Head from 'next/head' import { parseCookies } from 'nookies' -import React from 'react' +import React, { useState } from 'react' import BasicButton from '../../../components/buttons/basicButton/BasicButton' import Header from '../../../components/header/Header' 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 FormData from 'form-data'; + +import Snackbar from '@mui/material/Snackbar'; +import MuiAlert, { AlertProps } from '@mui/material/Alert'; + +const Alert = React.forwardRef(function Alert( + props, + ref, +) { + return ; +}); export default function industryInfo({userName}: any) { + const formData = new FormData(); + + const [pdf, setPdf] = useState(); + function onChange(e) { + setPdf(e.target.files[0]) + } + + const [openSnackSuccess, setOpenSnackSuccess] = useState(false); + const [openSnackError, setOpenSnackError] = useState(false); + + const handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => { + if (reason === 'clickaway') { + return; + } + + setOpenSnackError(false); + setOpenSnackSuccess(false); + }; + + function handleCreateClient() { + formData.append('file', pdf) + + api.post('/updateFile', formData).then(res => { + setOpenSnackSuccess(true) + }).catch(res => { + setOpenSnackError(true) + }) + } + return ( + + + PDF Baixado com Sucesso! + + + + + PDF não baixado! + + Smart Energia - Info de Setor
    +
    - console.log()} title='Atualizar'/> + handleCreateClient()} title='Atualizar'/> ) @@ -45,4 +98,3 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { } } } - diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index e5dedef..1bdfc69 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -34,7 +34,7 @@ export default function Dashboard({grossAnualGraph, grossAnualYears, grossMensal
    - + { mapsInfo.map(value => { return diff --git a/src/pages/grossSavings.tsx b/src/pages/grossSavings.tsx index 26fe5dd..5a18bf0 100644 --- a/src/pages/grossSavings.tsx +++ b/src/pages/grossSavings.tsx @@ -12,17 +12,6 @@ import getAPIClient from '../services/ssrApi' import { GrossSavingsView } from '../styles/layouts/economy/grossSavings/GrossSavings' -function addMissingMonths(data) { - // console.log(data[0].mes.slice(1, 1)) -} - -function verifyDataByYear(data) { - if (data.length === 12) - return true - else - return false -} - export default function GrossSavings({graphData, years, userName}: any) { return ( diff --git a/src/pages/industryInfo.tsx b/src/pages/industryInfo.tsx index ae55ada..48960d9 100644 --- a/src/pages/industryInfo.tsx +++ b/src/pages/industryInfo.tsx @@ -1,15 +1,56 @@ import { GetServerSideProps } from 'next' import Head from 'next/head' import { parseCookies } from 'nookies' -import React from 'react' +import React, { 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 { IndustryInfoView } from '../styles/layouts/industryInfo/IndustryInfoView' +import Snackbar from '@mui/material/Snackbar'; +import MuiAlert, { AlertProps } from '@mui/material/Alert'; + +const Alert = React.forwardRef(function Alert( + props, + ref, +) { + return ; +}); + export default function industryInfo({userName}: any) { + const [openSnackSuccess, setOpenSnackSuccess] = useState(false); + const [openSnackError, setOpenSnackError] = useState(false); + + const handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => { + if (reason === 'clickaway') { + return; + } + + setOpenSnackError(false); + setOpenSnackSuccess(false); + }; + + function handleDownloadPdf() { + api.get('/download').then(res => { + setOpenSnackSuccess(true) + }).catch(res => { + setOpenSnackError(true) + }) + } + return ( + + + Cliente cadastrada com Sucesso! + + + + + Cliente não cadastrado! + + Smart Energia - Info de Setor @@ -17,7 +58,7 @@ export default function industryInfo({userName}: any) {
    - +
    ) }