diff --git a/src/components/administrativeTables/ClientsTable.tsx b/src/components/administrativeTables/ClientsTable.tsx index a56a973..90ccfaf 100644 --- a/src/components/administrativeTables/ClientsTable.tsx +++ b/src/components/administrativeTables/ClientsTable.tsx @@ -12,7 +12,34 @@ import TableSortLabel from '@mui/material/TableSortLabel'; import { visuallyHidden } from '@mui/utils'; import React, { useState, useEffect } from 'react'; +import Snackbar from '@mui/material/Snackbar'; +import MuiAlert, { AlertProps } from '@mui/material/Alert'; + +import Modal from '@mui/material/Modal'; + + import { TableView, StyledStatus } from './TableView'; +import { api } from '../../services/api'; + +const style = { + position: 'absolute' as const, + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + width: 900, + height: 500, + bgcolor: 'background.paper', + border: '2px solid #000', + boxShadow: 24, + p: 4, + overflowY: 'scroll' +}; +const Alert = React.forwardRef(function Alert( + props, + ref, +) { + return ; +}); interface Data { clientCode: number, @@ -161,6 +188,37 @@ export default function ClientTable({clients, onChange}: ClientsTableInterface) const [dense, setDense] = useState(false); const [rowsPerPage, setRowsPerPage] = useState(5); + const [openSnackError, setOpenSnackError] = useState(false); + + const [open, setOpen] = useState(false); + const [openModalInativar, setOpenModalInativar] = useState(false) + const handleOpen = () => setOpen(true); + const handleClose = () => setOpen(false); + + const [cod_client, setCod_client] = useState() + const [units, setUnits] = useState([]) + + function getClientUnits(client_id: number) { + api.post('/units', { + "filters": [ + {"type" : "=", "field": "dados_cadastrais.cod_smart_cliente", "value": client_id} + ], + "fields": ["unidade"], + "distinct": true + }).then(res => setUnits(res.data.data)).catch(res => { + setOpenSnackError(true) + }) + + return units + } + + const handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => { + if (reason === 'clickaway') { + return; + } + setOpenSnackError(false); + }; + const handleRequestSort = ( event: React.MouseEvent, property: keyof Data, @@ -220,6 +278,11 @@ export default function ClientTable({clients, onChange}: ClientsTableInterface) return ( + + + Não foi possivel encontrar unidades do client! + + {row.name} - clique aqui para ver as unidades + { + setOpen(true) + getClientUnits(row.client_id) + }}>clique aqui para ver as unidades {row.deleted_at? 'inativo' : 'ativo'} ); @@ -297,6 +363,25 @@ export default function ClientTable({clients, onChange}: ClientsTableInterface) onRowsPerPageChange={handleChangeRowsPerPage} /> + + + { + units.map((units, index) => { + return <> +
  • {units.unidade}
  • +
    + + }) + } +
    +
    ); } diff --git a/src/components/administrativeTables/FaqTable.tsx b/src/components/administrativeTables/FaqTable.tsx index a7014bb..9a6a0d7 100644 --- a/src/components/administrativeTables/FaqTable.tsx +++ b/src/components/administrativeTables/FaqTable.tsx @@ -283,7 +283,7 @@ export default function FaqTable({questionData, onChange}: FaqTableInterface) { {row.question} {row.answer} - {row.deleted_at? 'ativo' : 'inativo'} + {'ativo'} ); })} diff --git a/src/components/administrativeTables/NotificationsTable.tsx b/src/components/administrativeTables/NotificationsTable.tsx index 9b6a5af..345be97 100644 --- a/src/components/administrativeTables/NotificationsTable.tsx +++ b/src/components/administrativeTables/NotificationsTable.tsx @@ -290,7 +290,7 @@ export default function NotificationsTable({notifications, onChange}: Notificati {row.title} {'copel'} - {row.deleted_at===null? 'ativo' : 'inativo'} + {'ativo'} ); })} diff --git a/src/pages/administrative/clients/index.tsx b/src/pages/administrative/clients/index.tsx index dd710b6..f42abf3 100644 --- a/src/pages/administrative/clients/index.tsx +++ b/src/pages/administrative/clients/index.tsx @@ -1,11 +1,9 @@ import Box from '@mui/material/Box'; -import Button from '@mui/material/Button'; 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'; @@ -23,6 +21,8 @@ import { parseCookies } from 'nookies'; import { GetServerSideProps } from 'next'; import getAPIClient from '../../../services/ssrApi'; +import FormData from 'form-data'; + const style = { position: 'absolute' as const, top: '50%', @@ -44,7 +44,9 @@ const Alert = React.forwardRef(function Alert( return ; }); -export default function clients({clients}) { +export default function clients({clients, userName}) { + const formData = new FormData(); + const [client, setClient] = useState({ name: String, email: String, @@ -52,6 +54,7 @@ export default function clients({clients}) { password_confirmation: String, client_id: Number }) + const [logo, setLogo] = useState(false); const [selectedClients, setSelectedClients] = useState([]) const [open, setOpen] = useState(false); @@ -61,7 +64,6 @@ export default function clients({clients}) { const [openModal, setOpenModal] = useState(false) - // const [openSnackSuccess, setOpenSnackSuccess] = useState(false); const [openSnackError, setOpenSnackError] = useState(false); const [openSnackSuccessDelete, setOpenSnackSuccessDelete] = useState(false); @@ -84,20 +86,20 @@ export default function clients({clients}) { setOpenSnackErrorDelete(false); setOpenSnackSuccessDelete(false); }; - // + + function onChange(e) { + setLogo(e.target.files[0]) + } function handleCreateClient({name, email, password, password_confirmation, client_id}) { - api.post('/user', { - name, - email, - password, - password_confirmation, - client_id - }, { - headers: { - 'Content-Type': 'multipart/form-data' - }, - }).then(res => { + formData.append('name', name) + formData.append('email', email) + formData.append('password', password) + formData.append('password_confirmation', password_confirmation) + formData.append('client_id', client_id) + formData.append('profile_picture', logo) + + api.post('/user', formData).then(res => { setOpenSnackSuccess(true) setOpenModalInativar(false) window.location.reload() @@ -105,7 +107,6 @@ export default function clients({clients}) { setOpenSnackError(true) }) } - async function handleDeleteClient(id: any) { await id.map(client => { api.delete(`/user/${client}`).then(res => { @@ -118,26 +119,25 @@ export default function clients({clients}) { return (
    - - notificação cadastrada com sucesso! + Usuario cadastrada com sucesso! - Notificação não cadastrada! + Usuario não cadastrada! - notificação excluida com sucesso! + Usuario excluida com sucesso! - Notificação não excluida! + Usuario não excluida! @@ -196,7 +196,8 @@ export default function clients({clients}) { client_id: value.target.value }) }} variant="outlined" /> - + + {/* */}

    setOpen(false)} /> handleCreateClient(client)}/> @@ -206,7 +207,6 @@ export default function clients({clients}) { {setOpenModalInativar(value)}}> - handleDeleteClient(selectedClients)}/> setOpenModalInativar(false)}/> @@ -218,6 +218,7 @@ export default function clients({clients}) { export const getServerSideProps: GetServerSideProps = async (ctx) => { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) + const { ['user-name']: userName } = parseCookies(ctx) let clients = []; @@ -241,6 +242,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { clients, + userName } } } diff --git a/src/pages/pld/index.tsx b/src/pages/pld/index.tsx index 98a3b72..79a547c 100644 --- a/src/pages/pld/index.tsx +++ b/src/pages/pld/index.tsx @@ -26,9 +26,10 @@ interface pldInterface { graphByHourData: any, graphByMonthData: any userName: string, + clientMonth: any } -export default function pld({tableData, graphByHourData, graphByMonthData, userName}: pldInterface) { +export default function pld({tableData, graphByHourData, graphByMonthData, userName, clientMonth}: pldInterface) { const router = useRouter() const { region } = router.query @@ -255,18 +256,17 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN label="Age" > - 01 - 02 - 03 - 04 - 05 - 06 - 07 - 08 - 09 - 10 - 11 - 12 + Nenhum + { + clientMonth.sort((a, b) => { + if (parseFloat(a.mes_ref.slice(3,4)) > parseFloat(b.mes_ref.slice(3,4))) return 1 + if (parseFloat(a.mes_ref.slice(3,4)) < parseFloat(b.mes_ref.slice(3,4))) return -1 + + return 0 + }).map((data, index) => { + return {data.mes_ref.slice(2, 4)} + }) + } @@ -288,7 +288,7 @@ export default function pld({tableData, graphByHourData, graphByMonthData, userN @@ -301,8 +301,8 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { const { ['@smartAuth-token']: token } = parseCookies(ctx) const { ['user-name']: userName } = parseCookies(ctx) - let tableData = []; + let clientMonth = []; await apiClient.post('/pld/list').then(res => { tableData = res.data @@ -310,6 +310,16 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { console.log(res) }) + await apiClient.post('/pld', { + "filters": [], + "fields": ["mes_ref"], + "distinct": true + }).then(res => { + clientMonth = res.data.data + }).catch(res => { + console.log(res) + }) + if (!token) { return { redirect: { @@ -322,7 +332,8 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { props: { tableData, - userName + userName, + clientMonth } } }