-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: managing teams #9285
Merged
Merged
feat: managing teams #9285
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6225717
feat: managing teams
BartoszJarocki d97058a
feat: team members view
BartoszJarocki 97fed26
feat: use team name in team details
BartoszJarocki 5919989
fix: routing
BartoszJarocki 8e6020b
fix: some menus
BartoszJarocki 7cd6631
feat: added alert dialog component
BartoszJarocki 7496901
Added Delete Team Dialog
mwermuth 6d2bac8
Updated Delete Dialog label
mwermuth a73feae
Fixed Refresh after archiving team
mwermuth 1e45eb4
feat: As a SuperAdmin, I can remove team members
jordanh 8b84345
feat: As a SuperAdmin, I can remove team members
jordanh 5ec917c
chore: Refactor OrgMemberRow for readability
jordanh 7e568eb
chore: revert errant tsconfig.json change
jordanh 65f1b99
chore: revert add team members modal
jordanh c14c0ec
chore: code review fixups
jordanh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, {useState} from 'react' | ||
import FlatPrimaryButton from './FlatPrimaryButton' | ||
import {Input} from '../ui/Input/Input' | ||
import {Dialog} from '../ui/Dialog/Dialog' | ||
import {DialogContent} from '../ui/Dialog/DialogContent' | ||
import {DialogTitle} from '../ui/Dialog/DialogTitle' | ||
import {DialogActions} from '../ui/Dialog/DialogActions' | ||
import useMutationProps from '../hooks/useMutationProps' | ||
import SecondaryButton from './SecondaryButton' | ||
import ArchiveTeamMutation from '../mutations/ArchiveTeamMutation' | ||
import useAtmosphere from '../hooks/useAtmosphere' | ||
import useRouter from '../hooks/useRouter' | ||
|
||
interface Props { | ||
isOpen: boolean | ||
onClose: () => void | ||
onDeleteTeam: (teamId: string) => void | ||
teamId: string | ||
teamName: string | ||
teamOrgId: string | ||
} | ||
|
||
const DeleteTeamDialog = (props: Props) => { | ||
const atmosphere = useAtmosphere() | ||
const {history} = useRouter() | ||
const {isOpen, onClose, teamId, teamName, teamOrgId, onDeleteTeam} = props | ||
|
||
const {submitting, onCompleted, onError, error, submitMutation} = useMutationProps() | ||
|
||
const [typedTeamName, setTypedTeamName] = useState(false) | ||
|
||
const handleDeleteTeam = () => { | ||
if (submitting) return | ||
submitMutation() | ||
ArchiveTeamMutation(atmosphere, {teamId}, {history, onError, onCompleted}) | ||
onDeleteTeam(teamId) | ||
history.push(`/me/organizations/${teamOrgId}/teams`) | ||
} | ||
|
||
return ( | ||
<Dialog isOpen={isOpen} onClose={onClose}> | ||
<DialogContent className='z-10'> | ||
<DialogTitle className='mb-4'>Delete Team</DialogTitle> | ||
|
||
<fieldset className='mx-0 mb-6 flex w-full flex-col p-0'> | ||
<label className='mb-3 text-left text-sm font-semibold text-slate-600'> | ||
Please type your team name to confirm. <b>This action can't be undone.</b> | ||
</label> | ||
<Input | ||
autoFocus | ||
onChange={(e) => { | ||
e.preventDefault() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
if (e.target.value === teamName) setTypedTeamName(true) | ||
else setTypedTeamName(false) | ||
}} | ||
placeholder={teamName} | ||
/> | ||
{error && ( | ||
<div className='mt-2 text-sm font-semibold text-tomato-500'>{error.message}</div> | ||
)} | ||
</fieldset> | ||
|
||
<DialogActions> | ||
<FlatPrimaryButton size='medium' onClick={handleDeleteTeam} disabled={!typedTeamName}> | ||
I understand the consequences, delete this team | ||
</FlatPrimaryButton> | ||
<SecondaryButton onClick={onClose}>Cancel</SecondaryButton> | ||
</DialogActions> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default DeleteTeamDialog |
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,93 @@ | ||
import graphql from 'babel-plugin-relay/macro' | ||
import React from 'react' | ||
import {useFragment} from 'react-relay' | ||
import useAtmosphere from '~/hooks/useAtmosphere' | ||
import {MenuProps} from '../hooks/useMenu' | ||
import SetOrgUserRoleMutation from '../mutations/SetOrgUserRoleMutation' | ||
import useMutationProps from '../hooks/useMutationProps' | ||
import {OrgAdminActionMenu_organization$key} from '../__generated__/OrgAdminActionMenu_organization.graphql' | ||
import {OrgAdminActionMenu_organizationUser$key} from '../__generated__/OrgAdminActionMenu_organizationUser.graphql' | ||
import Menu from './Menu' | ||
import MenuItem from './MenuItem' | ||
|
||
interface Props { | ||
menuProps: MenuProps | ||
isViewerLastOrgAdmin: boolean | ||
organizationUser: OrgAdminActionMenu_organizationUser$key | ||
organization: OrgAdminActionMenu_organization$key | ||
toggleLeave: () => void | ||
toggleRemove: () => void | ||
} | ||
|
||
const OrgAdminActionMenu = (props: Props) => { | ||
const { | ||
menuProps, | ||
isViewerLastOrgAdmin, | ||
organizationUser: organizationUserRef, | ||
organization: organizationRef, | ||
toggleLeave, | ||
toggleRemove | ||
} = props | ||
const organization = useFragment( | ||
graphql` | ||
fragment OrgAdminActionMenu_organization on Organization { | ||
id | ||
} | ||
`, | ||
organizationRef | ||
) | ||
const organizationUser = useFragment( | ||
graphql` | ||
fragment OrgAdminActionMenu_organizationUser on OrganizationUser { | ||
role | ||
user { | ||
id | ||
} | ||
} | ||
`, | ||
organizationUserRef | ||
) | ||
const atmosphere = useAtmosphere() | ||
const {onError, onCompleted, submitting, submitMutation} = useMutationProps() | ||
const {id: orgId} = organization | ||
const {viewerId} = atmosphere | ||
const {role, user} = organizationUser | ||
const {id: userId} = user | ||
|
||
const setRole = | ||
(role: 'ORG_ADMIN' | 'BILLING_LEADER' | null = null) => | ||
() => { | ||
if (submitting) return | ||
submitMutation() | ||
const variables = {orgId, userId, role} | ||
SetOrgUserRoleMutation(atmosphere, variables, {onError, onCompleted}) | ||
} | ||
|
||
const isOrgAdmin = role === 'ORG_ADMIN' | ||
const isBillingLeader = role === 'BILLING_LEADER' | ||
const isSelf = viewerId === userId | ||
const canRemoveSelf = isSelf && !isViewerLastOrgAdmin | ||
const roleName = role === 'ORG_ADMIN' ? 'Org Admin' : 'Billing Leader' | ||
|
||
return ( | ||
<> | ||
<Menu ariaLabel={'Select your action'} {...menuProps}> | ||
{!isOrgAdmin && <MenuItem label='Promote to Org Admin' onClick={setRole('ORG_ADMIN')} />} | ||
{!isOrgAdmin && !isBillingLeader && ( | ||
<MenuItem label='Promote to Billing Leader' onClick={setRole('BILLING_LEADER')} /> | ||
)} | ||
{isOrgAdmin && !isSelf && ( | ||
<MenuItem label='Change to Billing Leader' onClick={setRole('BILLING_LEADER')} /> | ||
)} | ||
{((role && !isSelf) || canRemoveSelf) && ( | ||
<MenuItem label={`Remove ${roleName} role`} onClick={setRole(null)} /> | ||
)} | ||
{canRemoveSelf && <MenuItem label='Leave Organization' onClick={toggleLeave} />} | ||
{!isSelf && <MenuItem label='Remove from Organization' onClick={toggleRemove} />} | ||
{isSelf && !canRemoveSelf && <MenuItem label='Contact [email protected] to be removed' />} | ||
</Menu> | ||
</> | ||
) | ||
} | ||
|
||
export default OrgAdminActionMenu |
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
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> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pwa-chrome is no longer supported on my version of VS Code, the type is now simply
chrome