44 InformationCircleIcon ,
55 TrashIcon ,
66} from "@heroicons/react/24/outline" ;
7- import RjsfForm from "@rjsf/core" ;
87import type { FormProps as RjsfFormProps } from "@rjsf/core" ;
8+ import RjsfForm from "@rjsf/core" ;
99import {
1010 BaseInputTemplateProps ,
1111 ErrorSchema ,
@@ -48,6 +48,7 @@ import {
4848 Permission ,
4949} from "../types" ;
5050import { getSchemas } from "../utils/jsonSchema" ;
51+ import { getSubmitButtonOptions } from "../utils/rjsf" ;
5152import { formatLabel , isFileUploadFormat , slugify } from "../utils/tools" ;
5253import FormHeader from "./FormHeader" ;
5354import ArrayField from "./inputs/ArrayField" ;
@@ -69,7 +70,6 @@ import {
6970 TooltipRoot ,
7071 TooltipTrigger ,
7172} from "./radix/Tooltip" ;
72- import { getSubmitButtonOptions } from "../utils/rjsf" ;
7373
7474const RichTextField = lazy ( ( ) => import ( "./inputs/RichText/RichTextField" ) ) ;
7575
@@ -82,12 +82,14 @@ const widgets: RjsfFormProps["widgets"] = {
8282 TextareaWidget : TextareaWidget ,
8383} ;
8484
85- const Form = ( {
85+ export const Form = ( {
8686 data,
8787 schema,
8888 resource,
8989 validation : validationProp ,
9090 customInputs,
91+ onSubmitCallback,
92+ isEmbedded,
9193} : FormProps ) => {
9294 const [ validation , setValidation ] = useState ( validationProp ) ;
9395 const { basePath, options, apiBasePath } = useConfig ( ) ;
@@ -229,6 +231,7 @@ const Form = ({
229231 body : formData ,
230232 }
231233 ) ;
234+ debugger ;
232235 const result = await response . json ( ) ;
233236 if ( result ?. validation ) {
234237 setValidation ( result . validation ) ;
@@ -240,6 +243,12 @@ const Form = ({
240243 cleanAll ( ) ;
241244 }
242245 if ( result ?. deleted ) {
246+
247+ if ( onSubmitCallback ) {
248+ onSubmitCallback ( result ) ;
249+ return ;
250+ }
251+
243252 return router . replace ( {
244253 pathname : `${ basePath } /${ slugify ( resource ) } ` ,
245254 query : {
@@ -251,6 +260,12 @@ const Form = ({
251260 } ) ;
252261 }
253262 if ( result ?. created ) {
263+
264+ if ( onSubmitCallback ) {
265+ onSubmitCallback ( result ) ;
266+ return ;
267+ }
268+
254269 const pathname = result ?. redirect
255270 ? `${ basePath } /${ slugify ( resource ) } `
256271 : `${ basePath } /${ slugify ( resource ) } /${ result . createdId } ` ;
@@ -266,6 +281,12 @@ const Form = ({
266281 } ) ;
267282 }
268283 if ( result ?. updated ) {
284+
285+ if ( onSubmitCallback ) {
286+ onSubmitCallback ( result ) ;
287+ return ;
288+ }
289+
269290 const pathname = result ?. redirect
270291 ? `${ basePath } /${ slugify ( resource ) } `
271292 : location . pathname ;
@@ -306,9 +327,9 @@ const Form = ({
306327 const customInput = customInputs ?. [ props . name as Field < ModelName > ] ;
307328 const improvedCustomInput = customInput
308329 ? cloneElement ( customInput , {
309- ...customInput . props ,
310- mode : edit ? "edit" : "create" ,
311- } )
330+ ...customInput . props ,
331+ mode : edit ? "edit" : "create" ,
332+ } )
312333 : undefined ;
313334 return < ArrayField { ...props } customInput = { improvedCustomInput } /> ;
314335 } ,
@@ -605,7 +626,7 @@ const Form = ({
605626 extraErrors = { extraErrors }
606627 fields = { fields }
607628 disabled = { allDisabled }
608- formContext = { { isPending, schema } }
629+ formContext = { { isPending, schema, parentId : id } }
609630 templates = { templates }
610631 widgets = { widgets }
611632 ref = { ref }
@@ -618,9 +639,9 @@ const Form = ({
618639
619640 return (
620641 < div className = "relative h-full" >
621- < div className = "bg-nextadmin-background-default dark:bg-dark-nextadmin-background-default max-w-full p-4 align-middle sm:p-8" >
642+ < div className = { clsx ( ! isEmbedded && "bg-nextadmin-background-default dark:bg-dark-nextadmin-background-default p-4 sm:p-8" , " max-w-full align-middle " ) } >
622643 < Message className = "-mt-2 mb-2 sm:-mt-4 sm:mb-4" />
623- < div className = "bg-nextadmin-background-default dark:bg-dark-nextadmin-background-emphasis border-nextadmin-border-default dark:border-dark-nextadmin-border-default max-w-screen-md rounded-lg border p-4 sm:p-8" >
644+ < div className = { clsx ( ! isEmbedded && "bg-nextadmin-background-default dark:bg-dark-nextadmin-background-emphasis border-nextadmin-border-default dark:border-dark-nextadmin-border-default rounded-lg border" , " max-w-screen-md p-4 sm:p-8") } >
624645 < RjsfFormComponent ref = { formRef } />
625646 </ div >
626647 </ div >
@@ -635,7 +656,7 @@ const FormWrapper = ({
635656} : FormProps ) => {
636657 return (
637658 < ClientActionDialogProvider componentsMap = { clientActionsComponents } >
638- < FormHeader { ...props } />
659+ { props ?. isEmbedded ? null : < FormHeader { ...props } /> }
639660 < FormDataProvider
640661 data = { props . data }
641662 relationshipsRawData = { relationshipsRawData }
0 commit comments