@@ -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 ( '' ) ;
@@ -96,7 +96,7 @@ function Invitation() {
9696 return null ;
9797 }
9898 } ;
99-
99+
100100 // Fetch invitation statistics
101101 const {
102102 loading : isLoading ,
@@ -105,42 +105,41 @@ function Invitation() {
105105 } = useQuery ( GET_INVITATIONS_STATISTICS_QUERY , {
106106 variables : {
107107 orgToken : organizationToken ,
108- daysRange :
109- filterRange !== 'Custom range' ? parseRange ( filterRange ) : null ,
108+ daysRange : filterRange !== 'Custom range' ? parseRange ( filterRange ) : null ,
110109 startDate : filterRange === 'Custom range' ? customRange . startDate : null ,
111110 endDate : filterRange === 'Custom range' ? customRange . endDate : null ,
112111 } ,
113112 skip : ! organizationToken ,
114113 fetchPolicy : 'network-only' ,
115114 onError : ( error ) => toast . error ( 'Error fetching data' ) ,
116115 } ) ;
117-
116+
118117 // Fetch all invitations
119118 const {
120119 data,
121120 loading : queryLoading ,
122121 error : queryError ,
123122 refetch,
124123 } = useQuery ( GET_ALL_INVITATIONS , {
125- variables :{
124+ variables : {
126125 orgToken : organizationToken ,
127126 } ,
128127 fetchPolicy : 'network-only' ,
129128 } ) ;
130-
129+
131130 useEffect ( ( ) => {
132131 if ( invitationStats ) {
133132 setSelectedStatus ( invitationStats ) ; // Set the fetched status as the default value
134133 }
135134 } , [ invitationStats ] ) ;
136-
135+
137136 // Set email and role when modal opens
138137 useEffect ( ( ) => {
139138 if ( data && data . getAllInvitations ) {
140139 const invitation = data . getAllInvitations . invitations . find (
141140 ( inv : Invitationn ) => inv . id === selectedInvitationId ,
142141 ) ;
143-
142+
144143 if ( invitation && invitation . invitees . length > 0 ) {
145144 setEmail ( invitation . invitees [ 0 ] . email ) ;
146145 setRole ( invitation . invitees [ 0 ] . role ) ;
@@ -171,60 +170,65 @@ function Invitation() {
171170 setInvitationStats ( queryData . getInvitationStatistics ) ;
172171 }
173172 } , [ queryData , refreshData , isLoading ] ) ;
174-
173+
175174 // Handle the range change
176175 const handleRangeChange = ( e : React . ChangeEvent < HTMLSelectElement > ) => {
177176 setFilterRange ( e . target . value ) ;
178177 } ;
179-
178+
180179 // Handle custom date range
181180 const handleCustomRangeChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
182181 const { name, value } = e . target ;
183182 setCustomRange ( ( prev ) => ( { ...prev , [ name ] : value } ) ) ;
184183 } ;
185-
184+
186185 if ( ! organizationToken ) {
187186 return < p > Organization token not found. Please log in.</ p > ;
188187 }
189-
188+
190189 const updateInviteeMod = ( ) => {
191190 const newState = ! updateInviteeModel ;
192191 setUpdateInviteeModel ( newState ) ;
193192 } ;
194-
193+
195194 const [
196195 fetchInvitations ,
197196 { data : searchData , loading : searchLoading , error : searchError } ,
198197 ] = useLazyQuery ( GET_INVITATIONS , {
199198 variables : {
200- query : searchQuery ,
201- orgToken : organizationToken ,
202- } ,
199+ query : searchQuery ,
200+ orgToken : organizationToken ,
201+ } ,
203202 fetchPolicy : 'network-only' ,
204203 } ) ;
205-
204+
206205 const [
207206 filterInvitations ,
208207 { data : filterData , loading : filterLoad , error : filterError } ,
209208 ] = useLazyQuery ( GET_ROLES_AND_STATUSES , {
210- variables :filterVariables ,
211209 fetchPolicy : 'network-only' ,
212210 } ) ;
213-
211+
214212 useEffect ( ( ) => {
215213 if ( filterVariables . role || filterVariables . status ) {
216- filterInvitations ( ) ;
214+ filterInvitations ( {
215+ variables : {
216+ role : filterVariables . role || null ,
217+ status : typeof filterVariables . status === 'string' ? filterVariables . status : null ,
218+ orgToken : organizationToken ,
219+ } ,
220+ } ) ;
217221 }
218- } , [ filterVariables , filterInvitations ] ) ;
219-
222+ } , [ filterVariables , filterInvitations , organizationToken ] ) ;
223+
220224 // Consolidated effect to handle query and search data
221225 useEffect ( ( ) => {
222226 if ( queryLoading || searchLoading || filterLoad ) {
223227 setLoading ( true ) ;
224228 } else {
225229 setLoading ( false ) ;
226230 }
227-
231+
228232 if ( queryError ) {
229233 setError ( queryError . message ) ;
230234 } else if ( searchError ) {
@@ -254,57 +258,60 @@ function Invitation() {
254258 filterLoad ,
255259 filterError ,
256260 ] ) ;
257-
261+
258262 const handleSearch = ( ) => {
259263 if ( ! searchQuery . trim ( ) ) {
260264 setError ( 'Search query cannot be empty' ) ;
261265 return ;
262266 }
263-
267+
264268 setInvitations ( [ ] ) ;
265269 setError ( null ) ;
266270 setLoading ( false ) ;
267-
271+
268272 fetchInvitations ( { variables : { query : searchQuery } } ) ;
269273 } ;
270-
274+
271275 const handleFilter = ( ) => {
272276 if ( ! selectedRole && ! selectedStatus ) {
273277 toast . info ( 'Please select role or status.' ) ;
274278 return ;
275279 }
276-
280+
277281 setInvitations ( [ ] ) ;
278282 setError ( null ) ;
279283 setLoading ( false ) ;
280-
281- setFilterVariables ( { role : selectedRole , status : selectedStatus } ) ;
284+
285+ setFilterVariables ( {
286+ role : selectedRole ,
287+ status : typeof selectedStatus === 'string' ? selectedStatus : '' ,
288+ } ) ;
282289 } ;
283-
290+
284291 const toggleOptions = ( row : string ) => {
285292 setSelectedRow ( selectedRow === row ? null : row ) ;
286293 } ;
287-
294+
288295 const disabledSearch = ! searchQuery . trim ( ) ;
289-
296+
290297 interface EmailInputProps {
291298 email : string ;
292299 setEmail : ( email : string ) => void ;
293300 }
294-
301+
295302 const validateEmail = ( email : string ) : boolean => {
296303 const emailRegex = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ; // Simple email validation regex
297304 const isValidEmail = emailRegex . test ( email ) ;
298305 setIsValid ( isValidEmail ) ; // Update validation state
299306 return isValidEmail ;
300307 } ;
301-
308+
302309 const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
303310 const newEmail = e . target . value ;
304311 setEmail ( newEmail ) ;
305312 validateEmail ( newEmail ) ; // Validate on change
306313 } ;
307-
314+
308315 // Defining invitation table
309316 let content ;
310317 const capitalizeStrings = ( str : string ) : string => {
@@ -376,7 +383,7 @@ function Invitation() {
376383 </ div >
377384 </ div >
378385 </ div >
379-
386+
380387 { /* Conditionally render Cancel button */ }
381388 { row . original . Status === 'Pending' && (
382389 < div className = "mb-4" >
@@ -402,7 +409,7 @@ function Invitation() {
402409 </ div >
403410 </ div >
404411 ) }
405-
412+
406413 < div className = "mb-4" >
407414 < div
408415 className = "flex items-center p-2 rounded-md cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800"
@@ -426,7 +433,7 @@ function Invitation() {
426433 </ div >
427434 </ div >
428435 </ div >
429-
436+
430437 { row . original . Status === 'Pending' && (
431438 < div className = "mb-4" >
432439 < div className = "flex items-center p-2 rounded-md cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800" >
@@ -454,7 +461,7 @@ function Invitation() {
454461 ) ,
455462 } ,
456463 ] ;
457-
464+
458465 const datum : any = [ ] ;
459466 if ( invitations && invitations . length > 0 ) {
460467 invitations . forEach ( ( invitation ) => {
@@ -498,7 +505,7 @@ function Invitation() {
498505 </ >
499506 ) ;
500507 }
501-
508+
502509 const [ DeleteInvitation ] = useMutation ( DELETE_INVITATION , {
503510 variables : {
504511 invitationId : deleteInvitation ,
@@ -518,7 +525,7 @@ function Invitation() {
518525 } , 500 ) ;
519526 } ,
520527 } ) ;
521-
528+
522529 const handleOpenModal = ( ) => setIsModalOpen ( true ) ;
523530 const handleCloseModal = ( ) => {
524531 setIsModalOpen ( false ) ;
@@ -548,7 +555,7 @@ function Invitation() {
548555 } , 500 ) ;
549556 } ,
550557 } ) ;
551-
558+
552559 const [ CancelInvitation ] = useMutation ( CANCEL_INVITATION , {
553560 variables : {
554561 id : cancelInvitation ,
0 commit comments