diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx index 84bd8b3..70d018b 100644 --- a/src/Components/Api/Api.tsx +++ b/src/Components/Api/Api.tsx @@ -115,6 +115,7 @@ export function UserInfo() { }, }) .then((response) => { + console.log(response.data); return response.data; }) .catch((error) => { diff --git a/src/Components/Header/Header.tsx b/src/Components/Header/Header.tsx index 3ba2bdc..3acb0b8 100644 --- a/src/Components/Header/Header.tsx +++ b/src/Components/Header/Header.tsx @@ -4,6 +4,7 @@ import styles from "../../styles"; import AppIcon from "../AppIcon/AppIcon"; import Login from "../LoginButton/LoginButton"; import HomeIcon from "../HomeIcon/HomeIcon"; +import UserIcon from "../UserIcon/UserIcon"; export default function Header() { return ( @@ -16,8 +17,7 @@ export default function Header() { }} > - - +
navigate("/User")} + > + + + + + + + ); +} diff --git a/src/Routes/UserPage/UserPage.tsx b/src/Routes/UserPage/UserPage.tsx new file mode 100644 index 0000000..0085caf --- /dev/null +++ b/src/Routes/UserPage/UserPage.tsx @@ -0,0 +1,41 @@ +import styles from "../../styles"; +import Header from "../../Components/Header/Header"; +import { UserInfo } from "../../Components/Api/Api"; +import { useQuery } from "react-query"; +import { useSelector } from "react-redux"; +import { LoginState } from "../../Interfaces/Interfaces"; + +export default function UserPage() { + const { data, isLoading, error } = useQuery("user", UserInfo, { retry: 0 }); + const logged_in = useSelector((state: LoginState) => state.Login.logged_in); + if (isLoading && !error) { + return ( +
+
+

Loading...

+
+ ); + } else if (error) { + return ( +
+
+

An error has occured

+
+ ); + } else if (!logged_in) { + return ( +
+
+

Please login to view user info

+
+ ); + } + return ( +
+
+

Username: {data.username}

+

Email: {data.email}

+

User ID: {data.id}

+
+ ); +} diff --git a/src/index.tsx b/src/index.tsx index 0407eef..04f137a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -9,12 +9,13 @@ import NewNote from "./Routes/NewNote/NewNote"; import Login from "./Routes/Login/Login"; import Activation from "./Routes/Activation/Activation"; import Register from "./Routes/Register/Register"; +import UserPage from "./Routes/UserPage/UserPage"; +import ViewEditNote from "./Routes/ViewEditNote/ViewEditNote"; import { QueryClient, QueryClientProvider } from "react-query"; import { Provider } from "react-redux"; import Store from "./Features/Redux/Store/Store"; -import ViewEditNote from "./Routes/ViewEditNote/ViewEditNote"; const queryClient = new QueryClient(); @@ -43,6 +44,10 @@ const router = createBrowserRouter([ path: "/Note/:id", element: , }, + { + path: "/User", + element: , + }, ]); const root = ReactDOM.createRoot(