From a2af9cb173e6d62e7adea2e3554953b78074d4aa Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 1 Sep 2023 10:55:10 -0600 Subject: [PATCH 1/4] new branch + connected to backend --- app/src/assets/search.svg | 4 + app/src/routes/admin.tsx | 359 +++++++++++++++++++++++++++++++++++++- app/src/styles/admin.css | 116 +++++++++++- 3 files changed, 472 insertions(+), 7 deletions(-) create mode 100644 app/src/assets/search.svg diff --git a/app/src/assets/search.svg b/app/src/assets/search.svg new file mode 100644 index 00000000..5d034c64 --- /dev/null +++ b/app/src/assets/search.svg @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/routes/admin.tsx b/app/src/routes/admin.tsx index 41b051f8..b14153a7 100644 --- a/app/src/routes/admin.tsx +++ b/app/src/routes/admin.tsx @@ -1,9 +1,341 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import leaf_icon from "../assets/leaf.svg"; import { MobileView, BrowserView } from "react-device-detect"; import Toolbar from "../admin/toolbar"; +import '../styles/admin.css'; +import leaf_white from "../assets/leaf-white.svg"; +import search_icon from "../assets/search.svg"; +import axios from "axios"; +import { useAuth } from "../contexts/AuthContext"; + + + +function dishStatus(dishNumbers: number[]) { + + return( +
+ +
+ +

{dishNumbers[0]}

+

Currently in use

+
+
+ +

{dishNumbers[1]}

+

Returned

+
+
+ +

{dishNumbers[2]}

+

Overdue

+
+
+ +

{dishNumbers[3]}

+

Broken/lost

+
+ +
+ + ); +} + +function dishTag(text) { + let color = ''; + switch(text) { + case "mug": + color = '#496EA5'; + break; + case "dish": + color = '#496EA5'; + break; + case "overdue": + color = '#BF4949'; + break; + case "in use": + color = '#68B49A'; + break; + case "returned": + color = '#29604D'; + break; + case "broken": + color = '#BF4949' + break; + case "lost": + color = '#BF4949' + break; + } + return( +
+

{text}

+
+ ); +} + +function searchBar() { + return( +
+ +

Type text here...

+
+ ); +} + +function searchButton() { + return( +
+

Search

+
+ ); +} + +function addDish() { + return( +
+

+ Add new dish

+
+ ); +} + +function dishTable() { + return( +
+

Dish ID

+

Dish type

+

Dish Status

+

Overdue

+

Email

+
+ ); +} + +function findEmail(ID, users) { + if (ID == null) { + return('') + } + const user = users.filter(user => user.id == ID); + if (user[0] == undefined) { + return(''); + } + return(user[0].email) +} + +function findDish(ID, dishesUsed) { + if (ID == null) { + return('') + } + const dish = dishesUsed.filter(dish => dish.id == ID); + if (dish[0] == undefined) { + return(null); + } + return(dish) +} + +function findOverdue(dishesUsed, transactionsUsed) { + const transactions = transactionsUsed.filter(transaction => transaction.returned.timestamp == ""); + const timeToday = new Date(); + var num = 0; + transactions.map(transaction => + { + var time = transaction.timestamp.slice(0,10); + time = new Date(time); + var difference = (timeToday.getTime() - time.getTime()) / 86400000; + difference = parseInt(difference.toString()); + if (difference > 2) { + num += 1; + } + }); + return num; +} + +function createRows(dishesUsed, transactionsUsed, users) { + const list: any[] = []; + const timeToday = new Date(); + transactionsUsed.map(transaction => { + let dish = findDish(transaction.dish, dishesUsed); + if (dish == null) { + return []; + } + else { + dish = dish[0]; + } + let id = dish.qid; + let type = dish.type; + let email = findEmail(transaction.userId, users); + var status = ''; + let overdue = ''; + let timestamp = transaction.timestamp + if (transaction.returned.timestamp == "") { + var time = transaction.timestamp.slice(0,10); + time = new Date(time); + var difference = (timeToday.getTime() - time.getTime()) / 86400000; + difference = parseInt(difference.toString()); + if (difference > 2) { + status = 'overdue'; + difference = difference - 2; + overdue = difference.toString()+' days'; + } + else { + status = 'in use'; + } + } + else if (transaction.returned.timestamp != "") { + status = 'returned'; + } + const row = {id: id, type: type, email: email, status: status, overdue: overdue, timestamp: timestamp}; + list.push(row); + }); + return list; +} + +function Rows(tableRows) { + const [currentPage, setCurrentPage] = useState(1); + const recordsPerPage = 6; + const lastIndex = currentPage * recordsPerPage; + const firstIndex = lastIndex - recordsPerPage; + const records = tableRows.slice(firstIndex, lastIndex); + const npage = Math.ceil(tableRows.length / recordsPerPage); + const numbers: number[] = []; + for (let i = 1; i <= npage; i++) { + numbers.push(i); + } + function nextPage() { + if (currentPage !== npage) { + setCurrentPage(currentPage + 1) + } + } + function prePage() { + if (currentPage != 1) { + setCurrentPage(currentPage - 1) + } + } + function changeCPage(id) { + setCurrentPage(id) + } + return( +
+
+ {records.map(row => +
+

{row.id}

+
{dishTag(row.type)}
+

{dishTag(row.status)}

+

{row.overdue}

+

xxxxx1@ualberta.ca

+
+ )} +
+ +
+ + ); +} + +function sortRows(rows) { + const tableRows = rows.sort(function(a, b) { + var aTime = a.timestamp.slice(0,10); + aTime = new Date(aTime); + var bTime = b.timestamp.slice(0,10); + bTime = new Date(bTime); + if (aTime.getTime() < bTime.getTime()) { + return 1; + } + if (aTime.getTime() > bTime.getTime()) { + return -1; + } + return 0; + }); + return tableRows; + +} + +function Admin() { + + const { currentUser, sessionToken } = useAuth(); + const [dishesUsed, setDishesUsed] = useState([]); + const [users, setUsers] = useState([]); + const [transactionsUsed, setTransactionsUsed] = useState([]); + + //get dishes + useEffect(() => { + axios + .get(`${process.env.REACT_APP_BACKEND_ADDRESS}/api/dish`, { + headers: { "x-api-key": `${process.env.REACT_APP_API_KEY}`, "session-token": sessionToken }, + params: {all: true, transaction: true}, + }) + .then(function (response) { + setDishesUsed(response.data.dishes); + }) + .catch(function (error) { + console.log(error); + }); + }, []); + + //get users + useEffect(() => { + axios + .get(`${process.env.REACT_APP_BACKEND_ADDRESS}/api/users`, { + headers: { "x-api-key": `${process.env.REACT_APP_API_KEY}`, "session-token": sessionToken }, + }) + .then(function (response) { + setUsers(response.data.users); + }) + .catch(function (error) { + console.log(error); + }); + }, []); + + //get transactions + useEffect(() => { + axios + .get(`${process.env.REACT_APP_BACKEND_ADDRESS}/api/transactions`, { + headers: { "x-api-key": `${process.env.REACT_APP_API_KEY}`, "session-token": sessionToken }, + params: {all: true}, + }) + .then(function (response) { + setTransactionsUsed(response.data.transactions); + }) + .catch(function (error) { + console.log(error); + }); + }, []); + + + const numBorrowedDishes = dishesUsed.filter(dish => dish.borrowed == true).length; + const returnedDishes = dishesUsed.filter(dish => dish.borrowed == false).length; + const brokenDishes = dishesUsed.filter(dish => dish.condition == 'shattered').length; + const overdue = findOverdue(dishesUsed, transactionsUsed); + + let dishNumbers = [numBorrowedDishes, returnedDishes, overdue, brokenDishes]; + let tableRows = createRows(dishesUsed, transactionsUsed, users); + tableRows = sortRows(tableRows); + let row = Rows(tableRows); + let bar = dishStatus(dishNumbers); + let table = dishTable(); + let search = searchBar(); + let button = searchButton(); + let add = addDish(); -function admin() { return ( <> {/* on mobile */} @@ -11,18 +343,33 @@ function admin() {

Admin Panel

-

You're on mobile! Please go to desktop to view admin panel.

{/* on desktop */} - {/* TODO: implement browser view when user is on desktop */} - +
+ +
+

Home

+ {bar} +

Recent transactions

+ +
+ {search} + {button} +
+ {add} +
+
+ {table} + {row} +
+
); } -export default admin; +export default Admin; diff --git a/app/src/styles/admin.css b/app/src/styles/admin.css index b102d27c..b4a2a90a 100644 --- a/app/src/styles/admin.css +++ b/app/src/styles/admin.css @@ -7,6 +7,7 @@ --modalborder: #c9c9c9; } + .header { /*font-family: Inter;*/ font-size: 35px; @@ -16,6 +17,7 @@ text-align: left; } + .sub-header-2 { /*font-family: Inter;*/ font-size: 20px; @@ -25,6 +27,7 @@ text-align: left; } + .sub-header-4 { /*font-family: Inter;*/ font-size: 16px; @@ -34,6 +37,7 @@ text-align: left; } + .body { /*font-family: Inter;*/ font-size: 16px; @@ -43,6 +47,7 @@ text-align: left; } + .smallest { /*font-family: Inter;*/ font-size: 12px; @@ -52,6 +57,7 @@ text-align: left; } + .details { /*font-family: Inter;*/ font-size: 14px; @@ -61,6 +67,7 @@ text-align: center; } + input[type="radio"] { width: 19px; height: 19px; @@ -69,6 +76,92 @@ input[type="radio"] { margin-top: -4px; } +.pagination { + justify-content: center; + margin-top: 24px; +} + +.admin-container { + border-radius: 10px; + background-color: #E0F4F4; + width: 156px; + height: 118px; + margin-right: 40px; + padding: 16px; + border: 0; + color: black; +} + + +.table-header { + border-top-left-radius: 10px; + border-top-right-radius: 10px; + background-color: #464646; + width: 100%; + height: 56px; + padding: 16px; + border: 0; + color: white; +} + + +.search-container { + border-radius: 30px; + background-color: rgb(255, 255, 255); + width: 206px; + height: 40px; + margin-right: 40px; + border: 1px solid black; + color: #C2C2C2; + padding: 8px; +} + + +.search-b { + border-radius: 30px; + background-color: rgb(255, 255, 255); + width: 138px; + height: 40px; + border: 2px solid #68B49A; + color: #68B49A; + padding: 8px; + justify-content: space-around; +} + + +.add-dish { + border-radius: 30px; + background-color: #68B49A; + width: 213px; + height: 40px; + color: white; + padding: 8px; + justify-content: space-around; + align-self: flex-end; +} + + +.row-container { + width: 100%; + height: 56px; + padding: 16px; + border: 0; + color: black; +} + + +.tag-container { + border-radius: 30px; + background-color: rgb(255, 255, 255); + height: 40px; + border: 2px solid black; + padding: 4px; + padding-left: 20px; + padding-right: 20px; + justify-content: center; +} + + .admin-btn { border-radius: 0; background-color: var(--darkgrey); @@ -78,30 +171,36 @@ input[type="radio"] { text-align: center; } + .admin-btn:hover { background-color: var(--darkgrey); color: black; } + .admin-btn:active { background-color: var(--darkgrey) !important; color: black !important; } + .admin-btn:hover { background-color: darkgrey; color: black; } + .radio-label-group { margin: 8px 0 0 0; } + .add-dish-modal { max-width: none; width: 626px; } + .add-dish-modal .modal-content { height: 595px; border-radius: 0; @@ -110,20 +209,24 @@ input[type="radio"] { border-color: var(--modalborder); } + .add-dish-modal .modal-header { border-bottom: none; padding: 0; } + .add-dish-modal .modal-body { padding: 25px 33px 0 0; align-content: flex-start; } + .modal-title { height: 85px !important; } + .qr-input { border: 0; padding: 5px; @@ -131,10 +234,13 @@ input[type="radio"] { } + + /* * Sidebar */ + .sidebar { background-color: #464646; top: 0; @@ -148,17 +254,21 @@ input[type="radio"] { } + + @media (max-width: 767.98px) { .sidebar { top: 5rem; } } + .sidebar-icon { height: 16px; padding-right: 10px; } + .sidebar-sticky { height: 100vh; overflow-x: hidden; @@ -168,15 +278,18 @@ input[type="radio"] { color: white } + .sidebarNavLink { font-weight: 500; color: #333; } + .sidebar-heading { font-size: small; } + .nav-link { text-decoration: none; color: white; @@ -184,7 +297,8 @@ input[type="radio"] { font-size: large; } + a.nav-link:hover { color: white; background: #5E5E5E; -} \ No newline at end of file +} From 56b94778607919e8fc7c6a5c2e2f4049f1b32008 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 25 Sep 2023 02:44:02 -0600 Subject: [PATCH 2/4] fixed getting emails and search bar --- app/src/routes/admin.tsx | 100 ++++++++++++++++++--------------------- app/src/styles/admin.css | 1 - 2 files changed, 47 insertions(+), 54 deletions(-) diff --git a/app/src/routes/admin.tsx b/app/src/routes/admin.tsx index b14153a7..68553f5d 100644 --- a/app/src/routes/admin.tsx +++ b/app/src/routes/admin.tsx @@ -4,7 +4,6 @@ import { MobileView, BrowserView } from "react-device-detect"; import Toolbar from "../admin/toolbar"; import '../styles/admin.css'; import leaf_white from "../assets/leaf-white.svg"; -import search_icon from "../assets/search.svg"; import axios from "axios"; import { useAuth } from "../contexts/AuthContext"; @@ -73,23 +72,6 @@ function dishTag(text) { ); } -function searchBar() { - return( -
- -

Type text here...

-
- ); -} - -function searchButton() { - return( -
-

Search

-
- ); -} - function addDish() { return(
@@ -110,16 +92,7 @@ function dishTable() { ); } -function findEmail(ID, users) { - if (ID == null) { - return('') - } - const user = users.filter(user => user.id == ID); - if (user[0] == undefined) { - return(''); - } - return(user[0].email) -} + function findDish(ID, dishesUsed) { if (ID == null) { @@ -149,7 +122,7 @@ function findOverdue(dishesUsed, transactionsUsed) { return num; } -function createRows(dishesUsed, transactionsUsed, users) { +function createRows(dishesUsed, transactionsUsed) { const list: any[] = []; const timeToday = new Date(); transactionsUsed.map(transaction => { @@ -162,7 +135,7 @@ function createRows(dishesUsed, transactionsUsed, users) { } let id = dish.qid; let type = dish.type; - let email = findEmail(transaction.userId, users); + let email = transaction.user.email; var status = ''; let overdue = ''; let timestamp = transaction.timestamp @@ -189,7 +162,17 @@ function createRows(dishesUsed, transactionsUsed, users) { return list; } -function Rows(tableRows) { +function Rows(tableRows, search) { + + function searchFilter(item) { + return item.id == search + } + + if (search.length > 0) { + const rows = tableRows.filter(searchFilter) + tableRows = rows; + } + const [currentPage, setCurrentPage] = useState(1); const recordsPerPage = 6; const lastIndex = currentPage * recordsPerPage; @@ -197,6 +180,7 @@ function Rows(tableRows) { const records = tableRows.slice(firstIndex, lastIndex); const npage = Math.ceil(tableRows.length / recordsPerPage); const numbers: number[] = []; + for (let i = 1; i <= npage; i++) { numbers.push(i); } @@ -222,7 +206,7 @@ function Rows(tableRows) {
{dishTag(row.type)}

{dishTag(row.status)}

{row.overdue}

-

xxxxx1@ualberta.ca

+

{row.email}

)} @@ -273,8 +257,10 @@ function Admin() { const { currentUser, sessionToken } = useAuth(); const [dishesUsed, setDishesUsed] = useState([]); - const [users, setUsers] = useState([]); const [transactionsUsed, setTransactionsUsed] = useState([]); + const [searchInput, setSearchInput] = useState(""); + const [searchValue, setSearchValue] = useState(""); + console.log(searchInput) //get dishes useEffect(() => { @@ -291,20 +277,7 @@ function Admin() { }); }, []); - //get users - useEffect(() => { - axios - .get(`${process.env.REACT_APP_BACKEND_ADDRESS}/api/users`, { - headers: { "x-api-key": `${process.env.REACT_APP_API_KEY}`, "session-token": sessionToken }, - }) - .then(function (response) { - setUsers(response.data.users); - }) - .catch(function (error) { - console.log(error); - }); - }, []); - + //get transactions useEffect(() => { axios @@ -313,6 +286,7 @@ function Admin() { params: {all: true}, }) .then(function (response) { + console.log(response.data.transactions) setTransactionsUsed(response.data.transactions); }) .catch(function (error) { @@ -320,6 +294,14 @@ function Admin() { }); }, []); + const searchChange = (value) => { + value.preventDefault(); + setSearchInput(value.target.value); + }; + + const handleClick = () => { + setSearchValue(searchInput) + } const numBorrowedDishes = dishesUsed.filter(dish => dish.borrowed == true).length; const returnedDishes = dishesUsed.filter(dish => dish.borrowed == false).length; @@ -327,15 +309,14 @@ function Admin() { const overdue = findOverdue(dishesUsed, transactionsUsed); let dishNumbers = [numBorrowedDishes, returnedDishes, overdue, brokenDishes]; - let tableRows = createRows(dishesUsed, transactionsUsed, users); + let tableRows = createRows(dishesUsed, transactionsUsed); tableRows = sortRows(tableRows); - let row = Rows(tableRows); + let row = Rows(tableRows, searchValue); let bar = dishStatus(dishNumbers); let table = dishTable(); - let search = searchBar(); - let button = searchButton(); let add = addDish(); + return ( <> {/* on mobile */} @@ -357,8 +338,21 @@ function Admin() {

Recent transactions

- {search} - {button} + + {/* search Bar */} + + + + +
{add}
diff --git a/app/src/styles/admin.css b/app/src/styles/admin.css index b4a2a90a..0f073f78 100644 --- a/app/src/styles/admin.css +++ b/app/src/styles/admin.css @@ -92,7 +92,6 @@ input[type="radio"] { color: black; } - .table-header { border-top-left-radius: 10px; border-top-right-radius: 10px; From b9a39a1b8b75f093e0d7fba2b2ef29d62cc4f588 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 28 Sep 2023 21:45:46 -0600 Subject: [PATCH 3/4] fixed bugs --- app/src/routes/admin.tsx | 58 +++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/app/src/routes/admin.tsx b/app/src/routes/admin.tsx index 68553f5d..cc6b9be9 100644 --- a/app/src/routes/admin.tsx +++ b/app/src/routes/admin.tsx @@ -22,7 +22,7 @@ function dishStatus(dishNumbers: number[]) {

{dishNumbers[1]}

-

Returned

+

Available

@@ -32,7 +32,7 @@ function dishStatus(dishNumbers: number[]) {

{dishNumbers[3]}

-

Broken/lost

+

Dishes Lost

@@ -122,6 +122,23 @@ function findOverdue(dishesUsed, transactionsUsed) { return num; } +function findLost(dishesUsed, transactionsUsed) { + const transactions = transactionsUsed.filter(transaction => transaction.returned.timestamp == ""); + const timeToday = new Date(); + var num = 0; + transactions.map(transaction => + { + var time = transaction.timestamp.slice(0,10); + time = new Date(time); + var difference = (timeToday.getTime() - time.getTime()) / 86400000; + difference = parseInt(difference.toString()); + if (difference >=30) { + num += 1; + } + }); + return num; +} + function createRows(dishesUsed, transactionsUsed) { const list: any[] = []; const timeToday = new Date(); @@ -135,19 +152,35 @@ function createRows(dishesUsed, transactionsUsed) { } let id = dish.qid; let type = dish.type; - let email = transaction.user.email; + let email = ''; + if(transaction.user == undefined) { + email = 'NULL'; + } + else { + email = transaction.user.email; + } + let lost = ''; var status = ''; let overdue = ''; - let timestamp = transaction.timestamp + var timestamp; + if (transaction.returned.timestamp != '') { + timestamp = transaction.returned.timestamp; + } + else { + timestamp = transaction.timestamp; + } if (transaction.returned.timestamp == "") { var time = transaction.timestamp.slice(0,10); time = new Date(time); var difference = (timeToday.getTime() - time.getTime()) / 86400000; difference = parseInt(difference.toString()); - if (difference > 2) { + if (difference >= 30) { + status = 'lost' + } + else if (difference > 2) { status = 'overdue'; difference = difference - 2; - overdue = difference.toString()+' days'; + overdue = difference.toString()+' day(s)'; } else { status = 'in use'; @@ -237,9 +270,10 @@ function Rows(tableRows, search) { function sortRows(rows) { const tableRows = rows.sort(function(a, b) { - var aTime = a.timestamp.slice(0,10); + + let aTime = a.timestamp.slice(0,19); aTime = new Date(aTime); - var bTime = b.timestamp.slice(0,10); + let bTime = b.timestamp.slice(0,19); bTime = new Date(bTime); if (aTime.getTime() < bTime.getTime()) { return 1; @@ -260,7 +294,6 @@ function Admin() { const [transactionsUsed, setTransactionsUsed] = useState([]); const [searchInput, setSearchInput] = useState(""); const [searchValue, setSearchValue] = useState(""); - console.log(searchInput) //get dishes useEffect(() => { @@ -286,7 +319,6 @@ function Admin() { params: {all: true}, }) .then(function (response) { - console.log(response.data.transactions) setTransactionsUsed(response.data.transactions); }) .catch(function (error) { @@ -305,10 +337,10 @@ function Admin() { const numBorrowedDishes = dishesUsed.filter(dish => dish.borrowed == true).length; const returnedDishes = dishesUsed.filter(dish => dish.borrowed == false).length; - const brokenDishes = dishesUsed.filter(dish => dish.condition == 'shattered').length; - const overdue = findOverdue(dishesUsed, transactionsUsed); + const lost = findLost(dishesUsed, transactionsUsed); + const overdue = findOverdue(dishesUsed, transactionsUsed) - lost; - let dishNumbers = [numBorrowedDishes, returnedDishes, overdue, brokenDishes]; + let dishNumbers = [numBorrowedDishes, returnedDishes, overdue, lost]; let tableRows = createRows(dishesUsed, transactionsUsed); tableRows = sortRows(tableRows); let row = Rows(tableRows, searchValue); From 0015d5bc65e0f4d16d6f24e46e64ab0d2dd77aef Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 29 Sep 2023 20:07:53 -0600 Subject: [PATCH 4/4] fixed errors --- app/src/routes/admin.tsx | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/routes/admin.tsx b/app/src/routes/admin.tsx index cc6b9be9..db354b7f 100644 --- a/app/src/routes/admin.tsx +++ b/app/src/routes/admin.tsx @@ -108,12 +108,12 @@ function findDish(ID, dishesUsed) { function findOverdue(dishesUsed, transactionsUsed) { const transactions = transactionsUsed.filter(transaction => transaction.returned.timestamp == ""); const timeToday = new Date(); - var num = 0; + let num = 0; transactions.map(transaction => { - var time = transaction.timestamp.slice(0,10); + let time = transaction.timestamp.slice(0,10); time = new Date(time); - var difference = (timeToday.getTime() - time.getTime()) / 86400000; + let difference = (timeToday.getTime() - time.getTime()) / 86400000; difference = parseInt(difference.toString()); if (difference > 2) { num += 1; @@ -125,12 +125,12 @@ function findOverdue(dishesUsed, transactionsUsed) { function findLost(dishesUsed, transactionsUsed) { const transactions = transactionsUsed.filter(transaction => transaction.returned.timestamp == ""); const timeToday = new Date(); - var num = 0; + let num = 0; transactions.map(transaction => { - var time = transaction.timestamp.slice(0,10); + let time = transaction.timestamp.slice(0,10); time = new Date(time); - var difference = (timeToday.getTime() - time.getTime()) / 86400000; + let difference = (timeToday.getTime() - time.getTime()) / 86400000; difference = parseInt(difference.toString()); if (difference >=30) { num += 1; @@ -150,8 +150,8 @@ function createRows(dishesUsed, transactionsUsed) { else { dish = dish[0]; } - let id = dish.qid; - let type = dish.type; + const id = dish.qid; + const type = dish.type; let email = ''; if(transaction.user == undefined) { email = 'NULL'; @@ -159,10 +159,9 @@ function createRows(dishesUsed, transactionsUsed) { else { email = transaction.user.email; } - let lost = ''; - var status = ''; + let status = ''; let overdue = ''; - var timestamp; + let timestamp; if (transaction.returned.timestamp != '') { timestamp = transaction.returned.timestamp; } @@ -170,9 +169,9 @@ function createRows(dishesUsed, transactionsUsed) { timestamp = transaction.timestamp; } if (transaction.returned.timestamp == "") { - var time = transaction.timestamp.slice(0,10); + let time = transaction.timestamp.slice(0,10); time = new Date(time); - var difference = (timeToday.getTime() - time.getTime()) / 86400000; + let difference = (timeToday.getTime() - time.getTime()) / 86400000; difference = parseInt(difference.toString()); if (difference >= 30) { status = 'lost' @@ -340,13 +339,13 @@ function Admin() { const lost = findLost(dishesUsed, transactionsUsed); const overdue = findOverdue(dishesUsed, transactionsUsed) - lost; - let dishNumbers = [numBorrowedDishes, returnedDishes, overdue, lost]; + const dishNumbers = [numBorrowedDishes, returnedDishes, overdue, lost]; let tableRows = createRows(dishesUsed, transactionsUsed); tableRows = sortRows(tableRows); - let row = Rows(tableRows, searchValue); - let bar = dishStatus(dishNumbers); - let table = dishTable(); - let add = addDish(); + const row = Rows(tableRows, searchValue); + const bar = dishStatus(dishNumbers); + const table = dishTable(); + const add = addDish(); return (