Skip to content

Commit 8b5400b

Browse files
committed
Fix code snippet
1 parent 0a94c8d commit 8b5400b

File tree

1 file changed

+46
-58
lines changed

1 file changed

+46
-58
lines changed

docs/EditDialog.md

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -433,75 +433,63 @@ const sexChoices = [
433433
{ id: 'female', name: 'Female' },
434434
];
435435

436-
const CustomerForm = (props: any) => (
437-
<SimpleForm defaultValues={{ firstname: 'John', name: 'Doe' }} {...props}>
436+
const CustomerForm = () => (
437+
<SimpleForm>
438438
<TextInput source="first_name" validate={required()} />
439439
<TextInput source="last_name" validate={required()} />
440440
<DateInput source="dob" label="born" validate={required()} />
441441
<SelectInput source="sex" choices={sexChoices} />
442442
</SimpleForm>
443443
);
444444

445-
const EmployerSimpleFormWithFullyControlledDialogs = () => {
446-
const record = useRecordContext();
447-
448-
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
449-
const openEditDialog = useCallback(() => {
450-
setIsEditDialogOpen(true);
445+
const EmployerEdit = () => {
446+
const [record, setRecord] = React.useState<any>(undefined);
447+
const closeDialog = React.useCallback(() => {
448+
setRecord(undefined);
451449
}, []);
452-
const closeEditDialog = useCallback(() => {
453-
setIsEditDialogOpen(false);
454-
}, []);
455-
456450
return (
457-
<SimpleForm>
458-
<TextInput source="name" validate={required()} />
459-
<TextInput source="address" validate={required()} />
460-
<TextInput source="city" validate={required()} />
461-
<ReferenceManyField
462-
label="Customers"
463-
reference="customers"
464-
target="employer_id"
465-
>
466-
<DataTable>
467-
<DataTable.Col source="id" />
468-
<DataTable.Col source="first_name" />
469-
<DataTable.Col source="last_name" />
470-
<DataTable.Col source="dob" label="born" field={DateField} />
471-
<DataTable.Col source="sex">
472-
<SelectField source="sex" choices={sexChoices} />
473-
</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>
483-
</DataTable>
484-
</ReferenceManyField>
485-
<EditDialog
486-
fullWidth
487-
maxWidth="md"
488-
record={record}
489-
isOpen={isEditDialogOpen}
490-
open={openEditDialog}
491-
close={closeEditDialog}
492-
resource="customers"
493-
>
494-
<CustomerForm />
495-
</EditDialog>
496-
</SimpleForm>
451+
<Edit>
452+
<SimpleForm>
453+
<TextInput source="name" validate={required()} />
454+
<TextInput source="address" validate={required()} />
455+
<TextInput source="city" validate={required()} />
456+
<ReferenceManyField
457+
label="Customers"
458+
reference="customers"
459+
target="employer_id"
460+
>
461+
<DataTable>
462+
<DataTable.Col source="id" />
463+
<DataTable.Col source="first_name" />
464+
<DataTable.Col source="last_name" />
465+
<DataTable.Col label="born">
466+
<DateField source="dob" label="born" />
467+
</DataTable.Col>
468+
<DataTable.Col source="sex">
469+
<SelectField source="sex" choices={sexChoices} />
470+
</DataTable.Col>
471+
<DataTable.Col render={record => (
472+
<Button
473+
label="Edit customer"
474+
onClick={() => setRecord(record)}
475+
/>
476+
)} />
477+
</DataTable>
478+
</ReferenceManyField>
479+
<EditDialog
480+
record={record}
481+
resource="customers"
482+
isOpen={!!record}
483+
close={closeDialog}
484+
fullWidth
485+
maxWidth="md"
486+
>
487+
<CustomerForm />
488+
</EditDialog>
489+
</SimpleForm>
490+
</Edit>
497491
);
498492
};
499-
500-
const EmployerEdit = () => (
501-
<Edit>
502-
<EmployerSimpleFormWithFullyControlledDialogs />
503-
</Edit>
504-
);
505493
```
506494

507495
{% endraw %}

0 commit comments

Comments
 (0)