diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx new file mode 100644 index 0000000..ef1f11f --- /dev/null +++ b/src/components/Header/index.tsx @@ -0,0 +1,16 @@ +import { User } from 'types/User'; + +type HeaderProps = { + user: User; +}; + +function Header({ user }: HeaderProps) { + return ( +
+
Test logo for {user.email}
+
Test image for {user.name}
+
+ ); +} + +export default Header; diff --git a/src/components/PrivateRoutes/index.tsx b/src/components/PrivateRoutes/index.tsx index 74d261e..ce3c46d 100644 --- a/src/components/PrivateRoutes/index.tsx +++ b/src/components/PrivateRoutes/index.tsx @@ -1,11 +1,10 @@ import { useState, useEffect } from 'react'; -import { Navigate, Outlet, useOutletContext } from 'react-router-dom'; +import { Navigate, Outlet } from 'react-router-dom'; +import Header from 'components/Header'; import { getItem } from 'helpers/localStorage'; import type { User } from 'types/User'; -type ContextType = User; - import { LOGIN_URL } from '../../constants'; function PrivateRoutes() { @@ -16,7 +15,7 @@ function PrivateRoutes() { const fetchCurrentUser = async () => { const userProfile = getItem('UserProfile'); if (userProfile?.user) { - setUser({ ...userProfile.user }); + setUser({ name: userProfile.user.name, email: userProfile.user.email, avatarUrl: userProfile.user.avatar_url }); } setLoading(false); @@ -28,11 +27,14 @@ function PrivateRoutes() { return

Loading...

; } - return user ? : ; + return user ? ( + <> +
+ + + ) : ( + + ); } export default PrivateRoutes; - -export function useUser() { - return useOutletContext(); -} diff --git a/src/screens/Home/index.tsx b/src/screens/Home/index.tsx index 6cc0710..c87cb3e 100644 --- a/src/screens/Home/index.tsx +++ b/src/screens/Home/index.tsx @@ -1,15 +1,9 @@ -import { useUser } from 'components/PrivateRoutes'; - const HomeScreen = (): JSX.Element => { - const user = useUser(); - return ( <>
Home Screen
- {/* TODO: Remove when header implemented in #19 */} -
{`${user?.name} - ${user?.email} - ${user?.avatarUrl}`}
); };