|
'use client'; |
|
|
|
import { zodResolver } from '@hookform/resolvers/zod'; |
|
import { useForm } from 'react-hook-form'; |
|
import { z } from 'zod'; |
|
|
|
import { |
|
Form, |
|
FormControl, |
|
FormField, |
|
FormItem, |
|
FormLabel, |
|
FormMessage, |
|
} from '@/components/ui/form'; |
|
import { Input } from '@/components/ui/input'; |
|
import { MultiSelect } from '@/components/ui/multi-select'; |
|
import { |
|
Select, |
|
SelectContent, |
|
SelectItem, |
|
SelectTrigger, |
|
SelectValue, |
|
} from '@/components/ui/select'; |
|
import { useTranslate } from '@/hooks/common-hooks'; |
|
import { Cat, Dog, Fish, Rabbit, Turtle } from 'lucide-react'; |
|
import { useState } from 'react'; |
|
|
|
const frameworksList = [ |
|
{ value: 'react', label: 'React', icon: Turtle }, |
|
{ value: 'angular', label: 'Angular', icon: Cat }, |
|
{ value: 'vue', label: 'Vue', icon: Dog }, |
|
{ value: 'svelte', label: 'Svelte', icon: Rabbit }, |
|
{ value: 'ember', label: 'Ember', icon: Fish }, |
|
]; |
|
|
|
export default function BasicSettingForm() { |
|
const { t } = useTranslate('knowledgeConfiguration'); |
|
|
|
const formSchema = z.object({ |
|
name: z.string().min(1), |
|
a: z.number().min(2, { |
|
message: 'Username must be at least 2 characters.', |
|
}), |
|
language: z.string().min(1, { |
|
message: 'Username must be at least 2 characters.', |
|
}), |
|
c: z.number().min(2, { |
|
message: 'Username must be at least 2 characters.', |
|
}), |
|
d: z.string().min(2, { |
|
message: 'Username must be at least 2 characters.', |
|
}), |
|
}); |
|
|
|
const form = useForm<z.infer<typeof formSchema>>({ |
|
resolver: zodResolver(formSchema), |
|
defaultValues: { |
|
name: '', |
|
language: 'English', |
|
}, |
|
}); |
|
const [selectedFrameworks, setSelectedFrameworks] = useState<string[]>([ |
|
'react', |
|
'angular', |
|
]); |
|
|
|
function onSubmit(values: z.infer<typeof formSchema>) { |
|
console.log(values); |
|
} |
|
|
|
return ( |
|
<Form {...form}> |
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8"> |
|
<FormField |
|
control={form.control} |
|
name="name" |
|
render={({ field }) => ( |
|
<FormItem> |
|
<FormLabel>{t('name')}</FormLabel> |
|
<FormControl> |
|
<Input {...field}></Input> |
|
</FormControl> |
|
<FormMessage /> |
|
</FormItem> |
|
)} |
|
/> |
|
<FormField |
|
control={form.control} |
|
name="d" |
|
render={({ field }) => ( |
|
<FormItem> |
|
<FormLabel>Username</FormLabel> |
|
<FormControl> |
|
<Input {...field}></Input> |
|
</FormControl> |
|
<FormMessage /> |
|
</FormItem> |
|
)} |
|
/> |
|
<FormField |
|
control={form.control} |
|
name="language" |
|
render={({ field }) => ( |
|
<FormItem> |
|
<FormLabel>{t('language')}</FormLabel> |
|
<Select onValueChange={field.onChange} defaultValue={field.value}> |
|
<FormControl> |
|
<SelectTrigger> |
|
<SelectValue placeholder="Select a verified email to display" /> |
|
</SelectTrigger> |
|
</FormControl> |
|
<SelectContent> |
|
<SelectItem value="[email protected]">[email protected]</SelectItem> |
|
<SelectItem value="[email protected]">[email protected]</SelectItem> |
|
<SelectItem value="[email protected]">[email protected]</SelectItem> |
|
</SelectContent> |
|
</Select> |
|
<FormMessage /> |
|
</FormItem> |
|
)} |
|
/> |
|
<FormField |
|
control={form.control} |
|
name="c" |
|
render={({ field }) => ( |
|
<FormItem> |
|
<FormLabel>Username</FormLabel> |
|
<FormControl> |
|
<MultiSelect |
|
options={frameworksList} |
|
onValueChange={setSelectedFrameworks} |
|
defaultValue={selectedFrameworks} |
|
placeholder="Select frameworks" |
|
variant="inverted" |
|
maxCount={100} |
|
{...field} |
|
/> |
|
</FormControl> |
|
<FormMessage /> |
|
</FormItem> |
|
)} |
|
/> |
|
</form> |
|
</Form> |
|
); |
|
} |
|
|