diff --git a/src/components/administrativeTables/ClientsTable.tsx b/src/components/administrativeTables/ClientsTable.tsx index 748e87e..364a12d 100644 --- a/src/components/administrativeTables/ClientsTable.tsx +++ b/src/components/administrativeTables/ClientsTable.tsx @@ -180,7 +180,7 @@ function EnhancedTableHead(props: EnhancedTableProps) { ); } -export default function ClientTable() { +export default function ClientTable({clients}: any) { const [order, setOrder] = useState('asc'); const [orderBy, setOrderBy] = useState('status'); const [selected, setSelected] = useState([]); @@ -199,7 +199,7 @@ export default function ClientTable() { const handleSelectAllClick = (event: React.ChangeEvent) => { if (event.target.checked) { - const newSelecteds = rows.map((n) => n.name); + const newSelecteds = clients.map((n) => n.name); setSelected(newSelecteds); return; } @@ -259,20 +259,20 @@ export default function ClientTable() { rowCount={rows.length} /> - {stableSort(rows, getComparator(order, orderBy)) + {stableSort(clients, getComparator(order, orderBy)) .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) .map((row, index) => { - const isItemSelected = isSelected(row.clientCode); + const isItemSelected = isSelected(row.id); const labelId = `enhanced-table-checkbox-${index}`; return ( handleClick(event, row.clientCode.toString())} + onClick={(event) => handleClick(event, row.id.toString())} role="checkbox" aria-checked={isItemSelected} tabIndex={-1} - key={row.clientCode} + key={row.id} selected={isItemSelected} > @@ -290,11 +290,11 @@ export default function ClientTable() { scope="row" padding="none" > - Unidade - {row.clientCode} + Client - {row.client_id} {row.name} - {row.unity}button - {row.status} + clique aqui para ver as unidades + {row.deleted_at? 'inativo' : 'ativo'} ); })} diff --git a/src/pages/administrative/clients.tsx b/src/pages/administrative/clients.tsx index 23ac5e3..1a7b827 100644 --- a/src/pages/administrative/clients.tsx +++ b/src/pages/administrative/clients.tsx @@ -18,6 +18,9 @@ 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, @@ -33,8 +36,8 @@ const style = { overflowY: 'scroll' }; -export default function clients() { - const [client, setClient] = useState({ +export default function clients({clients}) { + const [client, setClient] = useState({ name: String, email: String, password: String, @@ -50,7 +53,7 @@ export default function clients() { const [openModal, setOpenModal] = useState(false) function handleCreateClient({name, email, password, password_confirmation, client_id}) { - api.post('', { + api.post('/user', { name, email, password, @@ -79,19 +82,44 @@ export default function clients() { 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" />

- console.log()} /> - console.log()}/> + console.log()} /> + handleCreateClient(client)}/>
- +
@@ -104,3 +132,32 @@ export default function clients() { ) } + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + const apiClient = getAPIClient(ctx) + const { ['@smartAuth-token']: token } = parseCookies(ctx) + + let clients = []; + + await apiClient.get('/user').then(res => { + clients = res.data + }).catch(res => { + console.log(res) + }) + + if (!token) { + return { + redirect: { + destination: '/', + permanent: false + } + } + } + + return { + props: { + clients, + } + } +} +