-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
151 additions
and
11 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
packages/client/modules/userDashboard/components/OrgTeamMembers/OrgTeamMemberMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Menu ariaLabel={'Select your action'} {...menuProps}> | ||
{isViewerTeamAdmin && (!isSelf || !isViewerLead) && ( | ||
<MenuItem | ||
label={<StyledLabel>Promote {preferredName} to Team Lead</StyledLabel>} | ||
key='promote' | ||
onClick={togglePromote} | ||
/> | ||
)} | ||
{isViewerTeamAdmin && !isSelf && ( | ||
<MenuItem | ||
label={<StyledLabel>Remove {preferredName} from Team</StyledLabel>} | ||
onClick={toggleRemove} | ||
/> | ||
)} | ||
</Menu> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters