@@ -60,12 +60,12 @@ function Invitation() {
6060 const newState = ! removeInviteeModel ;
6161 setRemoveInviteeModel ( newState ) ;
6262 } ;
63-
63+
6464 const cancelInviteeMod = ( ) => {
6565 const newState = ! cancelInviteeModel ;
6666 setCancelInviteeModel ( newState ) ;
6767 } ;
68-
68+
6969 const [ selectedRow , setSelectedRow ] = useState < string | null > ( null ) ;
7070 const [ removeInviteeModel , setRemoveInviteeModel ] = useState ( false ) ;
7171 const [ deleteInvitation , setDeleteInvitation ] = useState ( '' ) ;
@@ -80,7 +80,7 @@ function Invitation() {
8080 role : '' ,
8181 status : '' ,
8282 } ) ;
83-
83+
8484 const organizationToken = localStorage . getItem ( 'orgToken' ) ;
8585
8686 const parseRange = ( range : string ) => {
@@ -95,7 +95,7 @@ function Invitation() {
9595 return null ;
9696 }
9797 } ;
98-
98+
9999 // Fetch invitation statistics
100100 const {
101101 loading : isLoading ,
@@ -104,49 +104,48 @@ function Invitation() {
104104 } = useQuery ( GET_INVITATIONS_STATISTICS_QUERY , {
105105 variables : {
106106 orgToken : organizationToken ,
107- daysRange :
108- filterRange !== 'Custom range' ? parseRange ( filterRange ) : null ,
107+ daysRange : filterRange !== 'Custom range' ? parseRange ( filterRange ) : null ,
109108 startDate : filterRange === 'Custom range' ? customRange . startDate : null ,
110109 endDate : filterRange === 'Custom range' ? customRange . endDate : null ,
111110 } ,
112111 skip : ! organizationToken ,
113112 fetchPolicy : 'network-only' ,
114113 onError : ( error ) => toast . error ( 'Error fetching data' ) ,
115114 } ) ;
116-
115+
117116 // Fetch all invitations
118117 const {
119118 data,
120119 loading : queryLoading ,
121120 error : queryError ,
122121 refetch,
123122 } = useQuery ( GET_ALL_INVITATIONS , {
124- variables :{
123+ variables : {
125124 orgToken : organizationToken ,
126125 } ,
127126 fetchPolicy : 'network-only' ,
128127 } ) ;
129-
128+
130129 useEffect ( ( ) => {
131130 if ( invitationStats ) {
132131 setSelectedStatus ( invitationStats ) ; // Set the fetched status as the default value
133132 }
134133 } , [ invitationStats ] ) ;
135-
134+
136135 // Set email and role when modal opens
137136 useEffect ( ( ) => {
138137 if ( data && data . getAllInvitations ) {
139138 const invitation = data . getAllInvitations . invitations . find (
140139 ( inv : Invitationn ) => inv . id === selectedInvitationId ,
141140 ) ;
142-
141+
143142 if ( invitation && invitation . invitees . length > 0 ) {
144143 setEmail ( invitation . invitees [ 0 ] . email ) ;
145144 setRole ( invitation . invitees [ 0 ] . role ) ;
146145 }
147146 }
148147 } , [ data , selectedInvitationId ] ) ;
149-
148+
150149 useEffect ( ( ) => {
151150 if ( isLoading ) {
152151 setFilterLoading ( true ) ;
@@ -158,60 +157,65 @@ function Invitation() {
158157 setInvitationStats ( queryData . getInvitationStatistics ) ;
159158 }
160159 } , [ queryData , refreshData , isLoading ] ) ;
161-
160+
162161 // Handle the range change
163162 const handleRangeChange = ( e : React . ChangeEvent < HTMLSelectElement > ) => {
164163 setFilterRange ( e . target . value ) ;
165164 } ;
166-
165+
167166 // Handle custom date range
168167 const handleCustomRangeChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
169168 const { name, value } = e . target ;
170169 setCustomRange ( ( prev ) => ( { ...prev , [ name ] : value } ) ) ;
171170 } ;
172-
171+
173172 if ( ! organizationToken ) {
174173 return < p > Organization token not found. Please log in.</ p > ;
175174 }
176-
175+
177176 const updateInviteeMod = ( ) => {
178177 const newState = ! updateInviteeModel ;
179178 setUpdateInviteeModel ( newState ) ;
180179 } ;
181-
180+
182181 const [
183182 fetchInvitations ,
184183 { data : searchData , loading : searchLoading , error : searchError } ,
185184 ] = useLazyQuery ( GET_INVITATIONS , {
186185 variables : {
187- query : searchQuery ,
188- orgToken : organizationToken ,
189- } ,
186+ query : searchQuery ,
187+ orgToken : organizationToken ,
188+ } ,
190189 fetchPolicy : 'network-only' ,
191190 } ) ;
192-
191+
193192 const [
194193 filterInvitations ,
195194 { data : filterData , loading : filterLoad , error : filterError } ,
196195 ] = useLazyQuery ( GET_ROLES_AND_STATUSES , {
197- variables :filterVariables ,
198196 fetchPolicy : 'network-only' ,
199197 } ) ;
200-
198+
201199 useEffect ( ( ) => {
202200 if ( filterVariables . role || filterVariables . status ) {
203- filterInvitations ( ) ;
201+ filterInvitations ( {
202+ variables : {
203+ role : filterVariables . role || null ,
204+ status : typeof filterVariables . status === 'string' ? filterVariables . status : null ,
205+ orgToken : organizationToken ,
206+ } ,
207+ } ) ;
204208 }
205- } , [ filterVariables , filterInvitations ] ) ;
206-
209+ } , [ filterVariables , filterInvitations , organizationToken ] ) ;
210+
207211 // Consolidated effect to handle query and search data
208212 useEffect ( ( ) => {
209213 if ( queryLoading || searchLoading || filterLoad ) {
210214 setLoading ( true ) ;
211215 } else {
212216 setLoading ( false ) ;
213217 }
214-
218+
215219 if ( queryError ) {
216220 setError ( queryError . message ) ;
217221 } else if ( searchError ) {
@@ -241,57 +245,60 @@ function Invitation() {
241245 filterLoad ,
242246 filterError ,
243247 ] ) ;
244-
248+
245249 const handleSearch = ( ) => {
246250 if ( ! searchQuery . trim ( ) ) {
247251 setError ( 'Search query cannot be empty' ) ;
248252 return ;
249253 }
250-
254+
251255 setInvitations ( [ ] ) ;
252256 setError ( null ) ;
253257 setLoading ( false ) ;
254-
258+
255259 fetchInvitations ( { variables : { query : searchQuery } } ) ;
256260 } ;
257-
261+
258262 const handleFilter = ( ) => {
259263 if ( ! selectedRole && ! selectedStatus ) {
260264 toast . info ( 'Please select role or status.' ) ;
261265 return ;
262266 }
263-
267+
264268 setInvitations ( [ ] ) ;
265269 setError ( null ) ;
266270 setLoading ( false ) ;
267-
268- setFilterVariables ( { role : selectedRole , status : selectedStatus } ) ;
271+
272+ setFilterVariables ( {
273+ role : selectedRole ,
274+ status : typeof selectedStatus === 'string' ? selectedStatus : '' ,
275+ } ) ;
269276 } ;
270-
277+
271278 const toggleOptions = ( row : string ) => {
272279 setSelectedRow ( selectedRow === row ? null : row ) ;
273280 } ;
274-
281+
275282 const disabledSearch = ! searchQuery . trim ( ) ;
276-
283+
277284 interface EmailInputProps {
278285 email : string ;
279286 setEmail : ( email : string ) => void ;
280287 }
281-
288+
282289 const validateEmail = ( email : string ) : boolean => {
283290 const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ; // Simple email validation regex
284291 const isValidEmail = emailRegex . test ( email ) ;
285292 setIsValid ( isValidEmail ) ; // Update validation state
286293 return isValidEmail ;
287294 } ;
288-
295+
289296 const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
290297 const newEmail = e . target . value ;
291298 setEmail ( newEmail ) ;
292299 validateEmail ( newEmail ) ; // Validate on change
293300 } ;
294-
301+
295302 // Defining invitation table
296303 let content ;
297304 const capitalizeStrings = ( str : string ) : string => {
@@ -361,7 +368,7 @@ function Invitation() {
361368 </ div >
362369 </ div >
363370 </ div >
364-
371+
365372 { /* Conditionally render Cancel button */ }
366373 { row . original . Status === 'Pending' && (
367374 < div className = "mb-4" >
@@ -387,7 +394,7 @@ function Invitation() {
387394 </ div >
388395 </ div >
389396 ) }
390-
397+
391398 < div className = "mb-4" >
392399 < div
393400 className = "flex items-center hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-md cursor-pointer"
@@ -411,7 +418,7 @@ function Invitation() {
411418 </ div >
412419 </ div >
413420 </ div >
414-
421+
415422 { row . original . Status === 'Pending' && (
416423 < div className = "mb-4" >
417424 < div className = "flex items-center hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded-md cursor-pointer" >
@@ -439,7 +446,7 @@ function Invitation() {
439446 ) ,
440447 } ,
441448 ] ;
442-
449+
443450 const datum : any = [ ] ;
444451 if ( invitations && invitations . length > 0 ) {
445452 invitations . forEach ( ( invitation ) => {
@@ -483,7 +490,7 @@ function Invitation() {
483490 </ >
484491 ) ;
485492 }
486-
493+
487494 const [ DeleteInvitation ] = useMutation ( DELETE_INVITATION , {
488495 variables : {
489496 invitationId : deleteInvitation ,
@@ -503,7 +510,7 @@ function Invitation() {
503510 } , 500 ) ;
504511 } ,
505512 } ) ;
506-
513+
507514 const handleOpenModal = ( ) => setIsModalOpen ( true ) ;
508515 const handleCloseModal = ( ) => {
509516 setIsModalOpen ( false ) ;
@@ -533,7 +540,7 @@ function Invitation() {
533540 } , 500 ) ;
534541 } ,
535542 } ) ;
536-
543+
537544 const [ CancelInvitation ] = useMutation ( CANCEL_INVITATION , {
538545 variables : {
539546 id : cancelInvitation ,
0 commit comments