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