generated from kevisual/vite-react-template
feat: 将仓库可见性改为选择器组件,支持 public/private/protected
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user