import { useFieldArray, useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { PlusIcon, Trash2Icon } from 'lucide-react' import { z } from 'zod' import { appSwitcherConfigSchema } from '@cfdm/shared/contracts/app-switcher' import { Button } from '@cfdm/ui/components/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@cfdm/ui/components/card' import { FieldGroup } from '@cfdm/ui/components/field' import { Input } from '@cfdm/ui/components/input' import { FormField } from '@/components/form-field' import { SelectField } from '@/components/select-field' import { LoadingButton } from '@/components/loading-button' import { APP_SWITCHER_ICONS, type AppSwitcherIconName } from '@/lib/app-switcher-config' const ICON_OPTIONS = (Object.keys(APP_SWITCHER_ICONS) as AppSwitcherIconName[]).map((icon) => ({ value: icon, label: icon, })) const formSchema = z.object({ menuLabel: z.string().min(1), apps: appSwitcherConfigSchema.shape.apps, }) export type AppSwitcherFormValues = z.infer interface AppSwitcherEditorProps { defaultValues: AppSwitcherFormValues onSave: (values: AppSwitcherFormValues) => void isSaving?: boolean } export function AppSwitcherEditor({ defaultValues, onSave, isSaving }: AppSwitcherEditorProps) { const form = useForm({ resolver: zodResolver(formSchema), defaultValues, }) const { fields, append, remove } = useFieldArray({ control: form.control, name: 'apps' }) return ( Связанные приложения URL для переключателя в sidebar и deep links
void form.handleSubmit(onSave)(e)} > {fields.map((field, index) => (
form.setValue(`apps.${index}.icon`, (v ?? 'server') as AppSwitcherIconName, { shouldDirty: true, }) } options={ICON_OPTIONS} />
))}
Сохранить приложения
) }