diff --git a/website/src/components/accessibility.tsx b/website/src/components/accessibility.tsx index c595db1..1559e5d 100644 --- a/website/src/components/accessibility.tsx +++ b/website/src/components/accessibility.tsx @@ -24,7 +24,7 @@ export function ToggleAccessibilitySetting({setting, setter}: ToggleAccessibilit * @returns {boolean} - The accessibility setting */ const loader = () => { - let loadedMode = localStorage.getItem(setting) + let loadedMode = sessionStorage.getItem(setting) let mode = false // If the mode is loaded as true, otherwise it must be false or incorrect @@ -50,7 +50,7 @@ export function ToggleAccessibilitySetting({setting, setter}: ToggleAccessibilit toggleRef.current!.checked = newMode // Save the mode - localStorage.setItem(setting, newMode.toString()) + sessionStorage.setItem(setting, newMode.toString()) // Update the state setter(newMode) diff --git a/website/src/lib/cache.ts b/website/src/lib/cache.ts index e4a5e21..0bfeac8 100644 --- a/website/src/lib/cache.ts +++ b/website/src/lib/cache.ts @@ -4,7 +4,7 @@ interface CacheItem { } /** - * Will try to get an item from the localstorage, if the item is expired, it will be removed from the local storage + * Will try to get an item from the sessionStorage, if the item is expired, it will be removed from the local storage * * @param {string} id - The key used to store the item in the local storage * @@ -15,7 +15,7 @@ interface CacheItem { export function getFromCache(id: string){ let item = null; - item = localStorage.getItem(id); + item = sessionStorage.getItem(id); // Check if the item exists in the local storage if(item){ @@ -29,7 +29,7 @@ export function getFromCache(id: string){ console.log("Cache item [" + id + "] has expired"); // If it has expired, remove it from the local storage - localStorage.removeItem(id); + sessionStorage.removeItem(id); // Return null return null; @@ -60,6 +60,6 @@ export function saveToCache(id: string, data: any){ } // Save the cache item to the local storage - localStorage.setItem(id, JSON.stringify(cacheItem)); + sessionStorage.setItem(id, JSON.stringify(cacheItem)); } \ No newline at end of file diff --git a/website/src/pages/account/index.tsx b/website/src/pages/account/index.tsx index b764864..4d9c0d2 100644 --- a/website/src/pages/account/index.tsx +++ b/website/src/pages/account/index.tsx @@ -269,7 +269,7 @@ export function AccountPage({dataID}: AccountPageProps){ const signOutUser = async () => { // Clear the cache - localStorage.clear() + sessionStorage.clear() await signOut({callbackUrl: "/"}) } @@ -486,6 +486,12 @@ export function AccountPage({dataID}: AccountPageProps){
+
+
+
+
+
+
diff --git a/website/src/pages/account/keys/[id].tsx b/website/src/pages/account/keys/[id].tsx index 8146c05..78cfe2a 100644 --- a/website/src/pages/account/keys/[id].tsx +++ b/website/src/pages/account/keys/[id].tsx @@ -143,7 +143,7 @@ export default function KeyViewer(){ setLoading("Refreshing...") // Clear the local cache - localStorage.removeItem("userApiKeysData_"+userApiKeyData.user_id) + sessionStorage.removeItem("userApiKeysData_"+userApiKeyData.user_id) // Get the key data await getKeyData(router.query.id as string) diff --git a/website/src/pages/account/keys/create.tsx b/website/src/pages/account/keys/create.tsx index 5480eab..5686022 100644 --- a/website/src/pages/account/keys/create.tsx +++ b/website/src/pages/account/keys/create.tsx @@ -142,7 +142,7 @@ export function AccountPage({dataID}: AccountPageProps){ } // Delete the cached user keys - localStorage.removeItem("userApiKeysData_0") + sessionStorage.removeItem("userApiKeysData_0") setLoading(false) // Go to the account page diff --git a/website/src/pages/admin/users.tsx b/website/src/pages/admin/users.tsx index 11ca247..8dc8fa8 100644 --- a/website/src/pages/admin/users.tsx +++ b/website/src/pages/admin/users.tsx @@ -9,6 +9,8 @@ import {globalStyles} from "@/lib/global_css"; import { useLogger } from 'next-axiom'; import Table from "@/components/table"; import {Layout} from "@/components/layout"; +import {useRouter} from "next/router"; +import {getNamesInPreference} from "@/lib/plant_data"; export default function Admin(){ const pageName = "Admin"; @@ -20,7 +22,7 @@ export default function Admin(){ // Stats const [users, setUsers] = useState([] as RongoaUser[]) - const [sortedField, setSortedField] = useState("id") + const router = useRouter() // Load the data const [loadingMessage, setLoadingMessage] = useState("") @@ -37,7 +39,7 @@ export default function Admin(){ dataFetch.current = true fetchData() - }, [session]) + }) const fetchData = async () => { @@ -52,13 +54,10 @@ export default function Admin(){ // Set the users let userData = users as RongoaUser[] - for(let i = 0; i < userData.length; i++){ + for(let i = 0; i < userData.length; i++) userData[i].database = userData[i] as any; - } - - // Sort the users by id - userData.sort((a, b) => a.database.id - b.database.id) + console.log(userData) setUsers(userData) setLoadingMessage("") } @@ -71,6 +70,7 @@ export default function Admin(){ const name = (document.getElementById(`name_${id}`) as HTMLElement).innerText const email = (document.getElementById(`email_${id}`) as HTMLElement).innerText const type = (document.getElementById(`type_${id}`) as HTMLInputElement).value + const restricted = (document.getElementById(`restricted_${id}`) as HTMLInputElement).value let permValue = permissionOptions.indexOf(type) // Check the if correct type @@ -98,7 +98,8 @@ export default function Admin(){ id: id, name: name, email: email, - type: permValue + type: permValue, + restricted: restricted === "Yes" } await makeRequestWithToken("get", "/api/user/update?adminData=" + JSON.stringify(adminData)) @@ -110,7 +111,7 @@ export default function Admin(){ sessionStorage.removeItem("user_admin_data") // Reload the page - window.location.reload() + await router.push("/admin/") } const deleteUser = async (id: number) => { @@ -125,39 +126,13 @@ export default function Admin(){ sessionStorage.removeItem("user_admin_data") // Reload the page - window.location.reload() + await router.push("/admin/") } const reload = () => { window.location.reload() } - useEffect(() => { - - // Sort the array based on the field - switch (sortedField) { - case "id": - users.sort((a, b) => a.database.id - b.database.id) - break - - case "name": - users.sort((a, b) => a.database.user_name.localeCompare(b.database.user_name)) - break - - case "email": - users.sort((a, b) => a.database.user_email.localeCompare(b.database.user_email)) - break - - case "type": - users.sort((a, b) => a.database.user_type - b.database.user_type) - break - - case "last_login": - users.sort((a, b) => new Date(a.database.user_last_login).getTime() - new Date(b.database.user_last_login).getTime()) - break - } - }, [sortedField]); - return ( <> @@ -184,38 +159,62 @@ export default function Admin(){
- - - - - - - - - - - - {users.map((user, index) => ( - - - - - - - - - + + + + + + + + + + - ))} + + + + {users.map((user, index) => ( + + + + + + + + + + + ))} +
{setSortedField("id")}}>ID {setSortedField("name")}}>Name {setSortedField("email")}}>Email {setSortedField("type")}}>Type {setSortedField("restricted")}}>Restricted Access {setSortedField("last_login")}}>Last LoginUpdateRemove
{user.id}

{user.database.user_name}

{user.database.user_email}

- - {user.database.user_restricted_access ? "Yes" : "No"} {new Date(user.database.user_last_login).toLocaleString()}
IDNameEmailTypeRestricted AccessLast LoginUpdateRemove
{user.id}

{user.database.user_name}

{user.database.user_email}

+ + + + {new Date(user.database.user_last_login).toLocaleString()}
+ + + {/* New User */} +
+
+
+
+ todo +

New User

+ + + +
+
+
+
) diff --git a/website/src/pages/api/user/update.ts b/website/src/pages/api/user/update.ts index 4950c58..84f19d0 100644 --- a/website/src/pages/api/user/update.ts +++ b/website/src/pages/api/user/update.ts @@ -58,7 +58,7 @@ export default async function handler( } let data = JSON.parse(adminData as any); - query = `UPDATE users SET ${tables.user_name} = '${data.name}', ${tables.user_email} = '${data.email}', ${tables.user_type} = '${data.type}' WHERE id = ${data.id}`; + query = `UPDATE users SET ${tables.user_name} = '${data.name}', ${tables.user_email} = '${data.email}', ${tables.user_type} = '${data.type}', ${tables.user_restricted_access} = ${data.restricted} WHERE id = ${data.id}`; console.log(query); } diff --git a/website/src/pages/plants/create.tsx b/website/src/pages/plants/create.tsx index d4b6d4a..af27e31 100644 --- a/website/src/pages/plants/create.tsx +++ b/website/src/pages/plants/create.tsx @@ -2431,7 +2431,7 @@ export default function CreatePlant() { } // Remove the plant from the local storage - localStorage.removeItem("plant_" + idNum) + sessionStorage.removeItem("plant_" + idNum) // Add the id to the upload data console.log("SETTING ID") diff --git a/website/src/styles/pages/account/index.module.css b/website/src/styles/pages/account/index.module.css index 9d84498..0e5ad88 100644 --- a/website/src/styles/pages/account/index.module.css +++ b/website/src/styles/pages/account/index.module.css @@ -104,6 +104,7 @@ .deleteAccountButton{ background-color: red; + scale: 75%; } .signInButton{