From 45c2e1bda332e13fc0971139f59ae1a5269d1d43 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:50:01 -0400 Subject: [PATCH] Create stat reduction modal --- components/GameAppealCard.tsx | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/components/GameAppealCard.tsx b/components/GameAppealCard.tsx index f47665d..17e8b59 100644 --- a/components/GameAppealCard.tsx +++ b/components/GameAppealCard.tsx @@ -6,12 +6,55 @@ import { CardFooter, CardHeader, Heading, + Input, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, Stack, StackDivider, Text, + useDisclosure, + useToast, } from "@chakra-ui/react"; export default function (props: GameAppealProps) { + async function performAction(action: "accept" | "deny"): Promise { + const statsReduction = parseInt( + (document.getElementById("reductPercentage") as HTMLInputElement).value + ); + + const actionResponse = await fetch(`/api/game-appeals/${props.roblox_id}`, { + body: JSON.stringify({ + statsReduction: isNaN(statsReduction) ? 0 : statsReduction, + }), + headers: { + "content-type": "application/json", + }, + method: "POST", + }); + + useToast()( + actionResponse.ok + ? { + duration: 5000, + status: "success", + title: `Appeal ${action === "accept" ? "accepted" : "denied"}`, + } + : { + description: `${ + ((await actionResponse.json()) as { error: string }).error + }`, + duration: 10000, + status: "error", + title: "An error occurred...", + } + ); + } + + const { isOpen, onClose, onOpen } = useDisclosure(); + return ( @@ -38,6 +81,39 @@ export default function (props: GameAppealProps) { + + + + + How much should this player's stats be reduced by? + + + + { + const value = (e.target as EventTarget & { value: string }) + .value; + + return !value.match(/\D/); + }} + placeholder="Number between 0 and 100" + /> + + + + + + + ); }