@@ -6,11 +6,16 @@ import {
66 FormLabel ,
77} from '@app-builder/components/Form' ;
88import { serverServices } from '@app-builder/services/init.server' ;
9- import { parseFormSafe } from '@app-builder/utils/input-validation' ;
109import { zodResolver } from '@hookform/resolvers/zod' ;
1110import { type ActionArgs , json } from '@remix-run/node' ;
1211import { useFetcher } from '@remix-run/react' ;
13- import { Button , HiddenInputs , Input , Modal } from '@ui-design-system' ;
12+ import {
13+ Button ,
14+ Checkbox ,
15+ HiddenInputs ,
16+ Input ,
17+ Modal ,
18+ } from '@ui-design-system' ;
1419import { type Namespace } from 'i18next' ;
1520import { useEffect , useState } from 'react' ;
1621import { Form , FormProvider , useForm } from 'react-hook-form' ;
@@ -24,6 +29,7 @@ export const handle = {
2429const editFieldFormSchema = z . object ( {
2530 description : z . string ( ) ,
2631 fieldId : z . string ( ) . uuid ( ) ,
32+ isEnum : z . boolean ( ) ,
2733} ) ;
2834
2935export async function action ( { request } : ActionArgs ) {
@@ -32,43 +38,47 @@ export async function action({ request }: ActionArgs) {
3238 failureRedirect : '/login' ,
3339 } ) ;
3440
35- const parsedForm = await parseFormSafe ( request , editFieldFormSchema ) ;
36- if ( ! parsedForm . success ) {
37- parsedForm . error . flatten ( ( issue ) => issue ) ;
41+ const parsedData = editFieldFormSchema . safeParse ( await request . json ( ) ) ;
42+
43+ if ( ! parsedData . success ) {
44+ parsedData . error . flatten ( ( issue ) => issue ) ;
3845
3946 return json ( {
4047 success : false as const ,
41- values : parsedForm . formData ,
42- error : parsedForm . error . format ( ) ,
48+ values : null ,
49+ error : parsedData . error . format ( ) ,
4350 } ) ;
4451 }
45- const { description, fieldId } = parsedForm . data ;
52+ const { description, fieldId, isEnum } = parsedData . data ;
4653
4754 try {
4855 await apiClient . patchDataModelField ( fieldId , {
4956 description,
57+ is_enum : isEnum ,
5058 } ) ;
5159 return json ( {
5260 success : true as const ,
53- values : parsedForm . data ,
61+ values : parsedData . data ,
5462 error : null ,
5563 } ) ;
5664 } catch ( error ) {
5765 return json ( {
5866 success : false as const ,
59- values : parsedForm . data ,
60- error : error ,
67+ values : parsedData . data ,
68+ error,
6169 } ) ;
6270 }
6371}
6472
6573export function EditField ( {
6674 fieldId,
6775 description,
76+ isEnum,
6877 children,
6978} : {
7079 fieldId : string ;
7180 description : string ;
81+ isEnum : boolean ;
7282 children : React . ReactNode ;
7383} ) {
7484 const { t } = useTranslation ( handle . i18n ) ;
@@ -80,6 +90,7 @@ export function EditField({
8090 defaultValues : {
8191 description,
8292 fieldId,
93+ isEnum,
8394 } ,
8495 } ) ;
8596 const { control, register, setValue } = formMethods ;
@@ -97,10 +108,11 @@ export function EditField({
97108 < Modal . Content >
98109 < Form
99110 control = { control }
100- onSubmit = { ( { formData } ) => {
101- fetcher . submit ( formData , {
111+ onSubmit = { ( { formDataJson } ) => {
112+ fetcher . submit ( formDataJson , {
102113 method : 'POST' ,
103114 action : '/ressources/data/editField' ,
115+ encType : 'application/json' ,
104116 } ) ;
105117 } }
106118 >
@@ -130,6 +142,29 @@ export function EditField({
130142 ) }
131143 />
132144 </ div >
145+ < FormField
146+ name = "isEnum"
147+ control = { control }
148+ render = { ( { field } ) => (
149+ < FormItem className = "flex flex-row items-center gap-4" >
150+ < FormControl >
151+ < Checkbox
152+ defaultChecked = { isEnum }
153+ onCheckedChange = { ( checked ) => {
154+ field . onChange ( checked ) ;
155+ } }
156+ />
157+ </ FormControl >
158+ < FormLabel >
159+ < p > { t ( 'data:create_field.is_enum.title' ) } </ p >
160+ < p className = "text-xs" >
161+ { t ( 'data:create_field.is_enum.subtitle' ) }
162+ </ p >
163+ </ FormLabel >
164+ < FormError />
165+ </ FormItem >
166+ ) }
167+ />
133168 < div className = "flex flex-1 flex-row gap-2" >
134169 < Modal . Close asChild >
135170 < Button className = "flex-1" variant = "secondary" >
0 commit comments