"use client"; import { useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import type { ForgejoRepository } from "@/lib/api-forgejo"; import { createForgejoIssue, ISSUE_TEMPLATE, type CreateIssueResponse, } from "@/lib/api-forgejo"; type CreateForgejoIssueDialogProps = { repositories: ForgejoRepository[]; open: boolean; onOpenChange: (open: boolean) => void; onSuccess: (result: CreateIssueResponse) => void; defaultRepositoryId?: string; }; export function CreateForgejoIssueDialog({ repositories, open, onOpenChange, onSuccess, defaultRepositoryId, }: CreateForgejoIssueDialogProps) { const [repositoryId, setRepositoryId] = useState( defaultRepositoryId ?? repositories[0]?.id ?? "", ); const [title, setTitle] = useState(""); const [body, setBody] = useState(ISSUE_TEMPLATE); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(null); const reset = () => { setTitle(""); setBody(ISSUE_TEMPLATE); setRepositoryId(defaultRepositoryId ?? repositories[0]?.id ?? ""); setError(null); }; const handleOpenChange = (next: boolean) => { if (!isSubmitting) { if (!next) reset(); onOpenChange(next); } }; const handleSubmit = async () => { if (!title.trim() || !repositoryId) return; setIsSubmitting(true); setError(null); try { const result = await createForgejoIssue({ repository_id: repositoryId, title: title.trim(), body, }); reset(); onSuccess(result); onOpenChange(false); } catch (err) { setError(err instanceof Error ? err.message : "Failed to create issue"); } finally { setIsSubmitting(false); } }; const selectedRepo = repositories.find((r) => r.id === repositoryId); const repoLabel = selectedRepo ? selectedRepo.display_name || `${selectedRepo.owner}/${selectedRepo.repo}` : "—"; return ( Create issue Open a new issue on the connected Git repository. The body is pre-filled with the standard issue template.
{repositories.length > 1 ? (
) : (
Repository:{" "} {repoLabel}
)}
setTitle(e.target.value)} disabled={isSubmitting} placeholder="Short, descriptive issue title" />

Fill in the sections below. Remove any that don't apply.