"use client"; import { useEffect, useState } from "react"; import { api } from "@/lib/api/client"; import { GlassCard } from "@/components/ui/glass-card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { PageHeader } from "@/components/dashboard/page-header"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; type Issue = { id: string; subject: string; body: string; status: string; master_reply: string | null; created_at: string; leagues: { name: string } | null; }; export function IssuesPanel({ leagues, asMaster, }: { leagues: { id: string; name: string }[]; asMaster: boolean; }) { const [issues, setIssues] = useState([]); const [loading, setLoading] = useState(false); const [showConfirm, setShowConfirm] = useState(false); const [pending, setPending] = useState(null); useEffect(() => { api.issues.list(asMaster).then((d) => setIssues(d as Issue[])); }, [asMaster]); async function submit(fd: FormData) { setLoading(true); try { await api.issues.create({ leagueId: fd.get("league_id") as string, subject: fd.get("subject") as string, body: fd.get("body") as string, }); const updated = (await api.issues.list(asMaster)) as Issue[]; setIssues(updated); } finally { setLoading(false); setShowConfirm(false); setPending(null); } } return (
{!asMaster && (
{ e.preventDefault(); if (leagues.length === 0) return; setPending(new FormData(e.currentTarget)); setShowConfirm(true); }} >