Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use state instead of getElementById
  • Loading branch information
regalijan committed Oct 20, 2023
1 parent ea1f54f commit c609ab4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions components/GameAppealCard.tsx
Expand Up @@ -22,19 +22,16 @@ import { useState } from "react";

export default function (props: GameAppealProps) {
const [loading, setLoading] = useState(false);
const [percentage, setPercentage] = useState(0);

async function performAction(action: "accept" | "deny"): Promise<void> {
setLoading(true);
const statsReduction = parseInt(
(document.getElementById("reductPercentage") as HTMLInputElement | null)
?.value ?? "0",
);

const actionResponse = await fetch(
`/api/game-appeals/${props.id}/${action}`,
{
body: JSON.stringify({
statsReduction: isNaN(statsReduction) ? 0 : statsReduction,
statsReduction: isNaN(percentage) ? 0 : percentage,
}),
headers: {
"content-type": "application/json",
Expand Down Expand Up @@ -112,13 +109,13 @@ export default function (props: GameAppealProps) {
</ModalHeader>
<ModalBody>
<Input
id="reductPercentage"
onBeforeInput={(e) => {
const value = (e.target as EventTarget & { value: string })
.value;

return !value.match(/\D/);
}}
onChange={(e) => setPercentage(parseInt(e.target.value))}
placeholder="Number between 0 and 100"
/>
</ModalBody>
Expand Down

0 comments on commit c609ab4

Please sign in to comment.