@@ -77,9 +77,9 @@ const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
77
77
> ( [ ] ) ;
78
78
const [ teamUserOptsLoading , setTeamUserOptsLoading ] =
79
79
useState < boolean > ( false ) ;
80
- const [ currentPage , setCurrentPage ] = useState < number > ( 1 ) ;
81
- const [ totalPages , setTotalPages ] = useState < number > ( 1 ) ;
82
- const ITEMS_PER_PAGE = 5 ;
80
+ const [ currentInvitationPage , setCurrentInvitationPage ] = useState < number > ( 1 ) ;
81
+ const [ totalInvitationPages , setTotalInvitationPages ] = useState < number > ( 1 ) ;
82
+ const ITEMS_PER_INVITATION_PAGE = 5 ;
83
83
84
84
const userOrgDomain = useMemo ( ( ) => {
85
85
if ( ! user ?. email ) return "" ;
@@ -111,7 +111,7 @@ const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
111
111
112
112
113
113
setInviteEmail ( "" ) ;
114
- setCurrentPage ( 1 ) ;
114
+ setCurrentInvitationPage ( 1 ) ;
115
115
await fetchPendingInvitations ( ) ;
116
116
onDataChanged ( ) ;
117
117
} catch ( err ) {
@@ -125,11 +125,11 @@ const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
125
125
try {
126
126
setInvitationsLoading ( true ) ;
127
127
128
- const res = await api . getAllProjectInvitations ( project . projectID , page , ITEMS_PER_PAGE ) ;
128
+ const res = await api . getAllProjectInvitations ( project . projectID , page , ITEMS_PER_INVITATION_PAGE ) ;
129
129
130
130
131
131
setPendingInvitations ( res . data . invitations || [ ] ) ;
132
- setTotalPages ( Math . ceil ( res . data . total / ITEMS_PER_PAGE ) ) ;
132
+ setTotalInvitationPages ( Math . ceil ( res . data . total / ITEMS_PER_INVITATION_PAGE ) ) ;
133
133
} catch ( err ) {
134
134
handleGlobalError ( err ) ;
135
135
} finally {
@@ -252,7 +252,7 @@ const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
252
252
setLoading ( true ) ;
253
253
const res = await api . updateInvitationRole ( inviteID , role ) ;
254
254
255
- await fetchPendingInvitations ( currentPage ) ;
255
+ await fetchPendingInvitations ( currentInvitationPage ) ;
256
256
onDataChanged ( ) ;
257
257
} catch ( err ) {
258
258
handleGlobalError ( err ) ;
@@ -331,6 +331,9 @@ const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
331
331
} : {
332
332
project : Project ;
333
333
} ) => {
334
+ const [ currentTeamPage , setCurrentTeamPage ] = useState ( 1 ) ;
335
+ const ITEMS_PER_TEAM_PAGE = 5 ;
336
+
334
337
const projTeam : ProjectDisplayMember [ ] = [ ] ;
335
338
if ( project . leads && Array . isArray ( project . leads ) ) {
336
339
project . leads . forEach ( ( item ) => {
@@ -361,56 +364,74 @@ const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
361
364
} ) ;
362
365
}
363
366
const sortedTeam = sortUsersByName ( projTeam ) as ProjectDisplayMember [ ] ;
364
-
365
-
367
+
368
+ const totalTeamPages = Math . ceil ( sortedTeam . length / ITEMS_PER_TEAM_PAGE ) ;
369
+ const startIndex = ( currentTeamPage - 1 ) * ITEMS_PER_TEAM_PAGE ;
370
+ const paginatedTeam = sortedTeam . slice ( startIndex , startIndex + ITEMS_PER_TEAM_PAGE ) ;
371
+
366
372
return (
367
- < Table celled striped compact { ...rest } >
368
- < Table . Header >
369
- < Table . Row >
370
- < Table . HeaderCell width = { "7" } > Name</ Table . HeaderCell >
371
- < Table . HeaderCell width = { "2" } > Role</ Table . HeaderCell >
372
- < Table . HeaderCell width = { "1" } > Actions</ Table . HeaderCell >
373
- </ Table . Row >
374
- </ Table . Header >
375
- < Table . Body >
376
- { sortedTeam . map ( ( item ) => (
377
- < Table . Row key = { item . uuid } >
378
- < Table . Cell >
379
- < Image avatar src = { item . avatar } />
380
- { item . firstName } { item . lastName }
381
- </ Table . Cell >
382
- < Table . Cell >
383
- < Dropdown
384
- placeholder = "Change role..."
385
- selection
386
- options = { projectRoleOptions }
387
- value = { item . roleValue }
388
- loading = { loading }
389
- onChange = { ( _e , { value } ) => {
390
- submitChangeTeamMemberRole (
391
- item . uuid ,
392
- value ? value . toString ( ) : ""
393
- )
394
- } }
395
- />
396
- </ Table . Cell >
397
- < Table . Cell >
398
- < Button
399
- color = "red"
400
- className = "ml-1p"
401
- onClick = { ( ) => {
402
- submitRemoveTeamMember ( item . uuid ) ;
403
- } }
404
- icon
405
- >
406
- < Icon name = "remove circle" />
407
- < span className = "ml-2" > Remove</ span >
408
- </ Button >
409
- </ Table . Cell >
373
+ < >
374
+ < Table celled striped compact { ...rest } >
375
+ < Table . Header >
376
+ < Table . Row >
377
+ < Table . HeaderCell width = { "7" } > Name</ Table . HeaderCell >
378
+ < Table . HeaderCell width = { "2" } > Role</ Table . HeaderCell >
379
+ < Table . HeaderCell width = { "1" } > Actions</ Table . HeaderCell >
410
380
</ Table . Row >
411
- ) ) }
412
- </ Table . Body >
413
- </ Table >
381
+ </ Table . Header >
382
+ < Table . Body >
383
+ { paginatedTeam . map ( ( item ) => (
384
+ < Table . Row key = { item . uuid } >
385
+ < Table . Cell >
386
+ < Image avatar src = { item . avatar } />
387
+ { item . firstName } { item . lastName }
388
+ </ Table . Cell >
389
+ < Table . Cell >
390
+ < Dropdown
391
+ placeholder = "Change role..."
392
+ selection
393
+ options = { projectRoleOptions }
394
+ value = { item . roleValue }
395
+ loading = { loading }
396
+ onChange = { ( _e , { value } ) => {
397
+ submitChangeTeamMemberRole (
398
+ item . uuid ,
399
+ value ? value . toString ( ) : ""
400
+ )
401
+ } }
402
+ />
403
+ </ Table . Cell >
404
+ < Table . Cell >
405
+ < Button
406
+ color = "red"
407
+ className = "ml-1p"
408
+ onClick = { ( ) => {
409
+ submitRemoveTeamMember ( item . uuid ) ;
410
+ } }
411
+ icon
412
+ >
413
+ < Icon name = "remove circle" />
414
+ < span className = "ml-2" > Remove</ span >
415
+ </ Button >
416
+ </ Table . Cell >
417
+ </ Table . Row >
418
+ ) ) }
419
+ </ Table . Body >
420
+ </ Table >
421
+ { totalTeamPages > 1 && (
422
+ < div className = "flex justify-center mt-4" >
423
+ < Pagination
424
+ activePage = { currentTeamPage }
425
+ totalPages = { totalTeamPages }
426
+ onPageChange = { ( _e , { activePage } ) => {
427
+ setCurrentTeamPage ( Number ( activePage ) ) ;
428
+ } }
429
+ firstItem = { totalTeamPages > 2 ? undefined : null }
430
+ lastItem = { totalTeamPages > 2 ? undefined : null }
431
+ />
432
+ </ div >
433
+ ) }
434
+ </ >
414
435
) ;
415
436
} ;
416
437
@@ -477,17 +498,17 @@ const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
477
498
) }
478
499
</ Table . Body >
479
500
</ Table >
480
- { totalPages > 1 && (
501
+ { totalInvitationPages > 1 && (
481
502
< div className = "flex justify-center mt-4" >
482
503
< Pagination
483
- activePage = { currentPage }
484
- totalPages = { totalPages }
504
+ activePage = { currentInvitationPage }
505
+ totalPages = { totalInvitationPages }
485
506
onPageChange = { ( _e , { activePage } ) => {
486
- setCurrentPage ( Number ( activePage ) ) ;
507
+ setCurrentInvitationPage ( Number ( activePage ) ) ;
487
508
fetchPendingInvitations ( Number ( activePage ) ) ;
488
509
} }
489
- firstItem = { totalPages > 2 ? undefined : null }
490
- lastItem = { totalPages > 2 ? undefined : null }
510
+ firstItem = { totalInvitationPages > 2 ? undefined : null }
511
+ lastItem = { totalInvitationPages > 2 ? undefined : null }
491
512
/>
492
513
</ div >
493
514
) }
0 commit comments