"use client"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { createPortal } from "react-dom"; import { Icon } from "@iconify/react"; import SubmitButton from "../submit-button"; interface Props { punishmentId: number; } export default function PunishmentDeletionDialog({ punishmentId }: Props) { const router = useRouter(); const [isOpen, setIsOpen] = useState(false); const [isVisible, setIsVisible] = useState(false); const [error, setError] = useState(undefined); const handleSubmit = async () => { const response = await fetch(`/api/admin/punish?id=${punishmentId}`, { method: "DELETE" }); if (!response.ok) { const data = await response.json(); setError(data.error); return; } router.refresh(); }; const close = () => { setIsVisible(false); setTimeout(() => { setIsOpen(false); }, 300); }; useEffect(() => { if (isOpen) { // slight delay to trigger animation setTimeout(() => setIsVisible(true), 10); } }, [isOpen]); return ( <> {isOpen && createPortal(

Punishment Deletion

Are you sure? This will delete the user‘s punishment and they will be able to come back.

{error && Error: {error}}
, document.body )} ); }