Skip to content

Commit 0b945f5

Browse files
committed
[DOC] rewrite selectArrayInput create example
1 parent e6cfbd3 commit 0b945f5

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

docs/SelectArrayInput.md

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -517,43 +517,40 @@ const PostCreate = () => {
517517

518518
const CreateTag = () => {
519519
const { filter, onCancel, onCreate } = useCreateSuggestionContext();
520-
const [value, setValue] = React.useState(filter || '');
521-
const [create] = useCreate();
522-
523-
const handleSubmit = event => {
524-
event.preventDefault();
525-
create(
526-
'tags',
527-
{
528-
data: {
529-
title: value,
530-
},
531-
},
532-
{
533-
onSuccess: (data) => {
534-
setValue('');
535-
onCreate(data);
536-
},
537-
}
538-
);
539-
};
540-
520+
521+
const onTagCreate = (tag) => {
522+
onCreate(tag);
523+
}
541524
return (
542525
<Dialog open onClose={onCancel}>
543-
<form onSubmit={handleSubmit}>
544-
<DialogContent>
545-
<TextField
546-
label="New tag"
547-
value={value}
548-
onChange={event => setValue(event.target.value)}
549-
autoFocus
550-
/>
551-
</DialogContent>
552-
<DialogActions>
553-
<Button type="submit">Save</Button>
554-
<Button onClick={onCancel}>Cancel</Button>
555-
</DialogActions>
556-
</form>
526+
<DialogTitle sx={{ m: 0, p: 2 }}>Create Tag</DialogTitle>
527+
<IconButton
528+
aria-label="close"
529+
onClick={onCancel}
530+
sx={theme => ({
531+
position: 'absolute',
532+
right: 8,
533+
top: 8,
534+
color: theme.palette.grey[500],
535+
})}
536+
>
537+
<CloseIcon />
538+
</IconButton>
539+
<DialogContent sx={{ p: 0 }}>
540+
<CreateBase
541+
redirect={false}
542+
resource="tags"
543+
mutationOptions={{
544+
onSuccess: tag => {
545+
onTagCreate(tag);
546+
},
547+
}}
548+
>
549+
<SimpleForm >
550+
<TextInput source="tag" helperText={false} autoFocus/>
551+
</SimpleForm>
552+
</CreateBase>
553+
</DialogContent>
557554
</Dialog>
558555
);
559556
};

0 commit comments

Comments
 (0)