"use client" import React, { useState } from "react" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Button } from "@/components/ui/button" import { AdminApi } from "@/lib/api" import { toast } from "sonner" import { ApiError } from "next/dist/server/api-utils" import { ResourceBadge } from "@/components/resource" import AddResourceTag from "./AddResourceTag" import { Textarea } from "@/components/ui/textarea" import { Plus } from "lucide-react" interface AddResourceProps { children: React.ReactNode; refresh: () => void; } export default function AddResource({ children, refresh }: AddResourceProps) { const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState({ title: "", description: "", imageUrl: "", link: "", tags: [] as { type: string, name: string }[], }); const handleSubmit = async () => { try { setLoading(true); await AdminApi.web.resource.create({ ...formData, }); toast.success("添加成功"); setOpen(false); refresh(); } catch (error) { toast.error((error as ApiError).message || "添加失败"); } } const handleOpenChange = (open: boolean) => { setOpen(open); if (open) { setFormData({ title: "", description: "", imageUrl: "", link: "", tags: [] as { type: string, name: string }[], }); } } return ( {children} 添加资源 添加一个新的资源到资源列表中
setFormData({ ...formData, title: e.target.value })} className="col-span-3" />