Correções em algumas páginas de acordo o retorno da api
This commit is contained in:
parent
5c984bb60e
commit
c19f3651c5
@ -58,9 +58,7 @@ export default function Sidebar() {
|
||||
}, [router.pathname])
|
||||
|
||||
useEffect(() => {
|
||||
api.post('/notify').then(res => {
|
||||
setNotificationsCount(res.data)
|
||||
})
|
||||
api.post('/notify').then(({ data: { data: notifyCount } }) => setNotificationsCount(notifyCount))
|
||||
}, [])
|
||||
|
||||
return (
|
||||
|
||||
@ -42,9 +42,7 @@ export function AuthProvider({children}: {children: React.ReactNode}) {
|
||||
logout()
|
||||
}
|
||||
|
||||
async function signIn({email, password}: SignInData) {
|
||||
signOut()
|
||||
|
||||
async function signIn({ email, password }: SignInData) {
|
||||
const { token, user, exception }: any = await signInRequest({
|
||||
email,
|
||||
password
|
||||
|
||||
@ -237,8 +237,6 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
await apiClient.post('/economy/grossAnnual').then(res => {
|
||||
grossAnualGraph = res.data.data
|
||||
})
|
||||
.then(console.log)
|
||||
.catch(console.log)
|
||||
|
||||
await apiClient.post('/economy/grossMonthly').then(res => {
|
||||
grossMensalGraph = res.data.data
|
||||
|
||||
@ -1,103 +1,108 @@
|
||||
import FormControl from '@mui/material/FormControl';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import InputAdornment from '@mui/material/InputAdornment';
|
||||
import InputLabel from '@mui/material/InputLabel';
|
||||
import OutlinedInput from '@mui/material/OutlinedInput';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import Head from 'next/head';
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
import FormControl from '@mui/material/FormControl'
|
||||
import IconButton from '@mui/material/IconButton'
|
||||
import InputAdornment from '@mui/material/InputAdornment'
|
||||
import InputLabel from '@mui/material/InputLabel'
|
||||
import OutlinedInput from '@mui/material/OutlinedInput'
|
||||
import TextField from '@mui/material/TextField'
|
||||
import Head from 'next/head'
|
||||
import Image from 'next/image'
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useContext, useState, useEffect, useCallback, useRef, forwardRef } from 'react'
|
||||
import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai';
|
||||
import RenderIf from '../utils/renderIf';
|
||||
import Snackbar from '@mui/material/Snackbar';
|
||||
import {
|
||||
useContext,
|
||||
useState,
|
||||
useEffect,
|
||||
useCallback,
|
||||
useRef,
|
||||
forwardRef
|
||||
} from 'react'
|
||||
import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai'
|
||||
import RenderIf from '../utils/renderIf'
|
||||
import Snackbar from '@mui/material/Snackbar'
|
||||
|
||||
import LoginButton from '../components/buttons/loginButton/LoginButton';
|
||||
import { AuthContext } from '../contexts/AuthContext';
|
||||
import { api } from '../services/api';
|
||||
import { LoginContainer, LoginView } from '../styles/layouts/login/LoginView';
|
||||
import Dashboard from './dashboard';
|
||||
import MuiAlert, { AlertProps } from '@mui/material/Alert';
|
||||
import { GetServerSideProps } from 'next';
|
||||
import { parseCookies } from 'nookies';
|
||||
import LoginButton from '../components/buttons/loginButton/LoginButton'
|
||||
import { AuthContext } from '../contexts/AuthContext'
|
||||
import { api } from '../services/api'
|
||||
import { LoginContainer, LoginView } from '../styles/layouts/login/LoginView'
|
||||
import Dashboard from './dashboard'
|
||||
import MuiAlert, { AlertProps } from '@mui/material/Alert'
|
||||
import { GetServerSideProps } from 'next'
|
||||
import { parseCookies } from 'nookies'
|
||||
import { AxiosError } from 'axios'
|
||||
|
||||
const Alert = forwardRef<HTMLDivElement, AlertProps>(function Alert(
|
||||
props,
|
||||
ref,
|
||||
ref
|
||||
) {
|
||||
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
|
||||
});
|
||||
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />
|
||||
})
|
||||
|
||||
export default function Home() {
|
||||
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false);
|
||||
const [openSnackError, setOpenSnackError] = useState<boolean>(false);
|
||||
const [openSnackSuccess, setOpenSnackSuccess] = useState<boolean>(false)
|
||||
const [openSnackError, setOpenSnackError] = useState<boolean>(false)
|
||||
|
||||
const field = useRef(null)
|
||||
|
||||
const [state, setstate] = useState(false);
|
||||
const [focus, setFocus] = useState('email');
|
||||
const [state, setstate] = useState(false)
|
||||
const [focus, setFocus] = useState('email')
|
||||
|
||||
const [values, setValues] = useState({
|
||||
password: null,
|
||||
showPassword: false,
|
||||
});
|
||||
showPassword: false
|
||||
})
|
||||
|
||||
const [email, setEmail] = useState<string>("")
|
||||
const [email, setEmail] = useState<string>('')
|
||||
const [password, setPassword] = useState<string>()
|
||||
|
||||
const router = useRouter()
|
||||
const rota = router.pathname
|
||||
|
||||
const handleChange = (prop) => (event) => {
|
||||
setValues({ ...values, [prop]: event.target.value });
|
||||
setPassword(event.target.value);
|
||||
};
|
||||
setValues({ ...values, [prop]: event.target.value })
|
||||
setPassword(event.target.value)
|
||||
}
|
||||
|
||||
const handleClickShowPassword = () => {
|
||||
setValues({
|
||||
...values,
|
||||
showPassword: !values.showPassword,
|
||||
});
|
||||
};
|
||||
showPassword: !values.showPassword
|
||||
})
|
||||
}
|
||||
|
||||
const handleMouseDownPassword = (event) => {
|
||||
event.preventDefault();
|
||||
};
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
const { signIn } = useContext(AuthContext)
|
||||
|
||||
async function handleSignIn() {
|
||||
if (email === "" || password === ""){
|
||||
setOpenSnackError(true)
|
||||
}else{
|
||||
try {
|
||||
await signIn({email, password}).then((res: any) => {
|
||||
if (res.response.status === 422 || res.response.status === 401 || res.response.status === 500 ) {
|
||||
if ([email, password].some(v => !v.trim())) return setOpenSnackError(true);
|
||||
|
||||
await signIn({ email, password })
|
||||
} catch (ex) {
|
||||
setOpenSnackError(true)
|
||||
}
|
||||
})
|
||||
} catch (exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setValues({
|
||||
password: (''),
|
||||
showPassword: null,
|
||||
});
|
||||
setEmail("")
|
||||
password: '',
|
||||
showPassword: null
|
||||
})
|
||||
setEmail('')
|
||||
}, [rota])
|
||||
|
||||
return (
|
||||
@ -105,40 +110,62 @@ export default function Home() {
|
||||
<Head>
|
||||
<title>Smart Energia</title>
|
||||
</Head>
|
||||
<Snackbar open={openSnackSuccess} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||
<Alert onClose={handleCloseSnack} severity="success" sx={{ width: '100%' }}>
|
||||
<Snackbar
|
||||
open={openSnackSuccess}
|
||||
autoHideDuration={4000}
|
||||
onClose={handleCloseSnack}
|
||||
>
|
||||
<Alert
|
||||
onClose={handleCloseSnack}
|
||||
severity="success"
|
||||
sx={{ width: '100%' }}
|
||||
>
|
||||
notificação cadastrada com sucesso!
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
<Snackbar open={openSnackError} autoHideDuration={4000} onClose={handleCloseSnack}>
|
||||
<Alert onClose={handleCloseSnack} severity="error" sx={{ width: '100%' }}>
|
||||
Prencha os Campos corretamente!
|
||||
<Snackbar
|
||||
open={openSnackError}
|
||||
autoHideDuration={4000}
|
||||
onClose={handleCloseSnack}
|
||||
>
|
||||
<Alert
|
||||
onClose={handleCloseSnack}
|
||||
severity="error"
|
||||
sx={{ width: '100%' }}
|
||||
>
|
||||
Preencha os campos corretamente!
|
||||
</Alert>
|
||||
</Snackbar>
|
||||
|
||||
<div>
|
||||
<Image src='/assets/marca1.png' width={500} height={340} />
|
||||
<Image src="/assets/marca1.png" width={500} height={340} />
|
||||
</div>
|
||||
|
||||
<LoginContainer>
|
||||
<h1>Bem-Vindo</h1>
|
||||
<h2>Estratégias Inteligentes em<br /> Gestão de Energia</h2>
|
||||
<h2>
|
||||
Estratégias Inteligentes em
|
||||
<br /> Gestão de Energia
|
||||
</h2>
|
||||
|
||||
|
||||
<TextField id="outlined-basic"
|
||||
sx={{ m: 1, width: '90%' }} label="Login" value={email} variant="outlined" onKeyDown={(e) => e.key==='Enter'? field.current.children[0].focus() : null}
|
||||
onChange={value => {
|
||||
setEmail(value.target.value.toLowerCase())
|
||||
}}/>
|
||||
<TextField
|
||||
id="outlined-basic"
|
||||
sx={{ m: 1, width: '90%' }}
|
||||
label="Login"
|
||||
value={email}
|
||||
variant="outlined"
|
||||
onKeyDown={(e) => e.key === 'Enter' && field.current.children[0].focus()}
|
||||
onChange={(value) => setEmail(value.target.value.toLowerCase())}
|
||||
/>
|
||||
<FormControl sx={{ m: 1, width: '90%' }} variant="outlined">
|
||||
<InputLabel htmlFor="outlined-adornment-password" >Senha</InputLabel>
|
||||
<InputLabel htmlFor="outlined-adornment-password">Senha</InputLabel>
|
||||
<OutlinedInput
|
||||
id="outlined-adornment-password"
|
||||
type={values.showPassword ? 'text' : 'password'}
|
||||
value={values.password}
|
||||
onChange={handleChange('password')}
|
||||
ref={field}
|
||||
onKeyDown={(e) => e.key==='Enter'? handleSignIn() : null}
|
||||
onKeyDown={(e) => (e.key === 'Enter' ? handleSignIn() : null)}
|
||||
endAdornment={
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
@ -147,22 +174,36 @@ export default function Home() {
|
||||
onMouseDown={handleMouseDownPassword}
|
||||
edge="end"
|
||||
>
|
||||
{values.showPassword ? <AiOutlineEye /> : <AiOutlineEyeInvisible />}
|
||||
{values.showPassword ? (
|
||||
<AiOutlineEye />
|
||||
) : (
|
||||
<AiOutlineEyeInvisible />
|
||||
)}
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
}
|
||||
label="Senha"
|
||||
/>
|
||||
</FormControl>
|
||||
<Link href='verifyEmail'>Esqueceu a senha ?</Link>
|
||||
<Link href="verifyEmail">Esqueceu a senha ?</Link>
|
||||
|
||||
<LoginButton title='ENTRAR' onClick={() => handleSignIn()}/>
|
||||
<LoginButton title="ENTRAR" onClick={() => handleSignIn()} />
|
||||
|
||||
<fieldset className="line">
|
||||
<legend className="text">Ou</legend>
|
||||
</fieldset>
|
||||
|
||||
<p><a href='tel:+55(41) 3012-5900' >+55(41) 3012-5900</a><br/><a href='https://www.energiasmart.com.br' target="_blank" rel="noreferrer" >www.energiasmart.com.br</a></p>
|
||||
<p>
|
||||
<a href="tel:+55(41) 3012-5900">+55(41) 3012-5900</a>
|
||||
<br />
|
||||
<a
|
||||
href="https://www.energiasmart.com.br"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
www.energiasmart.com.br
|
||||
</a>
|
||||
</p>
|
||||
</LoginContainer>
|
||||
</LoginView>
|
||||
)
|
||||
|
||||
@ -37,12 +37,12 @@ interface pldInterface {
|
||||
clientMonth: any
|
||||
}
|
||||
|
||||
export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
export default function pld({ tableData, userName, clientMonth }: pldInterface) {
|
||||
const { pldMenu, setPldMenu } = useContext(MenuContext)
|
||||
|
||||
const dateFormated = new Date()
|
||||
|
||||
const year_Month = `0${dateFormated.getMonth()+1}/${dateFormated.getFullYear()}`
|
||||
const year_Month = `0${dateFormated.getMonth() + 1}/${dateFormated.getFullYear()}`
|
||||
|
||||
const [date, setDate] = useState<any>(new Date());
|
||||
const [select, setSelect] = useState('SUDESTE');
|
||||
@ -56,9 +56,11 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
const [norte, setNorte] = useState([])
|
||||
const [sudeste, setSudeste] = useState([])
|
||||
const [nordeste, setNordeste] = useState([])
|
||||
const [ pageYPosition, setPageYPosition ] = useState(0);
|
||||
const [pageYPosition, setPageYPosition] = useState(0);
|
||||
|
||||
function getPageYAfterScroll(){
|
||||
console.log(tableData?.data)
|
||||
|
||||
function getPageYAfterScroll() {
|
||||
setPageYPosition(window.scrollY);
|
||||
}
|
||||
|
||||
@ -76,8 +78,8 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
function getDataByDay() {
|
||||
api.post('/pld/daily', {
|
||||
"filters": [
|
||||
{"type" : "=", "field" : "year_month_formatted", "value": month, "row": true},
|
||||
{"type" : "=", "field" : "submarket", "value": select}
|
||||
{ "type": "=", "field": "year_month_formatted", "value": month, "row": true },
|
||||
{ "type": "=", "field": "submarket", "value": select }
|
||||
],
|
||||
"order": [{ "field": "day_calc", "direction": "asc" }]
|
||||
}).then(res => {
|
||||
@ -92,8 +94,8 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"filters": [
|
||||
{"type" : "=", "field" : "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true},
|
||||
{"type" : "=", "field" : "submercado", "value": "SUL"}
|
||||
{ "type": "=", "field": "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true },
|
||||
{ "type": "=", "field": "submercado", "value": "SUL" }
|
||||
],
|
||||
"order": [{ "field": "hour", "direction": "asc" }]
|
||||
}).then(res => {
|
||||
@ -106,8 +108,8 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"filters": [
|
||||
{"type" : "=", "field" : "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true},
|
||||
{"type" : "=", "field" : "submercado", "value": "SUDESTE"}
|
||||
{ "type": "=", "field": "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true },
|
||||
{ "type": "=", "field": "submercado", "value": "SUDESTE" }
|
||||
],
|
||||
"order": [{ "field": "hour", "direction": "asc" }]
|
||||
}).then(res => {
|
||||
@ -120,8 +122,8 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"filters": [
|
||||
{"type" : "=", "field" : "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true},
|
||||
{"type" : "=", "field" : "submercado", "value": "NORTE"}
|
||||
{ "type": "=", "field": "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true },
|
||||
{ "type": "=", "field": "submercado", "value": "NORTE" }
|
||||
],
|
||||
"order": [{ "field": "hour", "direction": "asc" }]
|
||||
}).then(res => {
|
||||
@ -134,8 +136,8 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"filters": [
|
||||
{"type" : "=", "field" : "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true},
|
||||
{"type" : "=", "field" : "submercado", "value": "NORDESTE"}
|
||||
{ "type": "=", "field": "dia_num", "value": date.toLocaleDateString().split('/').reverse().join('-'), "row": true },
|
||||
{ "type": "=", "field": "submercado", "value": "NORDESTE" }
|
||||
],
|
||||
"order": [{ "field": "hour", "direction": "asc" }]
|
||||
}).then(res => {
|
||||
@ -150,14 +152,14 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
return ''
|
||||
else if (value >= tableData.result[0][`${region}_max`])
|
||||
return ''
|
||||
else if (tableData.result[0][`${region}_max`] - value > tableData.result[0][`${region}_max`]/2)
|
||||
else if (tableData.result[0][`${region}_max`] - value > tableData.result[0][`${region}_max`] / 2)
|
||||
return ''
|
||||
else if (tableData.result[1][`${region}_min`] - value <= tableData.result[1][`${region}_min`])
|
||||
return ''
|
||||
}
|
||||
|
||||
function downloadCSVFile(csv, filename) {
|
||||
const csv_file = new Blob(["\ufeff",csv], {type: "text/csv"});
|
||||
const csv_file = new Blob(["\ufeff", csv], { type: "text/csv" });
|
||||
|
||||
const download_link = document.createElement("a");
|
||||
|
||||
@ -177,7 +179,7 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
const rows = document.querySelectorAll("table tr");
|
||||
// const rows = document.getElementsByClassName('tabela');
|
||||
|
||||
for (let i = rows.length/2; i < rows.length; i++) {
|
||||
for (let i = rows.length / 2; i < rows.length; i++) {
|
||||
const row = [], cols: any = rows[i].querySelectorAll("td, th");
|
||||
|
||||
for (let j = 0; j < cols.length; j++) {
|
||||
@ -200,31 +202,31 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<main style={{width: '100%'}}>
|
||||
<main style={{ width: '100%' }}>
|
||||
<Head>
|
||||
<title>Smart Energia - PLD</title>
|
||||
</Head>
|
||||
<div id='title'/>
|
||||
<div id='title' />
|
||||
<Header name={userName}>
|
||||
<PageTitle title='PLD' subtitle='Evolução PLD - Valores em R$/MWh'/>
|
||||
<PageTitle title='PLD' subtitle='Evolução PLD - Valores em R$/MWh' />
|
||||
</Header>
|
||||
<TableHeader>
|
||||
<Tabs value={pldMenu} onChange={(e, nv) => setPldMenu(nv)} aria-label="">
|
||||
<Tab label="Pld Histórico"/>
|
||||
<Tab label="Valores Diários"/>
|
||||
<Tab label="Valores Horários"/>
|
||||
<Tab label="Pld Histórico" />
|
||||
<Tab label="Valores Diários" />
|
||||
<Tab label="Valores Horários" />
|
||||
</Tabs>
|
||||
<div className='btnDownload'>
|
||||
<RenderIf isTrue={pldMenu === 0}>
|
||||
<BasicButton onClick={() => {
|
||||
const html = document.querySelector("table").outerHTML;
|
||||
htmlToCSV(html, "tabela_PLD.csv");
|
||||
}} title='Download'/>
|
||||
}} title='Download' />
|
||||
</RenderIf>
|
||||
</div>
|
||||
</TableHeader>
|
||||
|
||||
<RenderIf isTrue={pldMenu===0}>
|
||||
<RenderIf isTrue={pldMenu === 0}>
|
||||
<PldTableView>
|
||||
<table className='tg'>
|
||||
<thead>
|
||||
@ -238,17 +240,17 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
tableData.data.map(data => {
|
||||
return <>
|
||||
<tr className={data.year_month_formatted==year_Month? 'actual' : ''}>
|
||||
tableData?.data?.map(data => (
|
||||
<>
|
||||
<tr className={data.year_month_formatted == year_Month ? 'actual' : ''}>
|
||||
<td className='tg-gceh'>{data.year_month_formatted}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.nordeste).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.norte).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.sudeste).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.sul).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.nordeste).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.norte).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.sudeste).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.sul).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
})
|
||||
))
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@ -261,31 +263,31 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
if (index === 0) {
|
||||
return <>
|
||||
<tr>
|
||||
<td style={{borderTopLeftRadius: 8}} className='tg-gceh'>Máximo</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td style={{ borderTopLeftRadius: 8 }} className='tg-gceh'>Máximo</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
} else if (index===1) {
|
||||
} else if (index === 1) {
|
||||
return <>
|
||||
<tr>
|
||||
<td className='tg-gceh'>Mínimo</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
} else if (index===2) {
|
||||
} else if (index === 2) {
|
||||
return <>
|
||||
<tr>
|
||||
<td className='tg-gceh' style={{borderBottomColor: 'transparent'}}>Desv. Padrão</td>
|
||||
<td className='tg-uulg' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.nordeste_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.norte_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.sudeste_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.sul_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh' style={{ borderBottomColor: 'transparent' }}>Desv. Padrão</td>
|
||||
<td className='tg-uulg' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.nordeste_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.norte_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.sudeste_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
<td className='tg-uulg' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.sul_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
}
|
||||
@ -296,7 +298,7 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
</PldTableMinMaxView>
|
||||
|
||||
<PldTableView display={false}>
|
||||
<table className="tg tabela" style={{display: 'none'}}>
|
||||
<table className="tg tabela" style={{ display: 'none' }}>
|
||||
<thead>
|
||||
<tr className='tr'>
|
||||
<th className='tg-8oo6'>Mês</th>
|
||||
@ -308,14 +310,14 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
tableData.data.map(data => {
|
||||
tableData?.data?.map(data => {
|
||||
return <>
|
||||
<tr className={`${data.year_month_formatted==year_Month? 'actual' : ''} tr`}>
|
||||
<tr className={`${data.year_month_formatted == year_Month ? 'actual' : ''} tr`}>
|
||||
<td className='tg-gceh'>{data.year_month_formatted}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.nordeste).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.norte).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.sudeste).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.sul).toLocaleString('pt-br',{currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.nordeste).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.norte).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className={`tg-gceh`}>{parseFloat(data.sudeste).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className={`tg-uulg`}>{parseFloat(data.sul).toLocaleString('pt-br', { currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
})
|
||||
@ -325,31 +327,31 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
if (index === 0) {
|
||||
return <>
|
||||
<tr className='tr'>
|
||||
<td style={{borderTopLeftRadius: 8}} className='tg-gceh'>Máximo</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_max).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td style={{ borderTopLeftRadius: 8 }} className='tg-gceh'>Máximo</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_max).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
} else if (index===1) {
|
||||
} else if (index === 1) {
|
||||
return <>
|
||||
<tr className='tr'>
|
||||
<td className='tg-gceh'>Mínimo</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_min).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.nordeste_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.norte_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh'>{parseFloat(data.sudeste_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
<td className='tg-uulg'>{parseFloat(data.sul_min).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2, maximumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
} else if (index===2) {
|
||||
} else if (index === 2) {
|
||||
return <>
|
||||
<tr className='tr'>
|
||||
<td className='tg-gceh' style={{borderBottomColor: 'transparent'}}>Desv. Padrão</td>
|
||||
<td className='tg-uulg' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.nordeste_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.norte_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.sudeste_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-uulg' style={{borderBottomColor: 'transparent'}}>{parseFloat(data.sul_desv_pad).toLocaleString('pt-br',{style: 'currency', currency: 'BRL', minimumFractionDigits: 2})}</td>
|
||||
<td className='tg-gceh' style={{ borderBottomColor: 'transparent' }}>Desv. Padrão</td>
|
||||
<td className='tg-uulg' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.nordeste_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.norte_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
<td className='tg-gceh' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.sudeste_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
<td className='tg-uulg' style={{ borderBottomColor: 'transparent' }}>{parseFloat(data.sul_desv_pad).toLocaleString('pt-br', { style: 'currency', currency: 'BRL', minimumFractionDigits: 2 })}</td>
|
||||
</tr>
|
||||
</>
|
||||
}
|
||||
@ -361,7 +363,7 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
</RenderIf>
|
||||
|
||||
{/* grafico de grafico por seleção de data (mês) (diario)*/}
|
||||
<RenderIf isTrue={pldMenu===1}>
|
||||
<RenderIf isTrue={pldMenu === 1}>
|
||||
<PldGraphView>
|
||||
<section className='toolsbar2'>
|
||||
<FormControl sx={{
|
||||
@ -418,7 +420,7 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
</RenderIf>
|
||||
|
||||
{/* grafico de grafico por seleção de data INTEIRA (horario)*/}
|
||||
<RenderIf isTrue={pldMenu===2}>
|
||||
<RenderIf isTrue={pldMenu === 2}>
|
||||
<PldGraphView>
|
||||
<section className='toolsbar2'>
|
||||
{/* <p>Selecione a data: </p> */}
|
||||
@ -429,7 +431,7 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
inputFormat="dd/MM/yyyy"
|
||||
value={date}
|
||||
onChange={handleChangeDate}
|
||||
renderInput={(params) => <TextField {...params} style={{minWidth: '320px'}}/>}
|
||||
renderInput={(params) => <TextField {...params} style={{ minWidth: '320px' }} />}
|
||||
/>
|
||||
</div>
|
||||
</LocalizationProvider>
|
||||
@ -441,7 +443,7 @@ export default function pld({tableData, userName, clientMonth}: pldInterface) {
|
||||
/>
|
||||
</PldGraphView>
|
||||
</RenderIf>
|
||||
{pageYPosition > 300 && <a href="#title" style={{position: 'fixed', right: '50px', bottom: '100px'}}>
|
||||
{pageYPosition > 300 && <a href="#title" style={{ position: 'fixed', right: '50px', bottom: '100px' }}>
|
||||
<Fab aria-label="add">
|
||||
<NavigationIcon />
|
||||
</Fab>
|
||||
@ -455,11 +457,11 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const { ['@smartAuth-token']: token } = parseCookies(ctx)
|
||||
const { ['user-name']: userName } = parseCookies(ctx)
|
||||
|
||||
let tableData = [];
|
||||
let tableData = { data: [], result: [] };
|
||||
let clientMonth = [];
|
||||
|
||||
await apiClient.post('/pld/list').then(res => {
|
||||
tableData = res.data
|
||||
tableData = res.data.data
|
||||
})
|
||||
|
||||
await apiClient.post('/pld', {
|
||||
|
||||
@ -30,7 +30,7 @@ export default function ResumoOperacao({
|
||||
clientMonth
|
||||
}: any) {
|
||||
const [month, setMonth] = useState('')
|
||||
const [unidade, setUnidade] = useState(clients[0].cod_smart_unidade)
|
||||
const [unidade, setUnidade] = useState(clients?.[0]?.cod_smart_unidade ?? 0)
|
||||
const [tableDataState, setTableDataState] = useState<any>([])
|
||||
|
||||
const { ['user-id']: id } = parseCookies()
|
||||
|
||||
@ -61,7 +61,7 @@ const months = [
|
||||
]
|
||||
|
||||
export default function Telemetria({ userName, clients }: any) {
|
||||
const [unity, setUnity] = useState(clients[0]?.codigo_scde)
|
||||
const [unity, setUnity] = useState(clients?.[0]?.codigo_scde ?? 0)
|
||||
const [startDate, setStartDate] = useState(new Date())
|
||||
const [endDate, setEndDate] = useState(new Date())
|
||||
const [month, setMonth] = useState(new Date().getMonth())
|
||||
@ -915,7 +915,6 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
distinct: true
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(res.data)
|
||||
clients = res.data.data
|
||||
})
|
||||
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
import { api } from "./api";
|
||||
import { api } from './api'
|
||||
|
||||
export const TOKEN_KEY = "@smartAuth-token";
|
||||
export const TOKEN_KEY = '@smartAuth-token'
|
||||
|
||||
interface SignInRequestData {
|
||||
email: string,
|
||||
email: string
|
||||
password: string
|
||||
}
|
||||
|
||||
type UserObjectType = {
|
||||
name: string;
|
||||
email: string;
|
||||
client_id: number;
|
||||
id: number;
|
||||
role: number;
|
||||
name: string
|
||||
email: string
|
||||
client_id: number
|
||||
id: number
|
||||
role: number
|
||||
profile_picture?: string
|
||||
}
|
||||
|
||||
export async function signInRequest(data: SignInRequestData) {
|
||||
let user: UserObjectType, token: string, exception: any = null
|
||||
let user: UserObjectType, token: string
|
||||
|
||||
await api
|
||||
.post('/auth/login', {
|
||||
@ -36,9 +36,6 @@ export async function signInRequest(data: SignInRequestData) {
|
||||
profile_picture: res.data.user.profile_picture
|
||||
}
|
||||
})
|
||||
.catch((res) => {
|
||||
exception = res
|
||||
})
|
||||
|
||||
return {
|
||||
token,
|
||||
@ -49,15 +46,14 @@ export async function signInRequest(data: SignInRequestData) {
|
||||
id: user?.id,
|
||||
role: user?.role,
|
||||
profile_picture: user?.profile_picture
|
||||
},
|
||||
exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default async function recoverUserInformation(id) {
|
||||
let user: UserObjectType
|
||||
|
||||
await api.get(`/user/${id}`).then(res => {
|
||||
await api.get(`/user/${id}`).then((res) => {
|
||||
user = {
|
||||
name: res.data.user.name,
|
||||
email: res.data.user.email,
|
||||
@ -80,7 +76,8 @@ export default async function recoverUserInformation(id) {
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
await api.post('/auth/logout', {})
|
||||
await api
|
||||
.post('/auth/logout', {})
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
.then(res => {})
|
||||
.then((res) => {})
|
||||
}
|
||||
|
||||
@ -18,9 +18,12 @@ export default function getAPIClient(
|
||||
const { '@smartAuth-token': token } = parseCookies(ctx)
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'https://api.energiasmart.com.br/api'
|
||||
// baseURL: 'https://api.energiasmart.com.br/api'
|
||||
// baseURL: 'https://api.energiasmart.klupp.com.br/api'
|
||||
// baseURL: 'http://api-smart.test/api'
|
||||
baseURL:
|
||||
process.env.NODE_ENV === 'production'
|
||||
? 'https://api.energiasmart.com.br/api'
|
||||
: 'http://api-smart.test/api'
|
||||
})
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user