Skip to content

Commit e7a94b9

Browse files
committed
Fix incorrect documentation of EditInDialogButton.
1 parent 6bf3c34 commit e7a94b9

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed

docs/EditDialog.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

431432
const sexChoices = [
432433
{ id: 'male', name: 'Male' },
@@ -445,19 +446,37 @@ const CustomerForm = (props: any) => (
445446
const 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
};

docs/ReferenceManyField.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -582,18 +582,14 @@ const EmployerEdit = () => (
582582
<DataTable>
583583
<DataTable.Col source="first_name" />
584584
<DataTable.Col source="last_name" />
585-
<DataTable.Col
586-
render={record => (
587-
<EditInDialogButton>
588-
<SimpleForm
589-
record={{ employer_id: record.id }}
590-
>
591-
<TextInput source="first_name" />
592-
<TextInput source="last_name" />
593-
</SimpleForm>
594-
</EditInDialogButton>
595-
)}
596-
/>
585+
<DataTable.Col>
586+
<EditInDialogButton>
587+
<SimpleForm>
588+
<TextInput source="first_name" />
589+
<TextInput source="last_name" />
590+
</SimpleForm>
591+
</EditInDialogButton>
592+
</DataTable.Col>
597593
</DataTable>
598594
</ReferenceManyField>
599595
</SimpleForm>

0 commit comments

Comments
 (0)