fixing bugs
This commit is contained in:
parent
9a7398ff15
commit
09ec73d1b4
@ -9,6 +9,7 @@ import { useRouter } from 'next/router'
|
|||||||
import { parseCookies } from 'nookies';
|
import { parseCookies } from 'nookies';
|
||||||
import React, { useContext, useEffect, useState } from 'react'
|
import React, { useContext, useEffect, useState } from 'react'
|
||||||
import { AuthContext } from '../../contexts/AuthContext';
|
import { AuthContext } from '../../contexts/AuthContext';
|
||||||
|
import { api } from '../../services/api';
|
||||||
|
|
||||||
import RenderIf from '../../utils/renderIf';
|
import RenderIf from '../../utils/renderIf';
|
||||||
import { SidebarView } from './SidebarView'
|
import { SidebarView } from './SidebarView'
|
||||||
@ -33,6 +34,7 @@ export default function Sidebar() {
|
|||||||
const { signOut } = useContext(AuthContext)
|
const { signOut } = useContext(AuthContext)
|
||||||
|
|
||||||
const [ economiaDrawer, setEconomiaDrawer ] = useState(false)
|
const [ economiaDrawer, setEconomiaDrawer ] = useState(false)
|
||||||
|
const [ notificationsCount, setNotificationsCount ] = useState()
|
||||||
|
|
||||||
const [ viewModal, setViewModal ] = useState(false)
|
const [ viewModal, setViewModal ] = useState(false)
|
||||||
|
|
||||||
@ -44,6 +46,12 @@ export default function Sidebar() {
|
|||||||
setViewModal(false)
|
setViewModal(false)
|
||||||
}, [router.pathname])
|
}, [router.pathname])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api.post('/notify').then(res => {
|
||||||
|
setNotificationsCount(res.data)
|
||||||
|
}).catch(res => console.log(res))
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<RenderIf isTrue={role === '1'}>
|
<RenderIf isTrue={role === '1'}>
|
||||||
@ -105,7 +113,7 @@ export default function Sidebar() {
|
|||||||
<Link href='/pld'><li className={router.pathname=='/pld'? 'actualPath' : null}><Image src='/assets/sidebar/newsIcon.svg' width={25} height={25} />{'PLD >'}</li></Link>
|
<Link href='/pld'><li className={router.pathname=='/pld'? 'actualPath' : null}><Image src='/assets/sidebar/newsIcon.svg' width={25} height={25} />{'PLD >'}</li></Link>
|
||||||
<Link href='/industryInfo'><li className={router.pathname=='/industryInfo'? 'actualPath' : null}><Image src='/assets/sidebar/sectorialInfoIcon.svg' width={25} height={25} />{'Info Setorial >'}</li></Link>
|
<Link href='/industryInfo'><li className={router.pathname=='/industryInfo'? 'actualPath' : null}><Image src='/assets/sidebar/sectorialInfoIcon.svg' width={25} height={25} />{'Info Setorial >'}</li></Link>
|
||||||
{/* <Link href='/consumption'><li className={router.pathname=='/consumption'? 'actualPath' : null} ><Image src='/assets/sidebar/consumptionIcon.svg' width={25} height={25} />{'Consumo'}</li></Link> */}
|
{/* <Link href='/consumption'><li className={router.pathname=='/consumption'? 'actualPath' : null} ><Image src='/assets/sidebar/consumptionIcon.svg' width={25} height={25} />{'Consumo'}</li></Link> */}
|
||||||
<Link href='/notifications'><li className={router.pathname=='/notifications'? 'actualPath' : null}><Image src='/assets/sidebar/notificationsIcon.svg' width={25} height={25} />{'Notificações >'}<div className='notification'><p>25</p></div></li></Link>
|
<Link href='/notifications'><li className={router.pathname=='/notifications'? 'actualPath' : null}><Image src='/assets/sidebar/notificationsIcon.svg' width={25} height={25} />{'Notificações >'}<div className='notification'><p>{notificationsCount}</p></div></li></Link>
|
||||||
<Link href='/aboutUs'><li className={router.pathname=='/aboutUs'? 'actualPath' : null}><Image src='/assets/sidebar/aboutUs.svg' width={25} height={25} />{'Sobre Nós >'}</li></Link>
|
<Link href='/aboutUs'><li className={router.pathname=='/aboutUs'? 'actualPath' : null}><Image src='/assets/sidebar/aboutUs.svg' width={25} height={25} />{'Sobre Nós >'}</li></Link>
|
||||||
<Link href='/faq'><li className={router.pathname=='/faq'? 'actualPath' : null}><Image src='/assets/sidebar/saqIcon.svg' width={25} height={25} />{'FAQ >'}</li></Link>
|
<Link href='/faq'><li className={router.pathname=='/faq'? 'actualPath' : null}><Image src='/assets/sidebar/saqIcon.svg' width={25} height={25} />{'FAQ >'}</li></Link>
|
||||||
<button onClick={handleOpen}><Image src='/assets/logout.svg' width={25} height={25} />{'Sair'}</button>
|
<button onClick={handleOpen}><Image src='/assets/logout.svg' width={25} height={25} />{'Sair'}</button>
|
||||||
|
|||||||
@ -19,10 +19,12 @@ import { GetServerSideProps } from 'next'
|
|||||||
import { parseCookies } from 'nookies'
|
import { parseCookies } from 'nookies'
|
||||||
import getAPIClient from '../services/ssrApi'
|
import getAPIClient from '../services/ssrApi'
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }: AppProps) {
|
export function MyApp({ Component, pageProps, notificationsCount }: AppProps | any) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const rota = router.pathname
|
const rota = router.pathname
|
||||||
|
|
||||||
|
console.log('notifications: ', notificationsCount)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleStart = (url) => {
|
const handleStart = (url) => {
|
||||||
console.log(`Loading: ${url}`)
|
console.log(`Loading: ${url}`)
|
||||||
@ -69,3 +71,29 @@ function MyApp({ Component, pageProps }: AppProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default MyApp;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,26 +1,79 @@
|
|||||||
import { GetServerSideProps } from 'next'
|
import { GetServerSideProps } from 'next'
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import { parseCookies } from 'nookies'
|
import { parseCookies } from 'nookies'
|
||||||
import React from 'react'
|
import React, { useState } from 'react'
|
||||||
import BasicButton from '../../../components/buttons/basicButton/BasicButton'
|
import BasicButton from '../../../components/buttons/basicButton/BasicButton'
|
||||||
import Header from '../../../components/header/Header'
|
import Header from '../../../components/header/Header'
|
||||||
import PageTitle from '../../../components/pageTitle/PageTitle'
|
import PageTitle from '../../../components/pageTitle/PageTitle'
|
||||||
import { IndustryInfoView } from '../../../styles/layouts/industryInfo/IndustryInfoView'
|
import { IndustryInfoView } from '../../../styles/layouts/industryInfo/IndustryInfoView'
|
||||||
import InputUploadPdf from '../../../components/inputUploadPdf/inputUpload';
|
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<HTMLDivElement, AlertProps>(function Alert(
|
||||||
|
props,
|
||||||
|
ref,
|
||||||
|
) {
|
||||||
|
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
export default function industryInfo({userName}: any) {
|
export default function industryInfo({userName}: any) {
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
const [pdf, setPdf] = useState<any>();
|
||||||
|
function onChange(e) {
|
||||||
|
setPdf(e.target.files[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
|
||||||
|
const [openSnackError, setOpenSnackError] = useState<boolean>(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 (
|
return (
|
||||||
<IndustryInfoView>
|
<IndustryInfoView>
|
||||||
|
<Snackbar open={openSnackSuccess} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="success" sx={{ width: '100%' }}>
|
||||||
|
PDF Baixado com Sucesso!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
<Snackbar open={openSnackError} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="error" sx={{ width: '100%' }}>
|
||||||
|
PDF não baixado!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Smart Energia - Info de Setor</title>
|
<title>Smart Energia - Info de Setor</title>
|
||||||
</Head>
|
</Head>
|
||||||
<Header name={userName} />
|
<Header name={userName} />
|
||||||
<div className='title'>
|
<div className='title'>
|
||||||
<PageTitle title='Info Setorial' subtitle='Realize o upload da última versão de info setorial' />
|
<PageTitle title='Info Setorial' subtitle='Realize o upload da última versão de info setorial' />
|
||||||
|
<input type="file" onChange={onChange}/>
|
||||||
<InputUploadPdf/>
|
<InputUploadPdf/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<BasicButton onClick={() => console.log()} title='Atualizar'/>
|
<BasicButton onClick={() => handleCreateClient()} title='Atualizar'/>
|
||||||
|
|
||||||
</IndustryInfoView>
|
</IndustryInfoView>
|
||||||
)
|
)
|
||||||
@ -45,4 +98,3 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export default function Dashboard({grossAnualGraph, grossAnualYears, grossMensal
|
|||||||
<PageTitle title='Visão Geral' subtitle='Bem Vindo a Smart Energia' />
|
<PageTitle title='Visão Geral' subtitle='Bem Vindo a Smart Energia' />
|
||||||
<Link href='pld'>
|
<Link href='pld'>
|
||||||
<section className="cardsSection" >
|
<section className="cardsSection" >
|
||||||
<MapCard title='R$/MWh' subtitle='abril / 22' date='até 10/10' statistic='' imgSource='/moneyIcon.svg' />
|
<MapCard title='R$/MWh' subtitle='' date='periodo' statistic='' imgSource='/moneyIcon.svg' />
|
||||||
{
|
{
|
||||||
mapsInfo.map(value => {
|
mapsInfo.map(value => {
|
||||||
return <MapCard key={value.submarket} title='S' subtitle={value.submarket} statistic={parseFloat(value.value).toFixed(2)} imgSource='/SUL.svg' />
|
return <MapCard key={value.submarket} title='S' subtitle={value.submarket} statistic={parseFloat(value.value).toFixed(2)} imgSource='/SUL.svg' />
|
||||||
|
|||||||
@ -12,17 +12,6 @@ import getAPIClient from '../services/ssrApi'
|
|||||||
|
|
||||||
import { GrossSavingsView } from '../styles/layouts/economy/grossSavings/GrossSavings'
|
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) {
|
export default function GrossSavings({graphData, years, userName}: any) {
|
||||||
return (
|
return (
|
||||||
<GrossSavingsView>
|
<GrossSavingsView>
|
||||||
|
|||||||
@ -1,15 +1,56 @@
|
|||||||
import { GetServerSideProps } from 'next'
|
import { GetServerSideProps } from 'next'
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import { parseCookies } from 'nookies'
|
import { parseCookies } from 'nookies'
|
||||||
import React from 'react'
|
import React, { useState } from 'react'
|
||||||
import BasicButton from '../components/buttons/basicButton/BasicButton'
|
import BasicButton from '../components/buttons/basicButton/BasicButton'
|
||||||
import Header from '../components/header/Header'
|
import Header from '../components/header/Header'
|
||||||
import PageTitle from '../components/pageTitle/PageTitle'
|
import PageTitle from '../components/pageTitle/PageTitle'
|
||||||
|
import { api } from '../services/api'
|
||||||
import { IndustryInfoView } from '../styles/layouts/industryInfo/IndustryInfoView'
|
import { IndustryInfoView } from '../styles/layouts/industryInfo/IndustryInfoView'
|
||||||
|
|
||||||
|
import Snackbar from '@mui/material/Snackbar';
|
||||||
|
import MuiAlert, { AlertProps } from '@mui/material/Alert';
|
||||||
|
|
||||||
|
const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
||||||
|
props,
|
||||||
|
ref,
|
||||||
|
) {
|
||||||
|
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
|
||||||
|
});
|
||||||
|
|
||||||
export default function industryInfo({userName}: any) {
|
export default function industryInfo({userName}: any) {
|
||||||
|
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
|
||||||
|
const [openSnackError, setOpenSnackError] = useState<boolean>(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 (
|
return (
|
||||||
<IndustryInfoView>
|
<IndustryInfoView>
|
||||||
|
<Snackbar open={openSnackSuccess} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="success" sx={{ width: '100%' }}>
|
||||||
|
Cliente cadastrada com Sucesso!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
<Snackbar open={openSnackError} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||||
|
<Alert onClose={handleCloseSnack} severity="error" sx={{ width: '100%' }}>
|
||||||
|
Cliente não cadastrado!
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Smart Energia - Info de Setor</title>
|
<title>Smart Energia - Info de Setor</title>
|
||||||
</Head>
|
</Head>
|
||||||
@ -17,7 +58,7 @@ export default function industryInfo({userName}: any) {
|
|||||||
<div className='title'>
|
<div className='title'>
|
||||||
<PageTitle title='Info Setorial' subtitle='Clique em "Baixar PDF", para fazer download do PDF' />
|
<PageTitle title='Info Setorial' subtitle='Clique em "Baixar PDF", para fazer download do PDF' />
|
||||||
</div>
|
</div>
|
||||||
<button>Baixar PDF</button>
|
<button onClick={() => handleDownloadPdf()}>Baixar PDF</button>
|
||||||
</IndustryInfoView>
|
</IndustryInfoView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user