Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Actually add user on click
  • Loading branch information
regalijan committed Nov 8, 2023
1 parent d2b5de1 commit 229facb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion components/GameModManagementModal.tsx
Expand Up @@ -22,6 +22,7 @@ import { useEffect, useState } from "react";

export default function (props: { isOpen: boolean; onClose: () => void }) {
const [mods, setMods] = useState([]);
const [userToAdd, setUserToAdd] = useState("");
const toast = useToast();

useEffect(() => {
Expand All @@ -45,6 +46,16 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
}, [props.isOpen]);

async function addUser(user: string) {
if (!user || !user.match(/^\d{17,19}$/)) {
toast({
description: "Please check your input and try again",
status: "error",
title: "Invalid user",
});

return;
}

const addResp = await fetch("/api/gme/add", {
body: JSON.stringify({ user }),
headers: {
Expand Down Expand Up @@ -133,7 +144,9 @@ export default function (props: { isOpen: boolean; onClose: () => void }) {
</TableContainer>
<HStack mt="8px">
<Input maxLength={19} placeholder="1234567890987654321" />
<Button ml="8px">Add</Button>
<Button ml="8px" onClick={async () => await addUser(userToAdd)}>
Add
</Button>
</HStack>
</ModalBody>
</ModalContent>
Expand Down

0 comments on commit 229facb

Please sign in to comment.