Skip to content

Commit

Permalink
Frontend tasklist page (#19)
Browse files Browse the repository at this point in the history
* Set up the route. Using default figma style for the tasklist page.

* use bootstrap components

* finish tasklist page v1

* Finished Navbar, customized buttons/link, added routes

* updated index.css to include cust colours and changed Navbar to be reusable between o and c

* changed Navbar border to support customer page

* Update Navbar to support pages without title

* unfinished store

* clean up

* matching package-clock configurations with the main branch

---------

Co-authored-by: UBC Student <[email protected]>
Co-authored-by: sl-81 <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent 2f164f2 commit 1c115af
Show file tree
Hide file tree
Showing 9 changed files with 706 additions and 129 deletions.
350 changes: 335 additions & 15 deletions frontend/package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
"preview": "vite preview"
},
"dependencies": {
"@reduxjs/toolkit": "^2.2.1",
"bootstrap": "^5.3.3",
"react": "^18.2.0",
"react-bootstrap": "^2.10.1",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.2"
"react-router-dom": "^6.22.2",
"react-redux": "^9.1.0"
},
"devDependencies": {
"@types/react": "^18.2.43",
Expand Down
252 changes: 147 additions & 105 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,113 +1,155 @@
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { BrowserRouter as Router, Routes, Route, Navigate } from "react-router-dom";
import "./index.css";
import Navbar from "./components/Navbar";
import ShoppingList from "./components/ShoppingList";
import Tasklist from "./components/tasklist";
import { configureStore } from '@reduxjs/toolkit'
import userSlice from './redux/user.tsx'
import React, { FC, ReactElement } from 'react'
import { Provider } from 'react-redux';

/**
* Store
*/
const store = configureStore({
reducer:{
user: userSlice
}
});

export type IRootState = ReturnType<typeof store.getState>

/**
* Routes
*/
export interface Props {
className?: string;
childElement?: ReactElement;
}

const PrivateRoute: FC<Props> =
({childElement}: Props) => {
//TODO:
//const isloggedInKey:string = useSelector((state:IRootState) => state.user.isLoggedInKey);
//const isloggedIn = localStorage.getItem(isloggedInKey) === "true";
const isloggedIn = true;
return isloggedIn
? (<>{childElement}</>)
: (<Navigate replace={false} to={'/officer'}/>)
}

const App = () => {
return (
<Router>
<Routes>
<Route path="/" element={<ShoppingList />} />
<Route
path="/store"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={false}
needtitle={true}
/>
}
/>
<Route
path="/officer"
element={
<Navbar
title="Login"
needbuttons={false}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/mainmenu"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/itemdetail/:id"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/reimburse"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/inventory"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/shoppinglist"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/additem"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/transaction"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
</Routes>
</Router>
<React.StrictMode>
<Provider store={store}>
<Router>
<Routes>
<Route path="/" element={<ShoppingList />} />
<Route
path="/store"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={false}
needtitle={true}
/>
}
/>
<Route
path="/officer"
element={
<Navbar
title="Login"
needbuttons={false}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/mainmenu"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/itemdetail/:id"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/reimburse"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/inventory"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/shoppinglist"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/additem"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route
path="/officer/transaction"
element={
<Navbar
title="Login"
needbuttons={true}
isofficerpage={true}
needtitle={true}
/>
}
/>
<Route path="/officer/tasklist" element={<PrivateRoute childElement={<Tasklist/>}/>}
/>
</Routes>
</Router>
</Provider>
</React.StrictMode>
);
};

Expand Down
52 changes: 52 additions & 0 deletions frontend/src/components/tasklist.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { FC } from 'react';
import '../styles/tasklist.css';
import { Button, Stack } from 'react-bootstrap';
import { useDispatch } from 'react-redux';
import { setIsLoggedInFalse } from '../redux/user';
import {Props} from '../App.tsx'


export const Tasklist: FC<Props> = (function Screen() {

const dispatch = useDispatch();

const handleLogout = () => {
dispatch(setIsLoggedInFalse(""));
};

return (
<div className='background'>
<Stack gap={3} className='tasklist'>
<div className="text-fff-48px-OpenSans manageInventory">Manage Inventory</div>
<div className="viewUpdateInventory">
<Button className='button-d9c4e3-24px-OpenSans' type="button" aria-pressed="true" >
<a href='./'>View/Update Inventory</a>
</Button>
</div>
<div className="getShoppingList">
<Button className='button-d9c4e3-24px-OpenSans' type="button" aria-pressed="true">
<a href='./'>Get Shopping List</a>
</Button>
</div>
<div className="text-fff-48px-OpenSans finance">Finance</div>
<div className="transactionHistory">
<Button className='button-d9c4e3-24px-OpenSans' type="button" aria-pressed="true">
<a href='./'>Transaction History</a>
</Button>
</div>
<div className="reimbursementRequest">
<Button className='button-d9c4e3-24px-OpenSans' type="button" aria-pressed="true">
<a href='./'>Reimbursement Request</a>
</Button>
</div>
<div className="logout">
<Button className='button-d9c4e3-24px-OpenSans' type="button" aria-pressed="true" onClick={handleLogout}>
<a href='./'>Logout</a>
</Button>
</div>
</Stack>
</div>
);
});

export default Tasklist;
15 changes: 8 additions & 7 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'


ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
<App />
</React.StrictMode>,
)
38 changes: 38 additions & 0 deletions frontend/src/redux/user.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createSlice } from "@reduxjs/toolkit"

export type UserType = {
user: string | null,
isLoggedIn: boolean;
isLoggedInKey: string;
}

const initialState : UserType = {
user: localStorage.getItem('user'),
//TODO: isLoggedIn: 'user' in localStorage,
isLoggedIn: true,
isLoggedInKey: "isLoggedIn"
}


const userSlice = createSlice({
name: "user",
initialState,
reducers: {
setIsLoggedInTrue (state, action) {
action.payload;
state.isLoggedIn = true;
//TODO: localStorage.setItem("user.isLoggedIn", 'true');
},

setIsLoggedInFalse (state, action) {
action.payload;
state.isLoggedIn = false;
//TODO: localStorage.setItem("user.isLoggedIn", 'false');
}
}
});

export const {setIsLoggedInTrue, setIsLoggedInFalse} = userSlice.actions;

export default userSlice.reducer;

Loading

0 comments on commit 1c115af

Please sign in to comment.