1
- import React , { useEffect , useState } from 'react' ;
1
+ import React from 'react' ;
2
2
import {
3
3
Box ,
4
4
CircularProgress ,
@@ -19,11 +19,7 @@ import {
19
19
AppealsType ,
20
20
TableViewModeEnum ,
21
21
} from '../../AppealsContext/AppealsContext' ;
22
- import {
23
- AppealContactsInfoFragment ,
24
- useAppealContactsQuery ,
25
- useDeleteAppealContactMutation ,
26
- } from './DeleteAppealContact.generated' ;
22
+ import { useDeleteAppealContactMutation } from './DeleteAppealContact.generated' ;
27
23
28
24
const LoadingIndicator = styled ( CircularProgress ) ( ( { theme } ) => ( {
29
25
margin : theme . spacing ( 0 , 1 , 0 , 0 ) ,
@@ -44,48 +40,9 @@ export const DeleteAppealContactModal: React.FC<
44
40
) as AppealsType ;
45
41
const [ deleteAppealContact , { loading : mutating } ] =
46
42
useDeleteAppealContactMutation ( ) ;
47
- const { data, fetchMore } = useAppealContactsQuery ( {
48
- variables : {
49
- appealId : appealId ?? '' ,
50
- } ,
51
- } ) ;
52
- const [ loading , setLoading ] = useState ( false ) ;
53
- const [ appealContactsIds , setAppealContactsIds ] = useState <
54
- AppealContactsInfoFragment [ ]
55
- > ( [ ] ) ;
56
-
57
- const loadAllAppealContacts = async ( ) => {
58
- let allContacts = data ?. appealContacts . nodes ?? [ ] ;
59
- let hasNextPage = true ;
60
- let cursor : string | null = null ;
61
-
62
- while ( hasNextPage ) {
63
- const response = await fetchMore ( {
64
- variables : {
65
- after : cursor ,
66
- } ,
67
- } ) ;
68
-
69
- const newContacts = response . data . appealContacts . nodes ;
70
- allContacts = [ ...allContacts , ...newContacts ] ;
71
- hasNextPage = response . data . appealContacts . pageInfo . hasNextPage ;
72
- cursor = response . data . appealContacts . pageInfo . endCursor ?? null ;
73
- }
74
-
75
- setAppealContactsIds ( allContacts ) ;
76
- setLoading ( false ) ;
77
- return allContacts ;
78
- } ;
79
-
80
- useEffect ( ( ) => {
81
- loadAllAppealContacts ( ) ;
82
- } , [ ] ) ;
83
43
84
44
const handleRemoveContact = async ( ) => {
85
- const appealContactId = appealContactsIds . find (
86
- ( appealContact ) => appealContact . contact . id === contactId ,
87
- ) ?. id ;
88
- if ( ! appealContactId ) {
45
+ if ( ! appealId ) {
89
46
enqueueSnackbar ( 'Error while removing contact from appeal.' , {
90
47
variant : 'error' ,
91
48
} ) ;
@@ -94,7 +51,8 @@ export const DeleteAppealContactModal: React.FC<
94
51
await deleteAppealContact ( {
95
52
variables : {
96
53
input : {
97
- id : appealContactId ,
54
+ contactId,
55
+ appealId,
98
56
} ,
99
57
} ,
100
58
update : ( cache ) => {
@@ -136,13 +94,13 @@ export const DeleteAppealContactModal: React.FC<
136
94
) }
137
95
</ DialogContent >
138
96
< DialogActions >
139
- < CancelButton onClick = { onClickDecline } disabled = { mutating || loading } >
97
+ < CancelButton onClick = { onClickDecline } disabled = { mutating } >
140
98
{ t ( 'No' ) }
141
99
</ CancelButton >
142
100
< SubmitButton
143
101
type = "button"
144
102
onClick = { handleRemoveContact }
145
- disabled = { mutating || loading }
103
+ disabled = { mutating }
146
104
>
147
105
{ t ( 'Yes' ) }
148
106
</ SubmitButton >
0 commit comments