@@ -202,7 +202,7 @@ const CreateAuthor = () => {
202
202
< DialogContent sx= {{ p: 0 }}>
203
203
< CreateBase
204
204
redirect= {false }
205
- resource= " author "
205
+ resource= " authors "
206
206
mutationOptions= {{
207
207
onSuccess : author => {
208
208
onAuthorCreate (author);
@@ -874,21 +874,22 @@ Use the `create` prop when you want a more polished or complex UI. For example a
874
874
import {
875
875
AutocompleteInput ,
876
876
Create ,
877
+ CreateBase ,
877
878
ReferenceInput ,
878
879
SimpleForm ,
879
880
TextInput ,
880
881
useCreate ,
881
- useCreateSuggestionContext
882
+ useCreateSuggestionContext ,
882
883
} from ' react-admin' ;
883
884
885
+ import CloseIcon from ' @mui/icons-material/Close' ;
884
886
import {
885
887
Box ,
886
888
BoxProps ,
887
889
Button ,
888
890
Dialog ,
889
- DialogActions ,
890
891
DialogContent ,
891
- TextField ,
892
+ IconButton ,
892
893
} from ' @mui/material' ;
893
894
894
895
const PostCreate = () => {
@@ -906,43 +907,42 @@ const PostCreate = () => {
906
907
907
908
const CreateCategory = () => {
908
909
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);
928
913
};
929
914
915
+
930
916
return (
931
917
< 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>
946
946
< / Dialog>
947
947
);
948
948
};
0 commit comments