feat: 将仓库可见性改为选择器组件,支持 public/private/protected

This commit is contained in:
xiongxiao
2026-03-16 01:22:49 +08:00
committed by cnb
parent 81b52cce8c
commit 3a821b1486

View File

@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import { useForm } from 'react-hook-form'
import { useForm, Controller } from 'react-hook-form'
import {
Dialog,
DialogContent,
@@ -12,6 +12,13 @@ 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 {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { useRepoStore } from '../store'
import { useShallow } from 'zustand/shallow'
@@ -32,7 +39,7 @@ export function CreateRepoDialog({ open, onOpenChange }: CreateRepoDialogProps)
createRepo: state.createRepo,
refresh: state.refresh,
})))
const { register, handleSubmit, reset } = useForm<FormData>()
const { register, handleSubmit, reset, control } = useForm<FormData>()
const [isSubmitting, setIsSubmitting] = useState(false)
useEffect(() => {
@@ -94,10 +101,22 @@ export function CreateRepoDialog({ open, onOpenChange }: CreateRepoDialogProps)
<div className="space-y-2">
<Label htmlFor="visibility"></Label>
<Input
id="visibility"
placeholder="public 或 private"
{...register('visibility')}
<Controller
name="visibility"
control={control}
defaultValue="public"
render={({ field }) => (
<Select {...field}>
<SelectTrigger id="visibility">
<SelectValue placeholder="选择可见性" />
</SelectTrigger>
<SelectContent>
<SelectItem value="public"> (public)</SelectItem>
<SelectItem value="private"> (private)</SelectItem>
<SelectItem value="protected"> (protected)</SelectItem>
</SelectContent>
</Select>
)}
/>
</div>