Refactor member progress

fix/team-members
Kamran Ahmed 2 months ago
parent 77061ac543
commit 7dd04df1c8
  1. 4
      src/components/TeamMembers/TeamMemberItem.tsx
  2. 25
      src/components/TeamMembers/TeamMembersPage.tsx
  3. 73
      src/components/TeamProgress/TeamProgressPage.tsx

@ -12,6 +12,7 @@ type TeamMemberProps = {
userId: string; userId: string;
index: number; index: number;
teamId: string; teamId: string;
canViewProgress: boolean;
canManageCurrentTeam: boolean; canManageCurrentTeam: boolean;
onDeleteMember: () => void; onDeleteMember: () => void;
onUpdateMember: () => void; onUpdateMember: () => void;
@ -29,11 +30,12 @@ export function TeamMemberItem(props: TeamMemberProps) {
userId, userId,
onDeleteMember, onDeleteMember,
onSendProgressReminder, onSendProgressReminder,
canViewProgress = true,
} = props; } = props;
const currentTeam = useStore($currentTeam); const currentTeam = useStore($currentTeam);
const canManageTeam = useStore($canManageCurrentTeam); const canManageTeam = useStore($canManageCurrentTeam);
const showNoProgressBadge = !member.hasProgress && member.status === 'joined'; const showNoProgressBadge = canViewProgress && !member.hasProgress && member.status === 'joined';
const allowProgressReminder = const allowProgressReminder =
canManageTeam && canManageTeam &&
!member.hasProgress && !member.hasProgress &&

@ -146,25 +146,13 @@ export function TeamMembersPage() {
toast.success('Reminder has been sent'); toast.success('Reminder has been sent');
} }
const enrichedMembers = teamMembers.map((member) => { const joinedMembers = teamMembers.filter(
const shouldNotShowProgressWarning =
team?.personalProgressOnly &&
!canManageCurrentTeam &&
member.userId !== user?.id;
return {
...member,
...(shouldNotShowProgressWarning ? { hasProgress: true } : {}),
};
});
const joinedMembers = enrichedMembers.filter(
(member) => member.status === 'joined', (member) => member.status === 'joined',
); );
const invitedMembers = enrichedMembers.filter( const invitedMembers = teamMembers.filter(
(member) => member.status === 'invited', (member) => member.status === 'invited',
); );
const rejectedMembers = enrichedMembers.filter( const rejectedMembers = teamMembers.filter(
(member) => member.status === 'rejected', (member) => member.status === 'rejected',
); );
@ -217,6 +205,11 @@ export function TeamMembersPage() {
index={index} index={index}
teamId={teamId} teamId={teamId}
userId={user?.id!} userId={user?.id!}
canViewProgress={
canManageCurrentTeam ||
!team?.personalProgressOnly ||
String(member.userId) === user?.id
}
onResendInvite={() => { onResendInvite={() => {
resendInvite(teamId, member._id!).finally(() => { resendInvite(teamId, member._id!).finally(() => {
pageProgressMessage.set(''); pageProgressMessage.set('');
@ -253,6 +246,7 @@ export function TeamMembersPage() {
index={index} index={index}
teamId={teamId} teamId={teamId}
userId={user?.id!} userId={user?.id!}
canViewProgress={false}
onResendInvite={() => { onResendInvite={() => {
resendInvite(teamId, member._id!).finally(() => { resendInvite(teamId, member._id!).finally(() => {
pageProgressMessage.set(''); pageProgressMessage.set('');
@ -292,6 +286,7 @@ export function TeamMembersPage() {
member={member} member={member}
index={index} index={index}
teamId={teamId} teamId={teamId}
canViewProgress={false}
userId={user?.id!} userId={user?.id!}
onResendInvite={() => { onResendInvite={() => {
resendInvite(teamId, member._id!).finally(() => { resendInvite(teamId, member._id!).finally(() => {

@ -10,6 +10,7 @@ import { getUrlParams, setUrlParams } from '../../lib/browser';
import { useAuth } from '../../hooks/use-auth'; import { useAuth } from '../../hooks/use-auth';
import { MemberProgressModal } from './MemberProgressModal'; import { MemberProgressModal } from './MemberProgressModal';
import { MemberCustomProgressModal } from './MemberCustomProgressModal'; import { MemberCustomProgressModal } from './MemberCustomProgressModal';
import { canManageCurrentRoadmap } from '../../stores/roadmap.ts';
export type UserProgress = { export type UserProgress = {
resourceTitle: string; resourceTitle: string;
@ -81,28 +82,15 @@ export function TeamProgressPage() {
} }
setTeamMembers( setTeamMembers(
response response.sort((a, b) => {
.filter((member) => { if (a.email === user?.email) {
// If personal progress only is enabled, only show the current user's progress return -1;
// and only if the user is a member }
if ( if (b.email === user?.email) {
currentTeam?.personalProgressOnly && return 1;
currentTeam?.role === 'member' }
) { return 0;
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;
}),
); );
} }
@ -236,21 +224,32 @@ export function TeamProgressPage() {
)} )}
{selectedGrouping === 'member' && ( {selectedGrouping === 'member' && (
<div className="grid gap-4 sm:grid-cols-2"> <div className="grid gap-4 sm:grid-cols-2">
{teamMembers.map((member) => ( {teamMembers.map((member) => {
<MemberProgressItem const canViewMemberProgress =
key={member._id} currentTeam?.role !== 'member' ||
member={member} !currentTeam?.personalProgressOnly ||
teamId={teamId} member.email === user?.email;
isMyProgress={member?.email === user?.email}
onShowResourceProgress={(resourceId, isCustomResource) => { if (!canViewMemberProgress) {
setShowMemberProgress({ return null;
resourceId, }
member,
isCustomResource, return (
}); <MemberProgressItem
}} key={member._id}
/> member={member}
))} teamId={teamId}
isMyProgress={member?.email === user?.email}
onShowResourceProgress={(resourceId, isCustomResource) => {
setShowMemberProgress({
resourceId,
member,
isCustomResource,
});
}}
/>
);
})}
</div> </div>
)} )}
</div> </div>

Loading…
Cancel
Save