feat: 添加创建仓库对话框和停止工作区功能,优化仓库列表界面

This commit is contained in:
2026-02-10 00:18:57 +08:00
parent 36edf12fd0
commit f876a65c6b
4 changed files with 207 additions and 7 deletions

View File

@@ -0,0 +1,128 @@
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<FormData>()
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 (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-[600px]">
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="path"> *</Label>
<Input
id="path"
placeholder="例如: username/repository"
{...register('path', { required: true })}
/>
</div>
<div className="space-y-2">
<Label htmlFor="description"></Label>
<Textarea
id="description"
placeholder="简短描述你的仓库..."
rows={3}
{...register('description')}
/>
</div>
<div className="space-y-2">
<Label htmlFor="visibility"></Label>
<Input
id="visibility"
placeholder="public 或 private"
{...register('visibility')}
/>
</div>
<div className="space-y-2">
<Label htmlFor="topics"></Label>
<Input
id="license"
placeholder="例如: MIT, Apache-2.0"
{...register('license')}
/>
</div>
<DialogFooter>
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
disabled={isSubmitting}
>
</Button>
<Button type="submit" disabled={isSubmitting}>
{isSubmitting ? '创建中...' : '创建仓库'}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}