@@ -2,41 +2,45 @@ import * as React from 'react';
22import { Admin , AdminContext } from 'react-admin' ;
33
44import {
5+ CreateBase ,
6+ ListBase ,
7+ RecordContextProvider ,
58 Resource ,
9+ TestMemoryRouter ,
610 required ,
711 useCreate ,
8- useRecordContext ,
9- ListBase ,
1012 useListContext ,
11- RecordContextProvider ,
12- TestMemoryRouter ,
13+ useRecordContext ,
1314} from 'ra-core' ;
1415
16+ import AttributionIcon from '@mui/icons-material/Attribution' ;
17+ import CloseIcon from '@mui/icons-material/Close' ;
18+ import ExpandCircleDownIcon from '@mui/icons-material/ExpandCircleDown' ;
1519import {
20+ Box ,
21+ Button ,
1622 Dialog ,
17- DialogContent ,
1823 DialogActions ,
19- Button ,
24+ DialogContent ,
25+ DialogTitle ,
26+ IconButton ,
27+ InputAdornment ,
2028 Stack ,
2129 TextField ,
2230 Typography ,
23- Box ,
24- InputAdornment ,
2531} from '@mui/material' ;
26- import { useFormContext } from 'react-hook-form' ;
2732import fakeRestProvider from 'ra-data-fakerest' ;
2833import polyglotI18nProvider from 'ra-i18n-polyglot' ;
2934import englishMessages from 'ra-language-english' ;
30- import ExpandCircleDownIcon from '@mui/icons-material/ExpandCircleDown' ;
31- import AttributionIcon from '@mui/icons-material/Attribution' ;
35+ import { useFormContext } from 'react-hook-form' ;
3236
37+ import { useState } from 'react' ;
3338import { Create , Edit } from '../detail' ;
3439import { SimpleForm } from '../form' ;
3540import { AutocompleteInput , AutocompleteInputProps } from './AutocompleteInput' ;
3641import { ReferenceInput } from './ReferenceInput' ;
3742import { TextInput } from './TextInput' ;
3843import { useCreateSuggestionContext } from './useSupportCreateSuggestion' ;
39- import { useState } from 'react' ;
4044
4145export default { title : 'ra-ui-materialui/input/AutocompleteInput' } ;
4246
@@ -826,56 +830,42 @@ export const InsideReferenceInputWithError = () => (
826830
827831const CreateAuthor = ( ) => {
828832 const { filter, onCancel, onCreate } = useCreateSuggestionContext ( ) ;
829- const [ name , setName ] = React . useState ( filter || '' ) ;
830- const [ language , setLanguage ] = React . useState ( '' ) ;
831- const [ create ] = useCreate ( ) ;
832833
833- const handleSubmit = event => {
834- event . preventDefault ( ) ;
835- create (
836- 'authors' ,
837- {
838- data : {
839- name,
840- language,
841- } ,
842- } ,
843- {
844- onSuccess : data => {
845- setName ( '' ) ;
846- setLanguage ( '' ) ;
847- onCreate ( data ) ;
848- } ,
849- }
850- ) ;
834+ const onAuthorCreate = author => {
835+ onCreate ( author ) ;
851836 } ;
852837
853838 return (
854839 < Dialog open onClose = { onCancel } >
855- < form onSubmit = { handleSubmit } >
856- < DialogContent >
857- < Stack gap = { 4 } >
858- < TextField
859- name = "name"
860- label = "The author name"
861- value = { name }
862- onChange = { event => setName ( event . target . value ) }
863- autoFocus
864- />
865- < TextField
866- name = "language"
867- label = "The author language"
868- value = { language }
869- onChange = { event => setLanguage ( event . target . value ) }
870- autoFocus
871- />
872- </ Stack >
873- </ DialogContent >
874- < DialogActions >
875- < Button type = "submit" > Save</ Button >
876- < Button onClick = { onCancel } > Cancel</ Button >
877- </ DialogActions >
878- </ form >
840+ < DialogTitle sx = { { m : 0 , p : 2 } } > Create Author</ DialogTitle >
841+ < IconButton
842+ aria-label = "close"
843+ onClick = { onCancel }
844+ sx = { theme => ( {
845+ position : 'absolute' ,
846+ right : 8 ,
847+ top : 8 ,
848+ color : theme . palette . grey [ 500 ] ,
849+ } ) }
850+ >
851+ < CloseIcon />
852+ </ IconButton >
853+ < DialogContent sx = { { p : 0 } } >
854+ < CreateBase
855+ redirect = { false }
856+ resource = "author"
857+ mutationOptions = { {
858+ onSuccess : author => {
859+ onAuthorCreate ( author ) ;
860+ } ,
861+ } }
862+ >
863+ < SimpleForm defaultValues = { { name : filter } } >
864+ < TextInput source = "name" helperText = { false } />
865+ < TextInput source = "language" helperText = { false } />
866+ </ SimpleForm >
867+ </ CreateBase >
868+ </ DialogContent >
879869 </ Dialog >
880870 ) ;
881871} ;
0 commit comments