11import { FieldValues } from 'react-hook-form' ;
22import {
33 createHeadlessForm as baseCreateHeadlessForm ,
4- FormResult ,
54 modify ,
65} from '@remoteoss/remote-json-schema-form-kit' ;
76import { convertToCents } from '@/src/components/form/utils' ;
8- import { JSFModify } from '@/src/flows/types' ;
7+ import {
8+ JSFModify ,
9+ JSONSchemaFormResultWithFieldsets ,
10+ } from '@/src/flows/types' ;
911import { findFieldsByType } from '@/src/flows/utils' ;
1012import { JSFFieldset } from '@/src/types/remoteFlows' ;
1113
12- type CreateHeadlessFormResult = FormResult & {
13- meta : {
14- 'x-jsf-fieldsets' : JSFFieldset ;
15- } ;
16- } ;
17-
1814/*
1915 * Creates a headless form from a JSON Schema, useful to avoid code duplication when creating headless forms.
2016 * @param jsfSchema - The JSON Schema
@@ -26,18 +22,24 @@ export const createHeadlessForm = (
2622 jsfSchema : Record < string , unknown > ,
2723 fieldValues ?: FieldValues ,
2824 options ?: { jsfModify ?: JSFModify } ,
29- ) : CreateHeadlessFormResult => {
25+ ) : JSONSchemaFormResultWithFieldsets => {
3026 if ( options && options . jsfModify ) {
3127 const { required, allOf, ...modifyConfig } = options . jsfModify ;
3228 const { schema } = modify ( jsfSchema , modifyConfig ) ;
3329 jsfSchema = schema ;
3430
3531 if ( required ) {
36- jsfSchema . required = [ ...schema . required , ...required ] ;
32+ jsfSchema . required = [
33+ ...( Array . isArray ( schema . required ) ? schema . required : [ ] ) ,
34+ ...required ,
35+ ] ;
3736 }
3837
3938 if ( allOf ) {
40- jsfSchema . allOf = [ ...( schema . allOf || [ ] ) , ...allOf ] ;
39+ jsfSchema . allOf = [
40+ ...( Array . isArray ( schema . allOf ) ? schema . allOf : [ ] ) ,
41+ ...allOf ,
42+ ] ;
4143 }
4244 }
4345
0 commit comments