"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { toast } from "sonner"; import { Pencil, Trash2, Upload, X, Check } from "lucide-react"; interface SoftwareVersion { id: string; version: string; versionCode: number; changelog: string; downloadType: string; filePath: string | null; externalUrl: string | null; fileSize: number; downloadCount: number; isLatest: boolean; forceUpdate: boolean; minVersion: string | null; createdAt: Date; } interface SoftwareEditFormProps { software: { id: string; name: string; slug: string; description: string; versions: SoftwareVersion[]; }; } export function SoftwareEditForm({ software }: SoftwareEditFormProps) { const router = useRouter(); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); const fd = new FormData(e.currentTarget); const res = await fetch(`/api/software/${software.id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: fd.get("name"), slug: fd.get("slug"), description: fd.get("description"), }), }); if (res.ok) { toast.success("更新成功"); router.refresh(); } else { const err = await res.json(); toast.error(err.error || "更新失败"); } setLoading(false); } return (
基本信息