Skip to content

Commit

Permalink
Some Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Feb 23, 2024
1 parent 51c6dcb commit 32c8df3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
4 changes: 3 additions & 1 deletion website/src/pages/account/keys/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
56 changes: 36 additions & 20 deletions website/src/pages/admin/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default function Admin(){

const { data: session } = useSession()

const permissionOptions = ["Member", "Editor", "Admin"]

// Stats
const [users, setUsers] = useState([] as RongoaUser[])

Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -175,7 +184,6 @@ export default function Admin(){
<Section autoPadding>
<div className={styles.plantTable}>
<div className={globalStyles.gridCentre}>
<p> Type can be Admin, Member or Editor </p>
<table>
<tr>
<th>ID</th>
Expand All @@ -192,10 +200,18 @@ export default function Admin(){
<td> {user.id} </td>
<td><input id={`name_${user.id}`} defaultValue={user.database.user_name}/></td>
<td><input id={`email_${user.id}`} defaultValue={user.database.user_email}/></td>
<td><input id={`type_${user.id}`} defaultValue={user.database.user_type == 2 ? "Admin" : user.database.user_type == 1 ? "Editor" : "Member"}/></td>
<td>
<select id={`type_${user.id}`}
defaultValue={permissionOptions[user.database.user_type]}>
<option value="Admin">Admin</option>
<option value="Editor">Editor</option>
<option value="Member">Member</option>
</select>
</td>
<td> {user.database.user_restricted_access ? "Yes" : "No"} </td>
<td> {new Date(user.database.user_last_login).toLocaleString()} </td>
<td><button onClick={() => {updateUser(user.database.id)}}>Update</button></td>
<td>
<button onClick={() => {updateUser(user.database.id)}}>Update</button></td>
</tr>
))}
</table>
Expand Down
4 changes: 4 additions & 0 deletions website/src/pages/api/plants/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -79,6 +81,7 @@ export default async function handler(

switch (mushrooms) {
case "include":
console.log("include")
break;

case "exclude":
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions website/src/pages/api/user/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export default async function handler(
response: NextApiResponse,
) {

// Get the origin of the request


// Get the client
const client = await getClient()

Expand Down
3 changes: 2 additions & 1 deletion website/src/pages/api/user/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion website/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 0 additions & 2 deletions website/src/pages/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32c8df3

Please sign in to comment.