review-select-with-create.tsx 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { Button } from '@/vdb/components/ui/button';
  2. import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/vdb/components/ui/dialog';
  3. import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/vdb/components/ui/form';
  4. import { Input } from '@/vdb/components/ui/input';
  5. import { Textarea } from '@/vdb/components/ui/textarea';
  6. import { DashboardFormComponentProps } from '@/vdb/framework/form-engine/form-engine-types';
  7. import { handleNestedFormSubmit } from '@/vdb/framework/form-engine/utils';
  8. import { zodResolver } from '@hookform/resolvers/zod';
  9. import { useForm } from 'react-hook-form';
  10. import { z } from 'zod';
  11. import { ReviewMultiSelect } from './custom-form-components';
  12. const formSchema = z.object({
  13. title: z.string().min(1, 'Title is required'),
  14. body: z.string().min(1, 'Body is required'),
  15. });
  16. type FormSchema = z.infer<typeof formSchema>;
  17. export function ReviewSelectWithCreate(props: DashboardFormComponentProps) {
  18. const form = useForm<FormSchema>({
  19. resolver: zodResolver(formSchema),
  20. defaultValues: {
  21. title: '',
  22. body: '',
  23. },
  24. });
  25. const onSubmit = (data: FormSchema) => {
  26. // TODO: Handle form submission
  27. form.reset();
  28. };
  29. return (
  30. <div>
  31. <ReviewMultiSelect {...props}></ReviewMultiSelect>
  32. <Dialog>
  33. <DialogTrigger asChild>
  34. <Button variant="outline">Create new</Button>
  35. </DialogTrigger>
  36. <DialogContent>
  37. <DialogHeader>
  38. <DialogTitle>Create new review</DialogTitle>
  39. </DialogHeader>
  40. <Form {...form}>
  41. <form onSubmit={handleNestedFormSubmit(form, onSubmit)} className="space-y-4">
  42. <FormField
  43. control={form.control}
  44. name="title"
  45. render={({ field }) => (
  46. <FormItem>
  47. <FormLabel>Title</FormLabel>
  48. <FormControl>
  49. <Input placeholder="Enter review title" {...field} />
  50. </FormControl>
  51. <FormMessage />
  52. </FormItem>
  53. )}
  54. />
  55. <FormField
  56. control={form.control}
  57. name="body"
  58. render={({ field }) => (
  59. <FormItem>
  60. <FormLabel>Body</FormLabel>
  61. <FormControl>
  62. <Textarea
  63. placeholder="Enter review body"
  64. className="min-h-[100px]"
  65. {...field}
  66. />
  67. </FormControl>
  68. <FormMessage />
  69. </FormItem>
  70. )}
  71. />
  72. <div className="flex justify-end gap-2">
  73. <Button type="submit">Create Review</Button>
  74. </div>
  75. </form>
  76. </Form>
  77. </DialogContent>
  78. </Dialog>
  79. </div>
  80. );
  81. }