import { useState } from 'react'; import { Modal, Button, Input, Form, toast } from "@heroui/react"; import { api } from '../api/client'; import { useSWRConfig } from 'swr'; export function CreateResourceModal({ isOpen, onOpenChange }: { isOpen: boolean, onOpenChange: (isOpen: boolean) => void }) { const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const [url, setUrl] = useState(''); const [category, setCategory] = useState(''); const [loading, setLoading] = useState(false); const { mutate } = useSWRConfig(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { await api.resources.post({ title, description, url, category }); mutate('/resources'); onOpenChange(false); setTitle(''); setDescription(''); setUrl(''); setCategory(''); } catch (err) { console.error(err); toast.danger('创建失败'); } finally { setLoading(false); } }; return ( 添加新资源
); }