import CheckBoxIcon from '@mui/icons-material/CheckBox'; import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank'; import Autocomplete from '@mui/material/Autocomplete'; import Box from '@mui/material/Box'; import Checkbox from '@mui/material/Checkbox'; import FormControl from '@mui/material/FormControl'; import Modal from '@mui/material/Modal'; import TextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import Head from 'next/head' import React, { useState } from 'react' import NotificationsTable from '../../../components/administrativeTables/NotificationsTable' import FaqButton1 from '../../../components/buttons/faqButton/FaqButton1'; import FaqButton2 from '../../../components/buttons/faqButton/FaqButton2'; import Header from '../../../components/header/Header' import PageTitle from '../../../components/pageTitle/PageTitle' import { api } from '../../../services/api'; import { FaqView } from '../../../styles/layouts/commonQuestions/FaqView' import Radio from '@mui/material/Radio'; import RadioGroup from '@mui/material/RadioGroup'; import FormControlLabel from '@mui/material/FormControlLabel'; import getAPIClient from '../../../services/ssrApi'; import { GetServerSideProps } from 'next'; import { parseCookies } from 'nookies'; import Notifications from '../../notifications'; import Snackbar from '@mui/material/Snackbar'; import MuiAlert, { AlertProps } from '@mui/material/Alert'; 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 ; }); const icon = ; const checkedIcon = ; interface NotificationInterface { title: string, body: string, users: object[] } export default function notification({clients, notifications}) { const [notification, setNotification] = useState({ title: '', body: '', users: [] }) const [open, setOpen] = useState(false); const [openSnackSuccess, setOpenSnackSuccess] = useState(false); const [openSnackError, setOpenSnackError] = useState(false); const [radiusValue, setRadiusValue] = useState('all'); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); const handleCloseSnack = (event?: React.SyntheticEvent | Event, reason?: string) => { if (reason === 'clickaway') { return; } setOpenSnackError(false); }; async function handleRegisterNewNotification({title, body, users}: NotificationInterface) { await api.post('/notification', { title, body, users }).then(res => setOpenSnackSuccess(true)).catch(res => setOpenSnackError(true)) } return ( Smart Energia - Notificações
notificação cadastrada com sucesso! Notificação não cadastrada!

Disparar Notificações

Pode ser que todas as notificaçõs demorem alguns minutos para estarem disponíveis
{ setNotification({ ...notification, title: value.target.value }) }} variant="outlined" />

{ setNotification({ ...notification, body: value.target.value }) }} variant="outlined" />

} checked={radiusValue==='all'? true : false}onChange={(value: React.ChangeEvent) => { setRadiusValue(value.target.value) }} label="Disparar para todos os clientes" /> } checked={radiusValue==='some'? true : false} onChange={(value: React.ChangeEvent) => { setRadiusValue(value.target.value) }} label="Disparar somente para alguns clientes" />
{ radiusValue === 'some'? { setNotification({...notification, users: newValue.map((el) => {return {"user_id": el.id}})}); }} getOptionLabel={(option) => option.name} renderOption={(props, option, { selected }) => (
  • {option.name}
  • )} sx={{ml:8}} style={{ width: 700 }} renderInput={(params) => ( )} /> : null } {console.log()}} /> { handleRegisterNewNotification(notification) }} />
    ) } export const getServerSideProps: GetServerSideProps = async (ctx) => { const apiClient = getAPIClient(ctx) const { ['@smartAuth-token']: token } = parseCookies(ctx) let clients = []; let notifications = []; await apiClient.get('/user').then(res => { clients = res.data }).catch(res => { console.log(res) }) await apiClient.get('/notification').then(res => { notifications = res.data }).catch(res => { console.log(res) }) if (!token) { return { redirect: { destination: '/', permanent: false } } } return { props: { clients, notifications } } }