From 32c8df34448a8bb15f315cd2f28d1ccdb6939b1b Mon Sep 17 00:00:00 2001 From: Max Tyson <98maxt98@gmail.com> Date: Fri, 23 Feb 2024 22:59:31 +1300 Subject: [PATCH] Some Fixes --- website/src/pages/account/keys/[id].tsx | 4 +- website/src/pages/admin/users.tsx | 56 ++++++++++++++++--------- website/src/pages/api/plants/search.ts | 4 ++ website/src/pages/api/user/delete.ts | 3 -- website/src/pages/api/user/update.ts | 3 +- website/src/pages/index.tsx | 1 - website/src/pages/search.tsx | 2 - 7 files changed, 45 insertions(+), 28 deletions(-) diff --git a/website/src/pages/account/keys/[id].tsx b/website/src/pages/account/keys/[id].tsx index 469e680..dc8ef7e 100644 --- a/website/src/pages/account/keys/[id].tsx +++ b/website/src/pages/account/keys/[id].tsx @@ -43,13 +43,14 @@ export default function KeyViewer(){ let user = urlData[1] // Try to parse the id - let localId = parseInt(id[0]) + let localId = parseInt(urlData[0]) if(isNaN(localId)){ setError("Invalid Key ID") setLoading(false) return } + try { // Create the url let apiUrl = "/api/user/api_keys?operation=fetch" @@ -69,6 +70,7 @@ export default function KeyViewer(){ // Get the data let apikeys = await makeCachedRequest("userApiKeysData_"+user, apiUrl) + console.log(apikeys) if (!apikeys){ setError("Failed to fetch API key data") setLoading(false) diff --git a/website/src/pages/admin/users.tsx b/website/src/pages/admin/users.tsx index dbca260..e8ab98f 100644 --- a/website/src/pages/admin/users.tsx +++ b/website/src/pages/admin/users.tsx @@ -24,6 +24,8 @@ export default function Admin(){ const { data: session } = useSession() + const permissionOptions = ["Member", "Editor", "Admin"] + // Stats const [users, setUsers] = useState([] as RongoaUser[]) @@ -77,6 +79,9 @@ export default function Admin(){ userData[i].database = userData[i] as any; } + // Sort the users by id + userData.sort((a, b) => a.database.id - b.database.id) + setUsers(userData) setLoading(false) } @@ -90,23 +95,13 @@ export default function Admin(){ const name = (document.getElementById(`name_${id}`) as HTMLInputElement).value const email = (document.getElementById(`email_${id}`) as HTMLInputElement).value const type = (document.getElementById(`type_${id}`) as HTMLInputElement).value - let permValue = 0 + let permValue = permissionOptions.indexOf(type) // Check the if correct type - switch (type){ - case "Admin": - permValue = ADMIN_USER_TYPE - break - case "Editor": - permValue = EDITOR_USER_TYPE - break - case "Member": - permValue = MEMBER_USER_TYPE - break - default: - setError("Invalid user type") - setLoading(false) - return + if(permValue === -1){ + setError("Invalid type") + setLoading(false) + return } // Check if name is not empty @@ -138,10 +133,24 @@ export default function Admin(){ // Remove the item in the local storage localStorage.removeItem("user_admin_data") - setLoading(false) + // Reload the page + window.location.reload() } - // TODO: Delete user . ban + const deleteUser = async (id: number) => { + + // Set the loading message + setLoading(true) + setLoadingMessage("Deleting user...") + + // Remove the user + + // Remove the item in the local storage + localStorage.removeItem("user_admin_data") + + // Reload the page + window.location.reload() + } const reload = () => { window.location.reload() @@ -175,7 +184,6 @@ export default function Admin(){
-

Type can be Admin, Member or Editor

@@ -192,10 +200,18 @@ export default function Admin(){ - + - + ))}
ID {user.id} + + {user.database.user_restricted_access ? "Yes" : "No"} {new Date(user.database.user_last_login).toLocaleString()} +
diff --git a/website/src/pages/api/plants/search.ts b/website/src/pages/api/plants/search.ts index 199f3de..b9a3174 100644 --- a/website/src/pages/api/plants/search.ts +++ b/website/src/pages/api/plants/search.ts @@ -60,6 +60,8 @@ export default async function handler( // Select what the user entered if (name) { + + //TODO: Find a better way to include these characters let replaceChars = ["ā", "ē", "ī", "ō", "ū", "Ā", "Ē", "Ī", "Ō", "Ū", "a", "e", "i", "o", "u", "A", "E", "I", "O", "U"] // Replace macrons with wildcard @@ -79,6 +81,7 @@ export default async function handler( switch (mushrooms) { case "include": + console.log("include") break; case "exclude": @@ -109,6 +112,7 @@ export default async function handler( } // Return the plants that match the query + console.log(query) const plantIds = await makeQuery(query, client) // If there are no plants, return an error diff --git a/website/src/pages/api/user/delete.ts b/website/src/pages/api/user/delete.ts index 8e5f87e..2a7603e 100644 --- a/website/src/pages/api/user/delete.ts +++ b/website/src/pages/api/user/delete.ts @@ -11,9 +11,6 @@ export default async function handler( response: NextApiResponse, ) { - // Get the origin of the request - - // Get the client const client = await getClient() diff --git a/website/src/pages/api/user/update.ts b/website/src/pages/api/user/update.ts index f57b8f7..4950c58 100644 --- a/website/src/pages/api/user/update.ts +++ b/website/src/pages/api/user/update.ts @@ -58,7 +58,8 @@ 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.user_type}' WHERE id = ${data.id}`; + query = `UPDATE users SET ${tables.user_name} = '${data.name}', ${tables.user_email} = '${data.email}', ${tables.user_type} = '${data.type}' WHERE id = ${data.id}`; + console.log(query); } const user = await makeQuery(query, client) diff --git a/website/src/pages/index.tsx b/website/src/pages/index.tsx index 9e80002..fbc16d3 100644 --- a/website/src/pages/index.tsx +++ b/website/src/pages/index.tsx @@ -1,5 +1,4 @@ //set PATH=%PATH%;C:\Users\max.tyson\Downloads\node-v21.6.1-win-x64 -// TODO: Fix Mushrooms page (and search potentially) // TODO: Manage Users page import React, {useEffect, useRef} from "react"; diff --git a/website/src/pages/search.tsx b/website/src/pages/search.tsx index 2c0703d..fcd0f0a 100644 --- a/website/src/pages/search.tsx +++ b/website/src/pages/search.tsx @@ -51,8 +51,6 @@ export default function Search(){ const query = urlParams.get('query'); const includeMushrooms = urlParams.get('include_mushrooms'); - console.log(includeMushrooms) - console.log(includeMushrooms == "true") setIncludeMushrooms(includeMushrooms == "true") // Check if the query is null