From a73feae86583c9f755857eff493e9285677c1faf Mon Sep 17 00:00:00 2001 From: Marcus Wermuth Date: Thu, 8 Feb 2024 09:11:15 +0100 Subject: [PATCH] Fixed Refresh after archiving team --- .../OrgTeamMembers/OrgTeamMemberMenu.tsx | 71 ++++++++++++++++++ .../OrgTeamMembers/OrgTeamMembers.tsx | 10 ++- .../OrgTeamMembers/OrgTeamMembersRow.tsx | 73 ++++++++++++++++--- .../client/mutations/ArchiveTeamMutation.ts | 8 ++ 4 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMemberMenu.tsx diff --git a/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMemberMenu.tsx b/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMemberMenu.tsx new file mode 100644 index 00000000000..7526eb55775 --- /dev/null +++ b/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMemberMenu.tsx @@ -0,0 +1,71 @@ +import styled from '@emotion/styled' +import React from 'react' +import graphql from 'babel-plugin-relay/macro' +import useAtmosphere from '~/hooks/useAtmosphere' +import {useFragment} from 'react-relay' +import {MenuProps} from '../../../../hooks/useMenu' +import Menu from '../../../../components/Menu' +import MenuItem from '../../../../components/MenuItem' +import MenuItemLabel from '../../../../components/MenuItemLabel' +import {OrgTeamMemberMenu_teamMember$key} from '../../../../__generated__/OrgTeamMemberMenu_teamMember.graphql' + +interface OrgTeamMemberMenuProps { + isLead: boolean + menuProps: MenuProps + isViewerLead: boolean + isViewerOrgAdmin: boolean + manageTeamMemberId?: string | null + teamMember: OrgTeamMemberMenu_teamMember$key + handleNavigate?: () => void + togglePromote: () => void + toggleRemove: () => void +} + +const StyledLabel = styled(MenuItemLabel)({ + padding: '4px 16px' +}) + +export const OrgTeamMemberMenu = (props: OrgTeamMemberMenuProps) => { + const { + isViewerLead, + isViewerOrgAdmin, + teamMember: teamMemberRef, + menuProps, + togglePromote, + toggleRemove + } = props + const teamMember = useFragment( + graphql` + fragment OrgTeamMemberMenu_teamMember on TeamMember { + isSelf + preferredName + userId + isLead + } + `, + teamMemberRef + ) + const atmosphere = useAtmosphere() + const {preferredName, userId} = teamMember + const {viewerId} = atmosphere + const isSelf = userId === viewerId + const isViewerTeamAdmin = isViewerLead || isViewerOrgAdmin + + return ( + + {isViewerTeamAdmin && (!isSelf || !isViewerLead) && ( + Promote {preferredName} to Team Lead} + key='promote' + onClick={togglePromote} + /> + )} + {isViewerTeamAdmin && !isSelf && ( + Remove {preferredName} from Team} + onClick={toggleRemove} + /> + )} + + ) +} diff --git a/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembers.tsx b/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembers.tsx index 8fd6b3ca16f..3fa502bf22a 100644 --- a/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembers.tsx +++ b/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembers.tsx @@ -25,6 +25,7 @@ const query = graphql` team(teamId: $teamId) { ...ArchiveTeam_team isLead + isOrgAdmin id name tier @@ -56,7 +57,7 @@ export const OrgTeamMembers = (props: Props) => { } = useDialogState() if (!team) return null - const {teamMembers} = team + const {isLead: isViewerLead, isOrgAdmin: isViewerOrgAdmin, teamMembers} = team return (
@@ -92,7 +93,12 @@ export const OrgTeamMembers = (props: Props) => {
{teamMembers.map((teamMember) => ( - + ))} diff --git a/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembersRow.tsx b/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembersRow.tsx index 3e132c89bdb..5bcc9ea48b7 100644 --- a/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembersRow.tsx +++ b/packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMembersRow.tsx @@ -7,17 +7,28 @@ import {AvatarFallback} from '../../../../ui/Avatar/AvatarFallback' import {AvatarImage} from '../../../../ui/Avatar/AvatarImage' import {Button} from '../../../../ui/Button/Button' import {MoreVert} from '@mui/icons-material' +import {OrgTeamMemberMenu} from './OrgTeamMemberMenu' +import {MenuPosition} from '../../../../hooks/useCoords' +import useMenu from '../../../../hooks/useMenu' +import PromoteTeamMemberModal from '../../../teamDashboard/components/PromoteTeamMemberModal/PromoteTeamMemberModal' +import RemoveTeamMemberModal from '../../../teamDashboard/components/RemoveTeamMemberModal/RemoveTeamMemberModal' +import useModal from '../../../../hooks/useModal' +import useAtmosphere from '../../../../hooks/useAtmosphere' type Props = { teamMemberRef: OrgTeamMembersRow_teamMember$key + isViewerLead: boolean + isViewerOrgAdmin: boolean } export const OrgTeamMembersRow = (props: Props) => { const {teamMemberRef} = props - const member = useFragment( + const teamMember = useFragment( graphql` fragment OrgTeamMembersRow_teamMember on TeamMember { + ...OrgTeamMemberMenu_teamMember id + userId picture preferredName isLead @@ -29,25 +40,49 @@ export const OrgTeamMembersRow = (props: Props) => { name } } + ...PromoteTeamMemberModal_teamMember + ...RemoveTeamMemberModal_teamMember } `, teamMemberRef ) - // const {togglePortal, originRef, menuPortal, menuProps} = useMenu(MenuPosition.UPPER_RIGHT) + const {isViewerLead, isViewerOrgAdmin} = props + const {id: isLead, isOrgAdmin, userId} = teamMember + + const atmosphere = useAtmosphere() + const {viewerId} = atmosphere + const isSelf = userId === viewerId + + const showMenuButton = + (isViewerOrgAdmin && !isLead) || + (isViewerLead && !isSelf && !isOrgAdmin) || + (!isViewerLead && isSelf) + + const {togglePortal, originRef, menuPortal, menuProps} = useMenu(MenuPosition.UPPER_RIGHT) + const { + closePortal: closePromote, + togglePortal: togglePromote, + modalPortal: portalPromote + } = useModal() + const { + closePortal: closeRemove, + togglePortal: toggleRemove, + modalPortal: portalRemove + } = useModal() return (
- - CN + + {teamMember.preferredName.substring(0, 2)}
- {member.preferredName}{' '} - {member.isLead ? ( + {teamMember.preferredName}{' '} + {teamMember.isLead ? ( Team Lead @@ -55,21 +90,41 @@ export const OrgTeamMembersRow = (props: Props) => {
Teams:
- {member.user.teams.map((team) => team.name).join(', ')} + {teamMember.user.teams.map((team) => team.name).join(', ')}
- + {menuPortal( + + )}
+ + {portalPromote()} + {portalRemove()}
) } diff --git a/packages/client/mutations/ArchiveTeamMutation.ts b/packages/client/mutations/ArchiveTeamMutation.ts index 15afd828d4b..218fdd0c7c1 100644 --- a/packages/client/mutations/ArchiveTeamMutation.ts +++ b/packages/client/mutations/ArchiveTeamMutation.ts @@ -30,6 +30,14 @@ graphql` activeMeetings { id } + organization { + allTeams { + id + } + viewerTeams { + id + } + } } teamTemplateIds }