import { useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' 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 { useRepoStore } from '../store' interface CreateRepoDialogProps { open: boolean onOpenChange: (open: boolean) => void } interface FormData { path: string license: string description: string visibility: string } export function CreateRepoDialog({ open, onOpenChange }: CreateRepoDialogProps) { const { createRepo, getList } = useRepoStore() const { register, handleSubmit, reset } = useForm() const [isSubmitting, setIsSubmitting] = useState(false) useEffect(() => { if (open) { // 重置表单 reset({ path: '', license: '', description: '', visibility: 'public' }) } }, [open, reset]) const onSubmit = async (data: FormData) => { setIsSubmitting(true) try { const submitData = { ...data, } const res = await createRepo(submitData) if (res?.code === 200) { onOpenChange(false) await getList(true) } } finally { setIsSubmitting(false) } } return ( 新建仓库 填写仓库信息以创建新的代码仓库