import Box from '@material-ui/core/Box' ; import Dialog from '@material-ui/core/Dialog' ; import promiseToast from '../Utils/promiseToast' ; import Form from '@rjsf/material-ui' ; import { getBaseURL } from '../Helpers' ; const URL = getBaseURL ( ) ; interface IPostRequestDialog { open : boolean ; getCreateSchema ? : any ; selectedItem : string ; handleGetRowData ( ) : void ; handleCloseDialog ( ) : void ; } export default function PostRequestDialog ( props ) { const handlePost = ( allData ) => { const requestOptions = { method : 'POST' , headers : { 'Content-Type' : 'application/json' } , body : JSON . stringify ( allData . formData ) , } ; const fetchPromise = fetch ( `${ URL }/${ props . selectedItem }/` , requestOptions ) . then ( ( response ) => { if ( ! response . ok ) { throw Error ( response . statusText ) ; } return response ; } ) . finally ( ( ) => { props . handleCloseDialog ( ) ; props . handleGetRowData ( ) ; } ) ; promiseToast ( fetchPromise ) ; } ; return ( < div > < Dialog open = { props . open } onClose = { props . handleCloseDialog } maxWidth = "xs" > < Box padding = { 4 } marginBottom = { 0 } > < Form schema = { props . getCreateSchema ( ) } onSubmit = { handlePost } / > < /Box> < /Dialog> < /div>); }