@@ -17,9 +17,7 @@ export function SegmentPropertiesForm({
1717 const dispatch = useAppDispatch ( )
1818 const toasts = useToasts ( )
1919
20- const manifest = useAppSelector ( ( state ) =>
21- state . typeManifests . manifests ?. find ( ( p ) => p . id === segment . segmentType )
22- )
20+ const manifests = useAppSelector ( ( state ) => state . typeManifests . manifests )
2321
2422 const form = useForm ( {
2523 defaultValues : segment ,
@@ -130,61 +128,65 @@ export function SegmentPropertiesForm({
130128 </ >
131129 ) }
132130 />
131+ < form . Subscribe selector = { ( state ) => state . values . segmentType } >
132+ { ( segmentType ) => {
133+ const manifest = manifests ?. find ( ( m ) => m . id === segmentType )
133134
134- { manifest ?. payload ?. map ( ( fieldInfo ) => {
135- console . log ( fieldInfo )
136- return (
137- < form . Field
138- key = { `payload.${ fieldInfo . id } ` }
139- name = { `payload.${ fieldInfo . id } ` }
140- children = { ( field ) => (
141- < >
142- < Form . Group className = "mb-3" >
143- < Form . Label htmlFor = { field . name } > { fieldInfo . label } :</ Form . Label >
144-
145- { fieldInfo . type === 'string' && (
146- < Form . Control
147- name = { field . name }
148- type = "text"
149- // eslint-disable-next-line @typescript-eslint/no-explicit-any
150- value = { field . state . value as any }
151- onBlur = { field . handleBlur }
152- onChange = { ( e ) => field . handleChange ( e . target . value ) }
153- />
154- ) }
135+ if ( ! manifest ) {
136+ return (
137+ < Form . Group className = "mb-3" >
138+ < Form . Text > Type not found</ Form . Text >
139+ </ Form . Group >
140+ )
141+ }
155142
156- { fieldInfo . type === 'number' && (
157- < Form . Control
158- name = { field . name }
159- type = "number"
160- value = { Number ( field . state . value ) }
161- onBlur = { field . handleBlur }
162- onChange = { ( e ) => field . handleChange ( Number ( e . target . value ) ) }
163- />
143+ return (
144+ < >
145+ { manifest . payload ?. map ( ( fieldInfo ) => (
146+ < form . Field key = { `payload.${ fieldInfo . id } ` } name = { `payload.${ fieldInfo . id } ` } >
147+ { ( field ) => (
148+ < >
149+ < Form . Group className = "mb-3" >
150+ < Form . Label htmlFor = { field . name } > { fieldInfo . label } :</ Form . Label >
151+
152+ { fieldInfo . type === 'string' && (
153+ < Form . Control
154+ type = "text"
155+ value = { String ( field . state . value ?? '' ) }
156+ onBlur = { field . handleBlur }
157+ onChange = { ( e ) => field . handleChange ( e . target . value ) }
158+ />
159+ ) }
160+
161+ { fieldInfo . type === 'number' && (
162+ < Form . Control
163+ name = { field . name }
164+ type = "number"
165+ value = { Number ( field . state . value ?? 0 ) }
166+ onBlur = { field . handleBlur }
167+ onChange = { ( e ) => field . handleChange ( Number ( e . target . value ) ) }
168+ />
169+ ) }
170+
171+ { fieldInfo . type === 'boolean' && (
172+ < Form . Switch
173+ name = { field . name }
174+ checked = { Boolean ( field . state . value ) }
175+ onBlur = { field . handleBlur }
176+ onChange = { ( e ) => field . handleChange ( e . target . checked ) }
177+ />
178+ ) }
179+ </ Form . Group >
180+ < FieldInfo field = { field } />
181+ </ >
164182 ) }
183+ </ form . Field >
184+ ) ) }
185+ </ >
186+ )
187+ } }
188+ </ form . Subscribe >
165189
166- { fieldInfo . type === 'boolean' && (
167- < Form . Switch
168- name = { field . name }
169- type = "text"
170- checked = { Boolean ( field . state . value ) }
171- onBlur = { field . handleBlur }
172- onChange = { ( e ) => field . handleChange ( e . target . checked ) }
173- />
174- ) }
175- </ Form . Group >
176- < FieldInfo field = { field } />
177- </ >
178- ) }
179- />
180- )
181- } ) }
182-
183- { ! manifest && (
184- < Form . Group className = "mb-3" >
185- < Form . Text > Type not found</ Form . Text >
186- </ Form . Group >
187- ) }
188190 < form . Subscribe
189191 selector = { ( state ) => [ state . canSubmit , state . isSubmitting , state . isPristine ] }
190192 children = { ( [ canSubmit , isSubmitting , isPristine ] ) => (
0 commit comments