From 5b541dfb3dbf452043b7f00424513e188e4d2d6c Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 28 Jul 2023 18:20:38 +0100 Subject: [PATCH] Updates to team functionality --- src/components/CreateTeam/RoleDropdown.tsx | 5 +-- .../TeamMembers/MemberActionDropdown.tsx | 40 +++++++++++++----- src/components/TeamMembers/TeamMemberItem.tsx | 42 +++++++++---------- .../TeamMembers/TeamMembersPage.tsx | 24 +++++------ .../TeamSettings/UpdateTeamForm.tsx | 8 +++- src/components/Toast.tsx | 2 +- 6 files changed, 70 insertions(+), 51 deletions(-) diff --git a/src/components/CreateTeam/RoleDropdown.tsx b/src/components/CreateTeam/RoleDropdown.tsx index 395e2517c..76174ddca 100644 --- a/src/components/CreateTeam/RoleDropdown.tsx +++ b/src/components/CreateTeam/RoleDropdown.tsx @@ -86,10 +86,7 @@ export function RoleDropdown(props: RoleDropdownProps) { }`} > + className={`capitalize`}> {selectedRole || 'Select Role'} void; onUpdateMember: () => void; onResendInvite: () => void; + onSendProgressReminder: () => void; isDisabled: boolean; + allowProgressReminder: boolean; + allowUpdateRole: boolean; member: TeamMemberDocument; }) { - const toast = useToast(); const menuRef = useRef(null); const [isOpen, setIsOpen] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -35,13 +40,28 @@ export function MemberActionDropdown({ setIsOpen(false); }, }, - { - name: 'Update Role', - handleClick: () => { - onUpdateMember(); - setIsOpen(false); - }, - }, + ...(allowUpdateRole + ? [ + { + name: 'Update Role', + handleClick: () => { + onUpdateMember(); + setIsOpen(false); + }, + }, + ] + : []), + ...(allowProgressReminder + ? [ + { + name: 'Send Progress Reminder', + handleClick: () => { + onSendProgressReminder(); + setIsOpen(false); + }, + }, + ] + : []), ...(['invited'].includes(member.status) ? [ { @@ -67,7 +87,7 @@ export function MemberActionDropdown({ {isOpen && (
    {actions.map((action, index) => { diff --git a/src/components/TeamMembers/TeamMemberItem.tsx b/src/components/TeamMembers/TeamMemberItem.tsx index 93e41a568..0670e0e83 100644 --- a/src/components/TeamMembers/TeamMemberItem.tsx +++ b/src/components/TeamMembers/TeamMemberItem.tsx @@ -2,6 +2,8 @@ import { MailIcon } from '../ReactIcons/MailIcon'; import { MemberActionDropdown } from './MemberActionDropdown'; import { MemberRoleBadge } from './RoleBadge'; import type { TeamMemberItem } from './TeamMembersPage'; +import { $canManageCurrentTeam } from '../../stores/team'; +import { useStore } from '@nanostores/preact'; type TeamMemberProps = { member: TeamMemberItem; @@ -9,9 +11,9 @@ type TeamMemberProps = { index: number; teamId: string; canManageCurrentTeam: boolean; - handleDeleteMember: () => void; + onDeleteMember: () => void; onUpdateMember: () => void; - handleSendReminder: () => void; + onSendProgressReminder: () => void; onResendInvite: () => void; }; @@ -23,16 +25,17 @@ export function TeamMemberItem(props: TeamMemberProps) { onUpdateMember, canManageCurrentTeam, userId, - handleDeleteMember, - handleSendReminder, + onDeleteMember, + onSendProgressReminder, } = props; - const showNoProgress = - member.progress.length === 0 && member.status === 'joined'; - const showReminder = - member.progress.length === 0 && + const canManageTeam = useStore($canManageCurrentTeam); + const showNoProgressBadge = !member.hasProgress && member.status === 'joined'; + const allowProgressReminder = + canManageTeam && + !member.hasProgress && member.status === 'joined' && - !(member.userId === userId); + member.userId !== userId; return (
    - {showReminder && ( - - )}

    {member.name} - {showNoProgress && ( - + {showNoProgressBadge && ( + No Progress )} @@ -91,18 +91,16 @@ export function TeamMemberItem(props: TeamMemberProps) {

    - {showReminder && ( - - - - )} {canManageCurrentTeam && ( - Reminder + Remind ); } diff --git a/src/components/TeamMembers/TeamMembersPage.tsx b/src/components/TeamMembers/TeamMembersPage.tsx index ea1153c15..c736fd4f2 100644 --- a/src/components/TeamMembers/TeamMembersPage.tsx +++ b/src/components/TeamMembers/TeamMembersPage.tsx @@ -1,6 +1,5 @@ import { useEffect, useState } from 'preact/hooks'; import { httpDelete, httpGet, httpPatch } from '../../lib/http'; -import { MemberActionDropdown } from './MemberActionDropdown'; import { useAuth } from '../../hooks/use-auth'; import { pageProgressMessage } from '../../stores/page'; import type { TeamDocument } from '../CreateTeam/CreateTeamForm'; @@ -13,7 +12,6 @@ import { UpdateMemberPopup } from './UpdateMemberPopup'; import { useStore } from '@nanostores/preact'; import { $canManageCurrentTeam } from '../../stores/team'; import { useToast } from '../../hooks/use-toast'; -import { MemberRoleBadge } from './RoleBadge'; import { TeamMemberItem } from './TeamMemberItem'; export interface TeamMemberDocument { @@ -43,7 +41,7 @@ export interface UserResourceProgressDocument { export interface TeamMemberItem extends TeamMemberDocument { name: string; avatar: string; - progress: UserResourceProgressDocument[]; + hasProgress: boolean; } export function TeamMembersPage() { @@ -187,7 +185,7 @@ export function TeamMembersPage() { /> )}
    -
    +

    {teamMembers.length} people in the team. @@ -211,7 +209,7 @@ export function TeamMembersPage() { }); }} canManageCurrentTeam={canManageCurrentTeam} - handleDeleteMember={() => { + onDeleteMember={() => { deleteMember(teamId, member._id!).finally(() => { pageProgressMessage.set(''); }); @@ -219,7 +217,7 @@ export function TeamMembersPage() { onUpdateMember={() => { setMemberToUpdate(member); }} - handleSendReminder={() => { + onSendProgressReminder={() => { handleSendReminder(teamId, member._id!).finally(() => { pageProgressMessage.set(''); }); @@ -231,8 +229,8 @@ export function TeamMembersPage() { {invitedMembers.length > 0 && (

    -

    Invited Members

    -
    +

    Invited Members

    +
    {invitedMembers.map((member, index) => { return ( { + onDeleteMember={() => { deleteMember(teamId, member._id!).finally(() => { pageProgressMessage.set(''); }); @@ -255,7 +253,7 @@ export function TeamMembersPage() { onUpdateMember={() => { setMemberToUpdate(member); }} - handleSendReminder={() => { + onSendProgressReminder={() => { handleSendReminder(teamId, member._id!).finally(() => { pageProgressMessage.set(''); }); @@ -269,7 +267,7 @@ export function TeamMembersPage() { {rejectedMembers.length > 0 && (
    -

    Rejected Members

    +

    Rejected Invites

    {rejectedMembers.map((member, index) => { return ( @@ -285,7 +283,7 @@ export function TeamMembersPage() { }); }} canManageCurrentTeam={canManageCurrentTeam} - handleDeleteMember={() => { + onDeleteMember={() => { deleteMember(teamId, member._id!).finally(() => { pageProgressMessage.set(''); }); @@ -293,7 +291,7 @@ export function TeamMembersPage() { onUpdateMember={() => { setMemberToUpdate(member); }} - handleSendReminder={() => { + onSendProgressReminder={() => { handleSendReminder(teamId, member._id!).finally(() => { pageProgressMessage.set(''); }); diff --git a/src/components/TeamSettings/UpdateTeamForm.tsx b/src/components/TeamSettings/UpdateTeamForm.tsx index 90fdbe0c5..2123856b3 100644 --- a/src/components/TeamSettings/UpdateTeamForm.tsx +++ b/src/components/TeamSettings/UpdateTeamForm.tsx @@ -141,10 +141,16 @@ export function UpdateTeamForm() { />
    -