diff --git a/package.json b/package.json index 6928e76..cf6bbec 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "install": "^0.13.0", "next": "12.1.6", "nookies": "^2.5.2", + "notistack": "^2.0.5", "npm": "^8.10.0", "nprogress": "^0.2.0", "patternomaly": "^1.3.2", diff --git a/src/components/sidebar/Sidebar.tsx b/src/components/sidebar/Sidebar.tsx index 05c298d..1f08998 100644 --- a/src/components/sidebar/Sidebar.tsx +++ b/src/components/sidebar/Sidebar.tsx @@ -1,11 +1,12 @@ import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Modal from '@mui/material/Modal'; -import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; +import { GetServerSideProps } from 'next'; import Image from 'next/image' import Link from 'next/link' import { useRouter } from 'next/router' +import { parseCookies } from 'nookies'; import React, { useEffect, useState } from 'react' import RenderIf from '../../utils/renderIf'; @@ -34,9 +35,9 @@ export default function Sidebar() { const router = useRouter() - const user = { - role: 'admin' - } + const { ['user-role']: role } = parseCookies() + + console.log(role) useEffect(() => { setViewModal(false) @@ -44,7 +45,7 @@ export default function Sidebar() { return ( <> - +
setViewModal(!viewModal)} > @@ -57,22 +58,6 @@ export default function Sidebar() {
  • {'Visão Geral'}
  • {'FAQ >'}
  • {'Notificações >'}

    25

  • - {/*
  • setEconomiaDrawer(!economiaDrawer)} className={router.pathname=='/grossSavings' || router.pathname=='/accumulatedSavings' || router.pathname=='/estimatedCost' || router.pathname=='/costIndicator' ? 'actualPath' : null } >{'Economia >'}
  • -
    -
  • Economia Bruta
  • -
  • Economia Acumulada
  • -
  • Custo Estimado
  • -
  • Custo R/MWh
  • -
    */} - {/*
  • {'Telemetria >'}
  • -
  • {'Resumo de Op. '}
  • -
  • {'Notícias >'}
  • -
  • {'PLD >'}
  • -
  • {'Info Setorial >'}
  • -
  • {'Consumo'}
  • -
  • {'Notificações >'}

    25

  • -
  • {'Sobre Nós >'}
  • -
  • {'FAQ >'}
  • */} - +
    setViewModal(!viewModal)} > diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index 6e34ac9..32e36b7 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -40,7 +40,7 @@ export function AuthProvider({children}: {children: React.ReactNode}) { maxAge: 60 * 60 * 1, // 1 hour }) - // setCookie(undefined, 'user-role', user.role) + setCookie(undefined, 'user-role', user.role) api.defaults.headers['Authorization'] = `Bearer ${token}` diff --git a/src/pages/administrative/notification/index.tsx b/src/pages/administrative/notification/index.tsx index 4b30dcc..021095f 100644 --- a/src/pages/administrative/notification/index.tsx +++ b/src/pages/administrative/notification/index.tsx @@ -25,8 +25,8 @@ import getAPIClient from '../../../services/ssrApi'; import { GetServerSideProps } from 'next'; import { parseCookies } from 'nookies'; import Notifications from '../../notifications'; -import Snackbar from '@mui/material/Snackbar/Snackbar'; -import Alert from '@mui/material/Alert/Alert'; +import Snackbar from '@mui/material/Snackbar'; +import MuiAlert, { AlertProps } from '@mui/material/Alert'; const style = { position: 'absolute' as const, @@ -42,6 +42,13 @@ const style = { overflowY: 'scroll' }; +const Alert = React.forwardRef(function Alert( + props, + ref, +) { + return ; +}); + const icon = ; const checkedIcon = ; @@ -68,6 +75,15 @@ export default function notification({clients, notifications}) { 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, @@ -84,6 +100,17 @@ export default function notification({clients, notifications}) {
    + + + notificação cadastrada com sucesso! + + + + + Notificação não cadastrada! + + +
    @@ -168,16 +195,6 @@ export default function notification({clients, notifications}) { - - - This is a success message! - - - - - This is a success message! - - ) } diff --git a/src/services/auth.ts b/src/services/auth.ts index e2b196b..0edd74e 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -27,12 +27,13 @@ export async function signInRequest(data: SignInRequestData) { "password": data.password, "device_name": "test" }).then(res => { + // console.log(res.data.user.roles.pivot.role_id) user = { name: res.data.user.name, email: res.data.user.email, client_id: res.data.user.client_id, id: res.data.user.id, - role: res.data.user.roles.role_id + role: res.data.user.roles[0].pivot.role_id } token = res.data.token }).catch(res => { @@ -40,8 +41,14 @@ export async function signInRequest(data: SignInRequestData) { }) return { - token, - user + token: token, + user: { + name: user?.name, + email: user?.email, + client_id: user?.client_id, + id: user?.id, + role: user?.role + } } } @@ -55,13 +62,18 @@ export default async function recoverUserInformation(id) { email: res.data.user.email, client_id: res.data.user.client_id, id: res.data.user.id, - role: res.data.user.roles.role_id + role: res.data.user.roles[0].pivot.role_id } }).catch(res => { console.log(res) }) return { - user + user: { + name: user?.name, + email: user?.email, + client_id: user?.client_id, + id: user?.id + } } } diff --git a/yarn.lock b/yarn.lock index f46ffc0..ed043f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1994,7 +1994,7 @@ clone@^1.0.2: version "1.0.4" resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" -clsx@^1.0.4, clsx@^1.1.1: +clsx@^1.0.4, clsx@^1.1.0, clsx@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/clsx/-/clsx-1.1.1.tgz" @@ -3616,6 +3616,13 @@ normalize-path@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz" +notistack@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/notistack/-/notistack-2.0.5.tgz#8eb53720453f6e02182cd0e6784ced630a7bb7e6" + dependencies: + clsx "^1.1.0" + hoist-non-react-statics "^3.3.0" + npm-audit-report@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/npm-audit-report/-/npm-audit-report-3.0.0.tgz#1bf3e531208b5f77347c8d00c3d9badf5be30cd6"