From 77061ac5431bcc11be4489307b397d3de787a661 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Wed, 11 Sep 2024 19:40:28 +0600 Subject: [PATCH] fix: hide the team member progress --- .../TeamMembers/TeamMembersPage.tsx | 38 +++++++++++++------ .../TeamProgress/TeamProgressPage.tsx | 33 +++++++++++----- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/components/TeamMembers/TeamMembersPage.tsx b/src/components/TeamMembers/TeamMembersPage.tsx index 33b4c621e..e6ce94cd2 100644 --- a/src/components/TeamMembers/TeamMembersPage.tsx +++ b/src/components/TeamMembers/TeamMembersPage.tsx @@ -61,7 +61,7 @@ export function TeamMembersPage() { async function loadTeam() { const { response, error } = await httpGet( - `${import.meta.env.PUBLIC_API_URL}/v1-get-team/${teamId}` + `${import.meta.env.PUBLIC_API_URL}/v1-get-team/${teamId}`, ); if (error || !response) { toast.error(error?.message || 'Something went wrong'); @@ -75,7 +75,7 @@ export function TeamMembersPage() { async function getTeamMemberList() { const { response, error } = await httpGet( - `${import.meta.env.PUBLIC_API_URL}/v1-get-team-member-list/${teamId}` + `${import.meta.env.PUBLIC_API_URL}/v1-get-team-member-list/${teamId}`, ); if (error || !response) { toast.error(error?.message || 'Failed to load team member list'); @@ -100,7 +100,7 @@ export function TeamMembersPage() { `${ import.meta.env.PUBLIC_API_URL }/v1-delete-member/${teamId}/${memberId}`, - {} + {}, ); if (error || !response) { @@ -118,7 +118,7 @@ export function TeamMembersPage() { `${ import.meta.env.PUBLIC_API_URL }/v1-resend-invite/${teamId}/${memberId}`, - {} + {}, ); if (error || !response) { @@ -135,7 +135,7 @@ export function TeamMembersPage() { `${ import.meta.env.PUBLIC_API_URL }/v1-send-progress-reminder/${teamId}/${memberId}`, - {} + {}, ); if (error || !response) { @@ -146,14 +146,26 @@ export function TeamMembersPage() { toast.success('Reminder has been sent'); } - const joinedMembers = teamMembers.filter( - (member) => member.status === 'joined' + const enrichedMembers = teamMembers.map((member) => { + const shouldNotShowProgressWarning = + team?.personalProgressOnly && + !canManageCurrentTeam && + member.userId !== user?.id; + + return { + ...member, + ...(shouldNotShowProgressWarning ? { hasProgress: true } : {}), + }; + }); + + const joinedMembers = enrichedMembers.filter( + (member) => member.status === 'joined', ); - const invitedMembers = teamMembers.filter( - (member) => member.status === 'invited' + const invitedMembers = enrichedMembers.filter( + (member) => member.status === 'invited', ); - const rejectedMembers = teamMembers.filter( - (member) => member.status === 'rejected' + const rejectedMembers = enrichedMembers.filter( + (member) => member.status === 'rejected', ); return ( @@ -269,7 +281,9 @@ export function TeamMembersPage() { {rejectedMembers.length > 0 && (
-

Rejected Invites

+

+ Rejected Invites +

{rejectedMembers.map((member, index) => { return ( diff --git a/src/components/TeamProgress/TeamProgressPage.tsx b/src/components/TeamProgress/TeamProgressPage.tsx index 6f386d55e..70d4f096d 100644 --- a/src/components/TeamProgress/TeamProgressPage.tsx +++ b/src/components/TeamProgress/TeamProgressPage.tsx @@ -81,15 +81,28 @@ export function TeamProgressPage() { } setTeamMembers( - response.sort((a, b) => { - if (a.email === user?.email) { - return -1; - } - if (b.email === user?.email) { - return 1; - } - return 0; - }), + response + .filter((member) => { + // If personal progress only is enabled, only show the current user's progress + // and only if the user is a member + if ( + currentTeam?.personalProgressOnly && + currentTeam?.role === 'member' + ) { + return member.email === user?.email; + } + + return true; + }) + .sort((a, b) => { + if (a.email === user?.email) { + return -1; + } + if (b.email === user?.email) { + return 1; + } + return 0; + }), ); } @@ -191,7 +204,7 @@ export function TeamProgressPage() { key={grouping.value} className={`rounded-md border p-1 px-2 text-sm ${ selectedGrouping === grouping.value - ? ' border-gray-400 bg-gray-200 ' + ? 'border-gray-400 bg-gray-200' : '' }`} onClick={() => setSelectedGrouping(grouping.value)}