From 21e48cc09fb640fa49a0b7690ca6585dcd689a46 Mon Sep 17 00:00:00 2001 From: teffcode Date: Wed, 8 Mar 2023 22:42:30 -0500 Subject: [PATCH] add: lab reto 7 --- src/Components/Navbar/index.jsx | 33 ++++++++++++++++++++------------- src/Pages/App/index.jsx | 32 ++++++++++++++++++++++++-------- src/Pages/SignIn/index.jsx | 1 + 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/Components/Navbar/index.jsx b/src/Components/Navbar/index.jsx index 6729340..276efc3 100644 --- a/src/Components/Navbar/index.jsx +++ b/src/Components/Navbar/index.jsx @@ -11,6 +11,13 @@ const Navbar = () => { const signOut = localStorage.getItem('sign-out') const parsedSignOut = JSON.parse(signOut) const isUserSignOut = context.signOut || parsedSignOut + // Account + const account = localStorage.getItem('account') + const parsedAccount = JSON.parse(account) + // Has an account + const noAccountInLocalStorage = parsedAccount ? Object.keys(parsedAccount).length === 0 : true + const noAccountInLocalState = context.account ? Object.keys(context.account).length === 0 : true + const hasUserAnAccount = !noAccountInLocalStorage || !noAccountInLocalState const handleSignOut = () => { const stringifiedSignOut = JSON.stringify(true) @@ -19,18 +26,7 @@ const Navbar = () => { } const renderView = () => { - if (isUserSignOut) { - return ( -
  • - isActive ? activeStyle : undefined } - onClick={() => handleSignOut()}> - Sign out - -
  • - ) - } else { + if (hasUserAnAccount && !isUserSignOut) { return ( <>
  • @@ -60,6 +56,17 @@ const Navbar = () => {
  • ) + } else { + return ( +
  • + isActive ? activeStyle : undefined } + onClick={() => handleSignOut()}> + Sign in + +
  • + ) } } @@ -67,7 +74,7 @@ const Navbar = () => {