@@ -423,10 +423,11 @@ import {
423423 SelectField ,
424424 SelectInput ,
425425 SimpleForm ,
426+ TextField ,
426427 TextInput ,
427428 useRecordContext ,
428429} from ' react-admin' ;
429- import { EditDialog } from ' @react-admin/ra-form-layout' ;
430+ import { CreateDialog } from ' @react-admin/ra-form-layout' ;
430431
431432const sexChoices = [
432433 { id: ' male' , name: ' Male' },
@@ -445,19 +446,37 @@ const CustomerForm = (props: any) => (
445446const EmployerSimpleFormWithFullyControlledDialogs = () => {
446447 const record = useRecordContext ();
447448
448- const [isEditDialogOpen, setIsEditDialogOpen ] = useState (false );
449- const openEditDialog = useCallback (() => {
450- setIsEditDialogOpen (true );
449+ const [isCreateDialogOpen, setIsCreateDialogOpen ] = useState (false );
450+ const openCreateDialog = useCallback (() => {
451+ setIsCreateDialogOpen (true );
451452 }, []);
452- const closeEditDialog = useCallback (() => {
453- setIsEditDialogOpen (false );
453+ const closeCreateDialog = useCallback (() => {
454+ setIsCreateDialogOpen (false );
454455 }, []);
455456
456457 return (
457458 <SimpleForm >
458459 <TextInput source = " name" validate = { required ()} />
459460 <TextInput source = " address" validate = { required ()} />
460461 <TextInput source = " city" validate = { required ()} />
462+ <Button
463+ label = " Create a new customer"
464+ onClick = { () => openCreateDialog ()}
465+ size = " medium"
466+ variant = " contained"
467+ sx = { { mb: 4 }}
468+ />
469+ <CreateDialog
470+ fullWidth
471+ maxWidth = " md"
472+ record = { { employer_id: record ?.id }} // pre-populates the employer_id to link the new customer to the current employer
473+ isOpen = { isCreateDialogOpen }
474+ open = { openCreateDialog }
475+ close = { closeCreateDialog }
476+ resource = " customers"
477+ >
478+ <CustomerForm />
479+ </CreateDialog >
461480 <ReferenceManyField
462481 label = " Customers"
463482 reference = " customers"
@@ -471,28 +490,8 @@ const EmployerSimpleFormWithFullyControlledDialogs = () => {
471490 <DataTable.Col source = " sex" >
472491 <SelectField source = " sex" choices = { sexChoices } />
473492 </DataTable.Col >
474- <DataTable.Col >
475- <Button
476- label = " Edit customer"
477- onClick = { () => openEditDialog ()}
478- size = " medium"
479- variant = " contained"
480- sx = { { mb: 4 }}
481- />
482- <DataTable.Col >
483493 </DataTable >
484494 </ReferenceManyField >
485- <EditDialog
486- fullWidth
487- maxWidth = " md"
488- record = { { employer_id: record ?.id }} // pre-populates the employer_id to link the new customer to the current employer
489- isOpen = { isEditDialogOpen }
490- open = { openEditDialog }
491- close = { closeEditDialog }
492- resource = " customers"
493- >
494- <CustomerForm />
495- </EditDialog >
496495 </SimpleForm >
497496 );
498497};
0 commit comments