From ff8c8073dbf0e506717e26f00f05c1304778754f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Leonardo=20Mur=C3=A7a?=
Date: Wed, 15 Jun 2022 15:03:12 -0300
Subject: [PATCH] Add action to avatar menu dropdown
---
src/AuthenticatedApp.js | 66 +++++++++++++++++++++++++--------------
src/components/Toolbar.js | 26 +++++++--------
src/screens/Home/index.js | 3 --
3 files changed, 53 insertions(+), 42 deletions(-)
diff --git a/src/AuthenticatedApp.js b/src/AuthenticatedApp.js
index 0826f86..3e7d44d 100644
--- a/src/AuthenticatedApp.js
+++ b/src/AuthenticatedApp.js
@@ -1,4 +1,4 @@
-import { Navigate, Route, Routes, useLocation } from 'react-router-dom';
+import { Navigate, Route, Routes, useNavigate } from 'react-router-dom';
import {
CalendarMonth,
CalendarMonthOutlined,
@@ -15,37 +15,55 @@ import { Container } from '@mui/system';
import useLayoutType from './hooks/useLayoutType';
import Toolbar from './components/Toolbar';
import { useUser } from './context/user';
+import { useAuthState } from './context/auth';
function AuthenticatedApp() {
+ const navigate = useNavigate();
const { state } = useUser();
+ const { logout } = useAuthState();
const layoutType = useLayoutType();
+ const avatarMenuOptions = [
+ {
+ text: 'Meu Perfil',
+ action: () => navigate('/profile', { replace: true }),
+ },
+ {
+ text: 'Sair',
+ action: logout,
+ },
+ ];
+
return (
- <>
-
- Olá, {state.user.name} 👋
-
- }
- layoutType={layoutType}
- />
-
-
+
+ Olá, {state.user.name} 👋
+
+ }
layoutType={layoutType}
+ avatarMenuOptions={avatarMenuOptions}
/>
-
- } />
- } />
- } />
- } />
-
-
- >
+
+
+
+ } />
+ } />
+ } />
+ } />
+
+
+ >
+ )
);
}
diff --git a/src/components/Toolbar.js b/src/components/Toolbar.js
index b5f358d..112e346 100644
--- a/src/components/Toolbar.js
+++ b/src/components/Toolbar.js
@@ -11,12 +11,10 @@ import {
} from '@mui/material';
import { useState } from 'react';
-function Toolbar({ title, layoutType }) {
+function Toolbar({ title, layoutType, avatarMenuOptions }) {
const [anchorElUser, setAnchorElUser] = useState(null);
const [anchorElNotifications, setAnchorElNotifications] = useState(null);
- console.log(layoutType);
-
switch (layoutType) {
case 'desktop':
return (
@@ -87,12 +85,11 @@ function Toolbar({ title, layoutType }) {
open={Boolean(anchorElUser)}
onClose={() => setAnchorElUser(null)}
>
-
-
+ {avatarMenuOptions.map(option => (
+
+ ))}
@@ -168,12 +165,11 @@ function Toolbar({ title, layoutType }) {
open={Boolean(anchorElUser)}
onClose={() => setAnchorElUser(null)}
>
-
-
+ {avatarMenuOptions.map(option => (
+
+ ))}
diff --git a/src/screens/Home/index.js b/src/screens/Home/index.js
index 190a837..cf56389 100644
--- a/src/screens/Home/index.js
+++ b/src/screens/Home/index.js
@@ -1,15 +1,12 @@
-import { useAuthState } from '../../context/auth';
import { useUser } from '../../context/user';
function Home() {
const { isPending, classrooms } = useUser();
- const { logout } = useAuthState();
return (
Página inicial
-
{isPending && Loading...
}
);