11import React from 'react' ;
22import { useHistory } from 'react-router-dom' ;
3- import { CRUD_DELETE , useDelete , useTranslate } from 'ra-core' ;
3+ import { useTranslate } from 'ra-core' ;
44import { makeStyles } from '@material-ui/core/styles' ;
55import Button from '@material-ui/core/Button' ;
66import DeleteIcon from '@material-ui/icons/Delete' ;
7-
7+ import { useDataProvider , useTranslate } from 'ra-core' ;
88import { EditButton , TopToolbar } from 'react-admin' ;
99import { Show } from '../ui' ;
1010import { ApplicationDetails } from './ApplicationDetails' ;
@@ -35,6 +35,7 @@ const AppShowActions = ({
3535 const notify = useLayer7Notify ( ) ;
3636 const contentLabelClasses = useContentStyles ( ) ;
3737 const history = useHistory ( ) ;
38+ const dataProvider = useDataProvider ( ) ;
3839 const [ deleting , setDeleting ] = React . useState ( false ) ;
3940
4041 React . useEffect ( ( ) => {
@@ -48,7 +49,9 @@ const AppShowActions = ({
4849 React . useEffect ( ( ) => {
4950 if ( data && userContext ) {
5051 if (
52+ data . status !== 'APPLICATION_PENDING_APPROVAL' &&
5153 data . status !== 'EDIT_APPLICATION_PENDING_APPROVAL' &&
54+ data . status !== 'DELETE_APPLICATION_PENDING_APPROVAL' &&
5255 ! userContext . userDetails . developer
5356 ) {
5457 setCanDelete ( true ) ;
@@ -57,29 +60,44 @@ const AppShowActions = ({
5760 }
5861 }
5962 } , [ canDelete , data , userContext ] ) ;
60-
61- const [ deleteApplication ] = useDelete ( 'applications' , data ?. id , data , {
62- action : CRUD_DELETE ,
63- onSuccess : ( ) => {
64- notify (
65- 'resources.applications.notifications.delete_success' ,
66- 'info' ,
67- {
68- smart_count : 1 ,
63+ const notifyAndNavigate = ( ) => {
64+ setDeleting ( false ) ;
65+ notify ( 'resources.applications.notifications.delete_success' , 'info' ) ;
66+ history . push ( '/applications' ) ;
67+ } ;
68+ const deleteApplication = ( ) => {
69+ dataProvider . delete (
70+ 'applications' ,
71+ {
72+ id : data . id ,
73+ } ,
74+ {
75+ onFailure : error => {
76+ setDeleting ( false ) ;
77+ notify ( error || 'resources.applications.notifications.delete_error' ,
78+ 'error' ) ;
79+ } ,
80+ onSuccess : delData => {
81+ dataProvider . getOne (
82+ 'applications' ,
83+ {
84+ id : data . id ,
85+ } ,
86+ {
87+ onFailure : error => notifyAndNavigate ( error ) ,
88+ onSuccess : getData => {
89+ setDeleting ( false ) ;
90+ notify ( 'resources.applications.notifications.delete_request_success' ,
91+ 'info' ) ;
92+ history . go ( 0 ) ;
93+ }
94+ }
95+ ) ;
6996 }
70- ) ;
71- setDeleting ( false ) ;
72- history . push ( '/applications' ) ;
73- } ,
74- onFailure : error => {
75- setDeleting ( false ) ;
76- notify (
77- error || 'resources.applications.notifications.delete_error' ,
78- 'error'
79- ) ;
80- } ,
81- } ) ;
82-
97+ }
98+ ) ;
99+ } ;
100+
83101 const confirmDelete = event => {
84102 setDeleteConfirm ( true ) ;
85103 } ;
0 commit comments