@@ -3,7 +3,7 @@ import { useNotify } from '../useNotify';
3
3
import { useMutation } from '@apollo/client' ;
4
4
import type { ActionInput , ActionsType } from '@/types' ;
5
5
import { useComputePlatform } from '../compute-platform' ;
6
- import { CREATE_ACTION , DELETE_ACTION , UPDATE_ACTION } from '@/graphql/mutations/action ' ;
6
+ import { CREATE_ACTION , DELETE_ACTION , UPDATE_ACTION } from '@/graphql/mutations' ;
7
7
8
8
interface UseActionCrudParams {
9
9
onSuccess ?: ( ) => void ;
@@ -15,57 +15,33 @@ export const useActionCRUD = (params?: UseActionCrudParams) => {
15
15
const { refetch } = useComputePlatform ( ) ;
16
16
const notify = useNotify ( ) ;
17
17
18
- const handleError = ( title : string , message : string ) => {
19
- notify ( {
20
- title,
21
- message,
22
- type : 'error' ,
23
- target : 'notification' ,
24
- crdType : 'notification' ,
25
- } ) ;
18
+ const notifyUser = ( title : string , message : string , type : 'error' | 'success' ) => {
19
+ notify ( { title, message, type, target : 'notification' , crdType : 'notification' } ) ;
20
+ } ;
26
21
27
- if ( params ?. onError ) params . onError ( ) ;
22
+ const handleError = ( title : string , message : string ) => {
23
+ notifyUser ( title , message , 'error' ) ;
24
+ params ?. onError ?.( ) ;
28
25
} ;
29
26
30
27
const handleComplete = ( title : string , message : string ) => {
28
+ notifyUser ( title , message , 'success' ) ;
31
29
setDrawerItem ( null ) ;
32
30
refetch ( ) ;
33
- notify ( {
34
- title,
35
- message,
36
- type : 'success' ,
37
- target : 'notification' ,
38
- crdType : 'notification' ,
39
- } ) ;
40
-
41
- if ( params ?. onSuccess ) params . onSuccess ( ) ;
31
+ params ?. onSuccess ?.( ) ;
42
32
} ;
43
33
44
34
const [ createAction , cState ] = useMutation ( CREATE_ACTION , {
45
- onError : ( error ) => {
46
- handleError ( 'Create Action' , error . message ) ;
47
- } ,
48
- onCompleted : ( ) => {
49
- handleComplete ( 'Create Action' , 'successfully created' ) ;
50
- } ,
35
+ onError : ( error ) => handleError ( 'Create Action' , error . message ) ,
36
+ onCompleted : ( ) => handleComplete ( 'Create Action' , 'successfully created' ) ,
51
37
} ) ;
52
-
53
38
const [ updateAction , uState ] = useMutation ( UPDATE_ACTION , {
54
- onError : ( error ) => {
55
- handleError ( 'Update Action' , error . message ) ;
56
- } ,
57
- onCompleted : ( ) => {
58
- handleComplete ( 'Update Action' , 'successfully updated' ) ;
59
- } ,
39
+ onError : ( error ) => handleError ( 'Update Action' , error . message ) ,
40
+ onCompleted : ( ) => handleComplete ( 'Update Action' , 'successfully updated' ) ,
60
41
} ) ;
61
-
62
42
const [ deleteAction , dState ] = useMutation ( DELETE_ACTION , {
63
- onError : ( error ) => {
64
- handleError ( 'Delete Action' , error . message ) ;
65
- } ,
66
- onCompleted : ( ) => {
67
- handleComplete ( 'Delete Action' , 'successfully deleted' ) ;
68
- } ,
43
+ onError : ( error ) => handleError ( 'Delete Action' , error . message ) ,
44
+ onCompleted : ( ) => handleComplete ( 'Delete Action' , 'successfully deleted' ) ,
69
45
} ) ;
70
46
71
47
return {
0 commit comments