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'; import BasicButton from '../../../components/buttons/basicButton/BasicButton' import FaqButton1 from '../../../components/buttons/faqButton/FaqButton1'; import FaqButton2 from '../../../components/buttons/faqButton/FaqButton2'; import Header from '../../../components/header/Header' import InputUpload from '../../../components/inputUplaod/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'; 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 ; }); export default function clients({clients, userName}) { const [client, setClient] = useState({ name: String, email: String, password: String, password_confirmation: String, client_id: Number }) const [selectedClients, setSelectedClients] = useState([]) const [open, setOpen] = useState(false); const [openModalInativar, setOpenModalInativar] = useState(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 handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => { if (reason === 'clickaway') { return; } setOpenSnackError(false); setOpenSnackSuccess(false); }; const handleCloseSnackDelete = (event?: React.SyntheticEvent | Event, reason?: string) => { if (reason === 'clickaway') { return; } setOpenSnackErrorDelete(false); setOpenSnackSuccessDelete(false); }; // 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 => { 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) setOpenModalInativar(false) window.location.reload() }).catch(res => setOpenSnackErrorDelete(true)) }) } return (
Usuario cadastrada com sucesso! Usuario não cadastrada! Usuario excluida com sucesso! Usuario não excluida!
{ setSelectedClients(value) }}/>

Adicionar Cliente

Adicionar Cliente Smart Energia
{ setClient({ ...client, name: value.target.value }) }} variant="outlined" /> { setClient({ ...client, email: value.target.value }) }} 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)}/>
{setOpenModalInativar(value)}}> handleDeleteClient(selectedClients)}/> setOpenModalInativar(false)}/>
) } export const getServerSideProps: GetServerSideProps = async (ctx) => { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) const { ['user-name']: userName } = parseCookies(ctx) let clients = []; await apiClient.get('/user').then(res => { // console.log(res) clients = res.data.data // console.log(clients) }).catch(res => { // console.log(res) }) if (!token) { return { redirect: { destination: '/', permanent: false } } } return { props: { clients, userName } } }