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 { 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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user