Skip to content

Commit 144cb42

Browse files
committed
2 parents abd84be + d0eaf54 commit 144cb42

File tree

22 files changed

+505
-139
lines changed

22 files changed

+505
-139
lines changed

client/src/css/AddMenuItem.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,20 @@
7171

7272
#menuadder-form button[type="button"].done-button:hover {
7373
background-color: rgb(231, 74, 74);
74+
}
75+
.help {
76+
display: flex;
77+
z-index: 2;
78+
align-items: center;
79+
justify-content: right;
80+
81+
}
82+
.help-btn {
83+
padding: 5px 10px;
84+
/* margin-top: 10px; */
85+
background-color: rgb(240, 46, 46);
86+
color: white;
87+
border: none;
88+
border-radius: 3px;
89+
cursor: pointer;
7490
}

client/src/css/Home.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040

4141

4242
/* Scroll bar stuff */
43+
::-webkit-scrollbar {
44+
width: 12px;
45+
height: 98%;
46+
border-radius:1rem;
47+
}
4348
/* Track */
4449
::-webkit-scrollbar-track {
4550
background: #f1f1f1;

client/src/css/ad.css

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@
6868
border-color: white;
6969
max-width: 8rem;
7070
max-height: 9rem;
71+
background-color: #e51636;
72+
color: white;
7173

7274
}
7375
.btn-sauce:hover {
74-
background-color: #c1c1c1;
76+
background-color: #940e23;
7577
cursor: pointer;
78+
transition: 0.2s ease;
7679
}
77-
::-webkit-scrollbar {
78-
width: 10px;
79-
height: 98%;
80-
border-radius:1rem;
81-
}
80+
8281

8382

client/src/host.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
/**
2+
3+
The current hostname of the window object
4+
@type {string}
5+
*/
16
const local = window.location.hostname;
7+
8+
/**
9+
10+
The base URL for the API server
11+
@type {string}
12+
*/
213
export const HOST = (local == "localhost") ? "http://localhost:3001" : "https://chick-fil-a-client-71.onrender.com";

client/src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import ReactDOM from "react-dom/client";
33
import "./css/index.css";
44
import App from "./pages/App";
55

6+
/**
7+
8+
The root element of the React application
9+
@type {ReactRoot}
10+
*/
611
const root = ReactDOM.createRoot(document.getElementById("root"));
712
root.render(
813
<React.StrictMode>

client/src/login_comp/login.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@ import { GoogleLogin } from "react-google-login";
33
const client_id =
44
"910012439370-t5574l8cl6b2jsg0n2t4n55dg4cgqp7l.apps.googleusercontent.com";
55

6+
/**
7+
8+
The Login component's UI, which renders a Google login button that can be used to authenticate with the Google API
9+
@function
10+
@returns {JSX.Element} - The Login component's UI
11+
*/
612
function Login() {
713

14+
/**
815
16+
A function that handles the successful authentication of a user via the Google API
17+
@function
18+
@param {Object} res - The response object returned by the Google API after successful authentication
19+
@param {Object} res.profileObj - The user profile object returned by the Google API after successful authentication
20+
*/
921
const onSuccess = (res) => {
1022
console.log("Login success! Curr user: ", res.profileObj);
1123
};
1224

25+
/**
26+
27+
A function that handles the failed authentication of a user via the Google API
28+
@function
29+
@param {Object} res - The response object returned by the Google API after failed authentication
30+
*/
1331
const onFailure = (res) => {
1432
console.log("Login failes! res: ", res);
1533
};

client/src/login_comp/logout.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ import {GoogleLogout} from 'react-google-login';
22

33
const client_id = "910012439370-t5574l8cl6b2jsg0n2t4n55dg4cgqp7l.apps.googleusercontent.com";
44

5+
/**
6+
7+
The Logout component's UI, which renders a Google logout button that can be used to log out of the Google API
8+
@function
9+
@returns {JSX.Element} - The Logout component's UI
10+
*/
511
function Logout(){
612

13+
/**
14+
15+
A function that handles the successful logout of a user via the Google API
16+
@function
17+
@returns {void}
18+
*/
719
const onSuccess = () =>{
820
console.log("Logout successful!");
921
}

client/src/pages/App.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,41 @@ import Header from "../components/Header";
2323
import CashierSauce from "./cashier/CashierSauce";
2424
import { useEffect } from "react";
2525

26+
/**
27+
28+
A React component for the main App
29+
@function
30+
@returns {JSX.Element} - The App component's UI
31+
*/
2632
function App() {
2733

2834

35+
/**
36+
37+
A custom hook that retrieves the user state from local storage and updates it when changed
38+
@function
39+
@param {string} initialValue - The initial value for the user state
40+
@param {string} key - The key used to store the user state in local storage
41+
@returns {Array} - An array containing the user state and a function to update it
42+
*/
2943
const [user, setUser] = useLocalState("", "user");
3044

45+
/**
46+
47+
A function that handles the user sign out event by resetting the user state and redirecting to the home page
48+
@function
49+
*/
3150
function HandleSignOut() {
3251
setUser({});
3352
console.log(user);
3453
window.location.href = "/";
3554
}
3655

56+
/**
57+
58+
A React hook that runs once when the component mounts to the DOM, and logs the current window's hostname to the console
59+
@function
60+
*/
3761
useEffect(() => {
3862
console.log(window.location.hostname);
3963
}, [])

client/src/pages/PrivateRoute/privateCashier.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@ import { useLocalState } from "../util/useLocalStorage";
44
import { useEffect, useState, useMemo } from "react";
55
import { HOST } from "../../host";
66

7+
/**
8+
9+
A React memoized component that wraps the given children in a Private Route that restricts access to authorized users only.
10+
11+
@param {Object} props - Component props.
12+
13+
@param {JSX.Element} props.children - The component(s) to be wrapped in the Private Route.
14+
15+
@returns {JSX.Element} - The Private Route component.
16+
*/
717
const PrivateRouteCashier = React.memo(({ children }) => {
818
const [user, setUser] = useLocalState("", "user");
919
const [isAuthorized, setIsAuthorized] = useState(false);
1020
const [privilege, setPrivilege] = useState(null);
1121
const [shouldRender, setShouldRender] = useState(false);
1222

23+
/**
24+
Sends a POST request to the server to check authorization and returns the response.
25+
@returns {Promise<Object>} - The response from the server.
26+
*/
1327
const make_request = React.useCallback(async () => {
1428
return await fetch(`${HOST}/check-authorization`, {
1529
method: "POST",
@@ -22,6 +36,16 @@ const PrivateRouteCashier = React.memo(({ children }) => {
2236
.then((data) => data);
2337
}, [user]);
2438

39+
/**
40+
41+
Checks the privileges of the user to determine if they are authorized to access the Private Route.
42+
43+
If the user is authorized, it sets the shouldRender state to true.
44+
45+
If the user is not authorized, it sets the shouldRender state to false and redirects to the home page.
46+
47+
@returns {Promise<void>}
48+
*/
2549
const checkPriv = React.useCallback(async () => {
2650
if (user.hasOwnProperty("email")) {
2751
const data = await make_request();

client/src/pages/PrivateRoute/privateManager.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@ import { useLocalState } from "../util/useLocalStorage";
33
import { useEffect, useState } from "react";
44
import { HOST } from "../../host";
55

6+
7+
/**
8+
9+
A higher-order component that renders its children only if the user is authorized as a manager.
10+
11+
@param {Object} props - The component props.
12+
13+
@param {React.ReactNode} props.children - The children to be rendered if the user is authorized.
14+
15+
@return {React.ReactNode} The rendered component or an empty string.
16+
*/
617
const PrivateRouteManager = React.memo(({ children }) => {
718
const [user, setUser] = useLocalState("", "user");
819
const [isAuthorized, setIsAuthorized] = useState(false);
920
const [privilege, setPrivilege] = useState(null);
1021
const [shouldRender, setShouldRender] = useState(false);
1122

23+
/**
24+
Makes a request to the server to check if the user is authorized.
25+
@return {Promise<Object>} A promise that resolves to an object containing authorization data.
26+
*/
1227
const make_request = React.useCallback(async () => {
1328
return await fetch(`${HOST}/check-authorization`, {
1429
method: "POST",
@@ -21,6 +36,13 @@ const PrivateRouteManager = React.memo(({ children }) => {
2136
.then((data) => data);
2237
}, [user]);
2338

39+
/**
40+
Checks if the user is authorized as a manager.
41+
42+
If authorized, sets the shouldRender state to true and renders the children.
43+
44+
If not authorized, sets the shouldRender state to false and redirects the user to the homepage.
45+
*/
2446
const checkPriv = React.useCallback(async () => {
2547
if (user.hasOwnProperty("email")) {
2648
const data = await make_request();
@@ -41,12 +63,10 @@ const PrivateRouteManager = React.memo(({ children }) => {
4163
if (data.isAuthorized && data.privilege === "manager") {
4264
console.log("user found");
4365
// do something here if success
44-
// setShouldRender(true); // not needed
4566
setShouldRender(true);
4667
} else {
4768
console.log("priv failed");
4869
// do something here if it failed
49-
// setShouldRender(false); // not needed
5070
setShouldRender(false);
5171
// since you want to navigate to "/" if the check is false, you can simply do it here
5272
document.location.assign("/");

0 commit comments

Comments
 (0)