From 48ed8f45c6fd8336f720005e1df85c4d909c7b1b Mon Sep 17 00:00:00 2001 From: keannu125 Date: Mon, 6 Mar 2023 13:59:16 +0800 Subject: [PATCH] Added individual product views and fixed login session checker --- src/App.tsx | 9 +++++ src/Components/Container/Container.tsx | 10 +++-- src/Components/Login/Login.tsx | 8 +--- .../ProductsPage/BlobView/BlobView.tsx | 37 ++++++++++++++----- .../ProductsPage/TableView/TableView.tsx | 11 ++++-- src/Components/SampleData/SampleData.tsx | 4 +- src/Interfaces/Interfaces.tsx | 6 ++- src/Routes/Product/Product.tsx | 24 ++++++++++++ 8 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 src/Routes/Product/Product.tsx diff --git a/src/App.tsx b/src/App.tsx index 203be88..c0f7fcc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,6 +9,7 @@ import Store from "./Plugins/Redux/Store/Store"; import { Provider } from "react-redux"; import Inventory from "./Routes/Inventory/Inventory"; import Login from "./Routes/Login/Login"; +import Product from "./Routes/Product/Product"; const router = createBrowserRouter([ { @@ -56,6 +57,14 @@ const router = createBrowserRouter([ ), }, + { + path: "/Product/:id", + element: ( + + + + ), + }, ]); export default function App() { diff --git a/src/Components/Container/Container.tsx b/src/Components/Container/Container.tsx index 906ffe1..f9b553b 100644 --- a/src/Components/Container/Container.tsx +++ b/src/Components/Container/Container.tsx @@ -5,7 +5,8 @@ import styles from "../../styles"; import { CheckSavedSession, UserInfo } from "../Api/Api"; import { toggle_login } from "../../Features/Redux/Slices/Login/LoginSlice"; import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; +import { LoginState } from "../../Interfaces/Interfaces"; export interface props { children: React.ReactNode; @@ -13,11 +14,14 @@ export interface props { export default function Container(props: props) { const dispatch = useDispatch(); + const logged_in = useSelector((state: LoginState) => state.logged_in.value); // Function to check for previous login session async function CheckPreviousSession() { if (await CheckSavedSession()) { - await dispatch(toggle_login()); - await dispatch(SetUser(await UserInfo())); + if (logged_in !== true) { + await dispatch(toggle_login()); + await dispatch(SetUser(await UserInfo())); + } } } useEffect(() => { diff --git a/src/Components/Login/Login.tsx b/src/Components/Login/Login.tsx index 0dbcc93..df42ebd 100644 --- a/src/Components/Login/Login.tsx +++ b/src/Components/Login/Login.tsx @@ -4,14 +4,10 @@ import { Button } from "@mui/material"; import styles from "../../styles"; import { useNavigate } from "react-router-dom"; import { LoggedInUserState } from "../../Interfaces/Interfaces"; +import { LoginState } from "../../Interfaces/Interfaces"; -export interface state { - logged_in: { - value: boolean; - }; -} export default function Login() { - const logged_in = useSelector((state: state) => state.logged_in.value); + const logged_in = useSelector((state: LoginState) => state.logged_in.value); const logged_in_user = useSelector( (state: LoggedInUserState) => state.logged_in_user.value ); diff --git a/src/Components/ProductsPage/BlobView/BlobView.tsx b/src/Components/ProductsPage/BlobView/BlobView.tsx index 5eddc30..3050979 100644 --- a/src/Components/ProductsPage/BlobView/BlobView.tsx +++ b/src/Components/ProductsPage/BlobView/BlobView.tsx @@ -3,16 +3,17 @@ import * as React from "react"; import styles from "../../../styles"; import { ProductList } from "../../../Interfaces/Interfaces"; import ProductIcon from "../../Icons/ProductIcon/ProductIcon"; +import { Button } from "@mui/material"; +import { useNavigate } from "react-router-dom"; export default function BlobView({ Products }: ProductList) { + const navigate = useNavigate(); return (
{Products.map((row) => (
-
- {" "} -

{row.name}

-
+
))}
diff --git a/src/Components/ProductsPage/TableView/TableView.tsx b/src/Components/ProductsPage/TableView/TableView.tsx index 5550cc9..ef020ec 100644 --- a/src/Components/ProductsPage/TableView/TableView.tsx +++ b/src/Components/ProductsPage/TableView/TableView.tsx @@ -9,8 +9,10 @@ import { } from "@mui/material"; import styles from "../../../styles"; import { ProductList } from "../../../Interfaces/Interfaces"; +import { useNavigate } from "react-router-dom"; export default function TableView({ Products }: ProductList) { + const navigate = useNavigate(); return ( - Last Modified + Date Added @@ -36,7 +38,10 @@ export default function TableView({ Products }: ProductList) { {Products.map((row) => ( navigate("/Product/" + row.id)} > {row.id} @@ -45,7 +50,7 @@ export default function TableView({ Products }: ProductList) { {row.name} - {row.last_modified} + {row.date_added} ))} diff --git a/src/Components/SampleData/SampleData.tsx b/src/Components/SampleData/SampleData.tsx index 4ceb9ef..d18907a 100644 --- a/src/Components/SampleData/SampleData.tsx +++ b/src/Components/SampleData/SampleData.tsx @@ -2,12 +2,12 @@ export const SampleProducts = [ { id: 1, name: "Zidane's Water", - last_modified: "2/24/2023 10:05AM", + date_added: "2/24/2023 10:05AM", }, { id: 2, name: "Dan's Beefed Corn", - last_modified: "2/25/2023 4:05PM", + date_added: "2/25/2023 4:05PM", }, ]; diff --git a/src/Interfaces/Interfaces.tsx b/src/Interfaces/Interfaces.tsx index e3bf52c..a95cf5e 100644 --- a/src/Interfaces/Interfaces.tsx +++ b/src/Interfaces/Interfaces.tsx @@ -5,12 +5,14 @@ export interface ProductList { export interface Product { id: number; name: string; - last_modified: string; + date_added: string; } // Redux Interfaces export interface LoginState { - Login: { logged_in: boolean }; + logged_in: { + value: boolean; + }; } export interface LoggedInUserState { diff --git a/src/Routes/Product/Product.tsx b/src/Routes/Product/Product.tsx new file mode 100644 index 0000000..fc95a47 --- /dev/null +++ b/src/Routes/Product/Product.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import styles from "../../styles"; +import { Button } from "@mui/material"; +import { useParams } from "react-router-dom"; + +export default function Product() { + let { id } = useParams(); + return ( +
+

+ Individual Product View for id {id} +

+ +
+ ); +}