diff --git a/src/components/administrativeTables/ClientsTable.tsx b/src/components/administrativeTables/ClientsTable.tsx index 742d03a..6cea371 100644 --- a/src/components/administrativeTables/ClientsTable.tsx +++ b/src/components/administrativeTables/ClientsTable.tsx @@ -67,7 +67,7 @@ type Order = 'asc' | 'desc'; function getComparator( order: Order, - orderBy: Key, + orderBy: any, ): ( a: { [key in Key]: number | string }, b: { [key in Key]: number | string }, @@ -136,7 +136,7 @@ function EnhancedTableHead(props: EnhancedTableProps) { const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } = props; const createSortHandler = - (property: keyof Data) => (event: React.MouseEvent) => { + (property: any) => (event: React.MouseEvent) => { onRequestSort(event, property); }; @@ -206,12 +206,12 @@ export default function ClientTable() { setSelected([]); }; - const handleClick = (event: React.MouseEvent, name: string) => { - const selectedIndex = selected.indexOf(name); + const handleClick = (event: React.MouseEvent, code: string) => { + const selectedIndex = selected.indexOf(code); let newSelected: readonly string[] = []; if (selectedIndex === -1) { - newSelected = newSelected.concat(selected, name); + newSelected = newSelected.concat(selected, code); } else if (selectedIndex === 0) { newSelected = newSelected.concat(selected.slice(1)); } else if (selectedIndex === selected.length - 1) { @@ -235,7 +235,7 @@ export default function ClientTable() { setPage(0); }; - const isSelected = (name: string) => selected.indexOf(name) !== -1; + const isSelected = (code: any) => selected.indexOf(code.toString()) !== -1; // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = @@ -268,7 +268,7 @@ export default function ClientTable() { return ( handleClick(event, row.clientCode)} + onClick={(event) => handleClick(event, row.clientCode.toString())} role="checkbox" aria-checked={isItemSelected} tabIndex={-1} diff --git a/src/components/administrativeTables/ClientsTableView.ts b/src/components/administrativeTables/ClientsTableView.ts index 4ad9b11..aa4aed0 100644 --- a/src/components/administrativeTables/ClientsTableView.ts +++ b/src/components/administrativeTables/ClientsTableView.ts @@ -33,7 +33,7 @@ export const ClientTableView = styled.main` } ` -export const StyledStatus = styled.div<{status: string}>` +export const StyledStatus = styled.div<{status: any}>` display: flex; align-items: center; justify-content: center; diff --git a/src/components/administrativeTables/FaqTable.tsx b/src/components/administrativeTables/FaqTable.tsx index 103fe10..7877191 100644 --- a/src/components/administrativeTables/FaqTable.tsx +++ b/src/components/administrativeTables/FaqTable.tsx @@ -42,12 +42,12 @@ function createData( } const rows = [ - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'Active'), - createData('Como usar o sistema', 'Você deve usar assim... e assado...', 'active'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'active'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'active'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'active'), - createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'inactive'), + createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), + createData('Como usar o sistema', 'Você deve usar assim... e assado...', 'ativo'), + createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), + createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), + createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'ativo'), + createData('Como usar o sistema?', 'Você deve usar assim... e assado...', 'inativo'), ]; function descendingComparator(a: T, b: T, orderBy: keyof T) { @@ -66,8 +66,8 @@ function getComparator( order: Order, orderBy: Key, ): ( - a: { [key in Key]: number | string }, - b: { [key in Key]: number | string }, + a: { [key in Key]: any }, + b: { [key in Key]: any }, ) => number { return order === 'desc' ? (a, b) => descendingComparator(a, b, orderBy) @@ -98,13 +98,13 @@ const headCells: readonly HeadCell[] = [ id: 'question', numeric: false, disablePadding: true, - label: 'código do cliente', + label: 'Pergunta', }, { id: 'answer', numeric: true, disablePadding: false, - label: 'name', + label: 'Resposta', }, { id: 'status', @@ -127,7 +127,7 @@ function EnhancedTableHead(props: EnhancedTableProps) { const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } = props; const createSortHandler = - (property: keyof Data) => (event: React.MouseEvent) => { + (property: any) => (event: React.MouseEvent) => { onRequestSort(event, property); }; @@ -171,7 +171,7 @@ function EnhancedTableHead(props: EnhancedTableProps) { ); } -export default function ClientTable() { +export default function FaqTable() { const [order, setOrder] = useState('asc'); const [orderBy, setOrderBy] = useState('status'); const [selected, setSelected] = useState([]); @@ -190,7 +190,7 @@ export default function ClientTable() { const handleSelectAllClick = (event: React.ChangeEvent) => { if (event.target.checked) { - const newSelecteds = rows.map((n) => n.name); + const newSelecteds = rows.map((n) => n.question); setSelected(newSelecteds); return; } diff --git a/src/components/administrativeTables/NotificationsTable.tsx b/src/components/administrativeTables/NotificationsTable.tsx new file mode 100644 index 0000000..e462c4f --- /dev/null +++ b/src/components/administrativeTables/NotificationsTable.tsx @@ -0,0 +1,315 @@ +import DeleteIcon from '@mui/icons-material/Delete'; +import FilterListIcon from '@mui/icons-material/FilterList'; +import Box from '@mui/material/Box'; +import Checkbox from '@mui/material/Checkbox'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import IconButton from '@mui/material/IconButton'; +import Paper from '@mui/material/Paper'; +import { alpha } from '@mui/material/styles'; +import Switch from '@mui/material/Switch'; +import Table from '@mui/material/Table'; +import TableBody from '@mui/material/TableBody'; +import TableCell from '@mui/material/TableCell'; +import TableContainer from '@mui/material/TableContainer'; +import TableHead from '@mui/material/TableHead'; +import TablePagination from '@mui/material/TablePagination'; +import TableRow from '@mui/material/TableRow'; +import TableSortLabel from '@mui/material/TableSortLabel'; +import Toolbar from '@mui/material/Toolbar'; +import Tooltip from '@mui/material/Tooltip'; +import Typography from '@mui/material/Typography'; +import { visuallyHidden } from '@mui/utils'; +import React, { useState } from 'react'; + +import { ClientTableView, StyledStatus } from './ClientsTableView'; + +interface Data { + notification: string, + client: string, + status: string, +} + +function createData( + notification: string, + client: string, + status: string, +): Data { + return { + notification, + client, + status, + }; +} + +const rows = [ + createData('Confira tal coisa - Texto da notificação', 'Copel', 'enviada'), + createData('Confira tal coisa - Texto da notificação', 'Copel', 'enviada'), + createData('Confira tal coisa - Texto da notificação', 'Copel', 'enviada'), + createData('Confira tal coisa - Texto da notificação', 'Copel', 'falhou'), + createData('Confira tal coisa - Texto da notificação', 'Copel', 'pendente'), + createData('Confira tal coisa - Texto da notificação', 'Copel', 'enviada'), +]; + +function descendingComparator(a: T, b: T, orderBy: keyof T) { + if (b[orderBy] < a[orderBy]) { + return -1; + } + if (b[orderBy] > a[orderBy]) { + return 1; + } + return 0; +} + +type Order = 'asc' | 'desc'; + +function getComparator( + order: Order, + orderBy: Key, +): ( + a: { [key in Key]: any }, + b: { [key in Key]: any }, +) => number { + return order === 'desc' + ? (a, b) => descendingComparator(a, b, orderBy) + : (a, b) => -descendingComparator(a, b, orderBy); +} + +function stableSort(array: readonly T[], comparator: (a: T, b: T) => number) { + const stabilizedThis = array.map((el, index) => [el, index] as [T, number]); + stabilizedThis.sort((a, b) => { + const order = comparator(a[0], b[0]); + if (order !== 0) { + return order; + } + return a[1] - b[1]; + }); + return stabilizedThis.map((el) => el[0]); +} + +interface HeadCell { + disablePadding: boolean; + id: keyof Data | string; + label: string; + numeric: boolean; +} + +const headCells: readonly HeadCell[] = [ + { + id: 'notification', + numeric: false, + disablePadding: true, + label: 'notificação', + }, + { + id: 'client', + numeric: true, + disablePadding: false, + label: 'cliente', + }, + { + id: 'status', + numeric: true, + disablePadding: false, + label: 'status', + }, +]; + +interface EnhancedTableProps { + numSelected: number; + onRequestSort: (event: React.MouseEvent, property: keyof Data) => void; + onSelectAllClick: (event: React.ChangeEvent) => void; + order: Order; + orderBy: string; + rowCount: number; +} + +function EnhancedTableHead(props: EnhancedTableProps) { + const { onSelectAllClick, order, orderBy, numSelected, rowCount, onRequestSort } = + props; + const createSortHandler = + (property: any) => (event: React.MouseEvent) => { + onRequestSort(event, property); + }; + + return ( + + + + 0 && numSelected < rowCount} + checked={rowCount > 0 && numSelected === rowCount} + onChange={onSelectAllClick} + inputProps={{ + 'aria-label': 'select all desserts', + }} + /> + + {headCells.map((headCell) => ( + + + {headCell.label} + {orderBy === headCell.id ? ( + + {order === 'desc' ? 'sorted descending' : 'sorted ascending'} + + ) : null} + + + ))} + + + ); +} + +export default function ClientTable() { + const [order, setOrder] = useState('asc'); + const [orderBy, setOrderBy] = useState('status'); + const [selected, setSelected] = useState([]); + const [page, setPage] = useState(0); + const [dense, setDense] = useState(false); + const [rowsPerPage, setRowsPerPage] = useState(5); + + const handleRequestSort = ( + event: React.MouseEvent, + property: keyof Data, + ) => { + const isAsc = orderBy === property && order === 'asc'; + setOrder(isAsc ? 'desc' : 'asc'); + setOrderBy(property); + }; + + const handleSelectAllClick = (event: React.ChangeEvent) => { + if (event.target.checked) { + const newSelecteds = rows.map((n) => n.notification); + setSelected(newSelecteds); + return; + } + setSelected([]); + }; + + const handleClick = (event: React.MouseEvent, name: string) => { + const selectedIndex = selected.indexOf(name); + let newSelected: readonly string[] = []; + + if (selectedIndex === -1) { + newSelected = newSelected.concat(selected, name); + } else if (selectedIndex === 0) { + newSelected = newSelected.concat(selected.slice(1)); + } else if (selectedIndex === selected.length - 1) { + newSelected = newSelected.concat(selected.slice(0, -1)); + } else if (selectedIndex > 0) { + newSelected = newSelected.concat( + selected.slice(0, selectedIndex), + selected.slice(selectedIndex + 1), + ); + } + + setSelected(newSelected); + }; + + const handleChangePage = (event: unknown, newPage: number) => { + setPage(newPage); + }; + + const handleChangeRowsPerPage = (event: React.ChangeEvent) => { + setRowsPerPage(parseInt(event.target.value, 10)); + setPage(0); + }; + + const isSelected = (name: string) => selected.indexOf(name) !== -1; + + // Avoid a layout jump when reaching the last page with empty rows. + const emptyRows = + page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; + + return ( + + + + + + + {stableSort(rows, getComparator(order, orderBy)) + .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) + .map((row, index) => { + const isItemSelected = isSelected(row.notification.toString()); + const labelId = `enhanced-table-checkbox-${index}`; + + return ( + handleClick(event, row.notification.toString())} + role="checkbox" + aria-checked={isItemSelected} + tabIndex={-1} + key={row.notification} + selected={isItemSelected} + > + + + + + {row.notification} + + {row.client} + {row.status} + + ); + })} + {emptyRows > 0 && ( + + + + )} + +
+
+ +
+
+ ); +} diff --git a/src/components/sidebar/Sidebar.tsx b/src/components/sidebar/Sidebar.tsx index 407206c..bd1ec75 100644 --- a/src/components/sidebar/Sidebar.tsx +++ b/src/components/sidebar/Sidebar.tsx @@ -63,6 +63,7 @@ export default function Sidebar() { */}
  • {'Clientes >'}
  • {'FAQ >'}
  • +
  • {'Notificações >'}

    25

  • {/*
  • {'Telemetria >'}
  • {'Resumo de Op. '}
  • {'Notícias >'}
  • diff --git a/src/pages/administrative/clients.tsx b/src/pages/administrative/clients.tsx index c1712b3..17fa2cd 100644 --- a/src/pages/administrative/clients.tsx +++ b/src/pages/administrative/clients.tsx @@ -6,6 +6,7 @@ import React, { useState } from 'react' import AdministrativeHeader from '../../components/administrativeHeader/AdministrativeHeader'; import ClientsTable from '../../components/administrativeTables/ClientsTable'; import BasicButton from '../../components/buttons/basicButton/BasicButton' +import Header from '../../components/header/Header' import ConfirmModal from '../../components/modal/ConfirmModal'; import Modal from '../../components/modal/Modal'; import PageTitle from '../../components/pageTitle/PageTitle' @@ -15,29 +16,10 @@ export default function clients() { const [openModal, setOpenModal] = useState(false) const [openModalInativar, setOpenModalInativar] = useState(false) - const rows = [ - { id: 1, codigoCliente: 'Unidade - 9500130', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - { id: 2, codigoCliente: 'Unidade - 9500130', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - { id: 3, codigoCliente: 'Unidade - 9500130', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - { id: 4, codigoCliente: 'Unidade - 9500689', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - { id: 5, codigoCliente: 'Unidade - 9500689', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - { id: 6, codigoCliente: 'Unidade - 9500689', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - { id: 7, codigoCliente: 'Unidade - 9500130', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - { id: 8, codigoCliente: 'Unidade - 9500130', clientName: 'FraCopelnces', units: 'clique para ver unidades', age: 'ativo' }, - { id: 9, codigoCliente: 'Unidade - 9500130', clientName: 'Copel', units: 'clique para ver unidades', age: 'ativo' }, - ]; - - const columns: GridColDef[] = [ - { field: 'codigoCliente', headerName: 'Código Cliente', width: 180 }, - { field: 'clientName', headerName: 'Nome do cliente', width: 130 }, - { field: 'units', headerName: 'Unidade', width: 130 }, - { field: 'status', headerName: 'Status', width: 90 }, - ]; - return (
    - +
    diff --git a/src/pages/administrative/notifications/index.tsx b/src/pages/administrative/notifications/index.tsx index f585fa2..d398c8c 100644 --- a/src/pages/administrative/notifications/index.tsx +++ b/src/pages/administrative/notifications/index.tsx @@ -7,6 +7,7 @@ import Head from 'next/head' import React from 'react' import AdministrativeHeader from '../../../components/administrativeHeader/AdministrativeHeader' +import NotificationsTable from '../../../components/administrativeTables/NotificationsTable'; import BasicButton from '../../../components/buttons/basicButton/BasicButton'; import CommonQuestionsCard from '../../../components/faqQuestionsCard/FaqQuestionsCard' import Header from '../../../components/header/Header' @@ -26,53 +27,13 @@ export default function commonQuestions() { return ( <> - - Smart Energia - FAQ - - -

    Perguntas Frequentes

    -

    Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    + + Smart Energia - FAQ + +
    - - -
    - - - - Clientes - - -
    - console.log()}/> - -
    - -
    - -
    - -
    - -
    - -
    -
    + ) diff --git a/src/styles/layouts/clients/ClientsView.ts b/src/styles/layouts/clients/ClientsView.ts index 21ab268..7692ffe 100644 --- a/src/styles/layouts/clients/ClientsView.ts +++ b/src/styles/layouts/clients/ClientsView.ts @@ -11,17 +11,13 @@ export const ClientsView = styled.main` width: 100%; - :nth-child(2) { + :nth-child(3) { justify-content: space-between; width: 18rem; margin: 45px 0 22px 0; } - - :last-child { - width: 100%; - } } `