Skip to content

Commit 8eed531

Browse files
committed
update Creating New Choices doc and pluralize ressource
1 parent c92d76b commit 8eed531

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

docs/AutocompleteInput.md

+37-37
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ const CreateAuthor = () => {
202202
<DialogContent sx={{ p: 0 }}>
203203
<CreateBase
204204
redirect={false}
205-
resource="author"
205+
resource="authors"
206206
mutationOptions={{
207207
onSuccess: author => {
208208
onAuthorCreate(author);
@@ -874,21 +874,22 @@ Use the `create` prop when you want a more polished or complex UI. For example a
874874
import {
875875
AutocompleteInput,
876876
Create,
877+
CreateBase,
877878
ReferenceInput,
878879
SimpleForm,
879880
TextInput,
880881
useCreate,
881-
useCreateSuggestionContext
882+
useCreateSuggestionContext,
882883
} from 'react-admin';
883884

885+
import CloseIcon from '@mui/icons-material/Close';
884886
import {
885887
Box,
886888
BoxProps,
887889
Button,
888890
Dialog,
889-
DialogActions,
890891
DialogContent,
891-
TextField,
892+
IconButton,
892893
} from '@mui/material';
893894

894895
const PostCreate = () => {
@@ -906,43 +907,42 @@ const PostCreate = () => {
906907

907908
const CreateCategory = () => {
908909
const { filter, onCancel, onCreate } = useCreateSuggestionContext();
909-
const [value, setValue] = React.useState(filter || '');
910-
const [create] = useCreate();
911-
912-
const handleSubmit = event => {
913-
event.preventDefault();
914-
create(
915-
'categories',
916-
{
917-
data: {
918-
title: value,
919-
},
920-
},
921-
{
922-
onSuccess: (data) => {
923-
setValue('');
924-
onCreate(data);
925-
},
926-
}
927-
);
910+
911+
const onCategoryCreate = category => {
912+
onCreate(category);
928913
};
929914

915+
930916
return (
931917
<Dialog open onClose={onCancel}>
932-
<form onSubmit={handleSubmit}>
933-
<DialogContent>
934-
<TextField
935-
label="New category name"
936-
value={value}
937-
onChange={event => setValue(event.target.value)}
938-
autoFocus
939-
/>
940-
</DialogContent>
941-
<DialogActions>
942-
<Button type="submit">Save</Button>
943-
<Button onClick={onCancel}>Cancel</Button>
944-
</DialogActions>
945-
</form>
918+
<DialogTitle sx={{ m: 0, p: 2 }}>Create Category</DialogTitle>
919+
<IconButton
920+
aria-label="close"
921+
onClick={onCancel}
922+
sx={theme => ({
923+
position: 'absolute',
924+
right: 8,
925+
top: 8,
926+
color: theme.palette.grey[500],
927+
})}
928+
>
929+
<CloseIcon />
930+
</IconButton>>
931+
<DialogContent sx={{ p: 0 }}>
932+
<CreateBase
933+
redirect={false}
934+
resource="categories"
935+
mutationOptions={{
936+
onSuccess: category => {
937+
onCategoryCreate(category);
938+
},
939+
}}
940+
>
941+
<SimpleForm defaultValues={{ title: filter }}>
942+
<TextInput source="name" helperText={false} autoFocus/>
943+
</SimpleForm>
944+
</CreateBase>
945+
</DialogContent>
946946
</Dialog>
947947
);
948948
};

packages/ra-ui-materialui/src/input/AutocompleteInput.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ const CreateAuthor = () => {
853853
<DialogContent sx={{ p: 0 }}>
854854
<CreateBase
855855
redirect={false}
856-
resource="author"
856+
resource="authors"
857857
mutationOptions={{
858858
onSuccess: author => {
859859
onAuthorCreate(author);

0 commit comments

Comments
 (0)