-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[NEW] Convert Team to Channel #22476
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1ba1253
wip
ad43a39
Add extra param to listRoomsOfUser to filter rooms user can delete
KevLehman f71d909
Merge commit 'ad43a39' into new/convert-to-channel
dougfabris 43eaee1
update the way permission was being checked
KevLehman b233fb8
Merge branch 'improve/filter-can-delete-on-teams' into new/convert-to…
dougfabris 663dfb2
new: convert team to channel
dougfabris 66cc8aa
fix: lastOwner warning
dougfabris 4c252a6
Merge branch 'develop' into new/convert-to-channel
tassoevan c3e57ca
Merge branch 'develop' into new/convert-to-channel
tassoevan a411eb8
fix: review
dougfabris 1d26f7e
improve: convert ChannelDesertationTable to ts
dougfabris 32c3088
Merge branch 'develop' into new/convert-to-channel
tassoevan d92aeec
Remove unused prop
tassoevan 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 hidden or 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 hidden or 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
17 changes: 17 additions & 0 deletions
17
client/contexts/ServerContext/endpoints/v1/teams/listRoomsOfUser.ts
This file contains hidden or 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,17 @@ | ||
| import { IRoom } from '../../../../../../definition/IRoom'; | ||
| import { IRecordsWithTotal } from '../../../../../../definition/ITeam'; | ||
|
|
||
| export type ListRoomsOfUserEndpoint = { | ||
| GET: (params: { | ||
| teamId: string; | ||
| teamName?: string; | ||
| userId?: string; | ||
| canUserDelete?: boolean; | ||
| offset?: number; | ||
| count?: number; | ||
| }) => Omit<IRecordsWithTotal<IRoom>, 'records'> & { | ||
| count: number; | ||
| offset: number; | ||
| rooms: IRecordsWithTotal<IRoom>['records']; | ||
| }; | ||
| }; |
23 changes: 0 additions & 23 deletions
23
client/views/room/contextualBar/Info/ConvertToTeamModal.js
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
8 changes: 4 additions & 4 deletions
8
...ms/contextualBar/ChannelDesertionTable.js → client/views/teams/ChannelDesertionTable.js
This file contains hidden or 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
82 changes: 82 additions & 0 deletions
82
client/views/teams/ConvertToChannelModal/BaseConvertToChannelModal.tsx
This file contains hidden or 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,82 @@ | ||
| import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; | ||
| import React, { FC, useState, useCallback } from 'react'; | ||
|
|
||
| import { IRoom } from '../../../../definition/IRoom'; | ||
| import FirstStep from './ModalSteps/FirstStep'; | ||
| import SecondStep from './ModalSteps/SecondStep'; | ||
|
|
||
| const STEPS = { | ||
| LIST_ROOMS: 'LIST_ROOMS', | ||
| CONFIRM_CONVERT: 'CONFIRM_CONVERT', | ||
| }; | ||
|
|
||
| type BaseConvertToChannelModalProps = { | ||
| onClose: () => void; | ||
| onCancel: () => void; | ||
| onConfirm: () => Array<IRoom>; | ||
| currentStep?: string; | ||
| rooms: Array<IRoom & { isLastOwner?: string }> | undefined; | ||
| selectedRooms: { [key: string]: IRoom }; | ||
| }; | ||
|
|
||
| const BaseConvertToChannelModal: FC<BaseConvertToChannelModalProps> = ({ | ||
| onClose, | ||
| onCancel, | ||
| onConfirm, | ||
| rooms, | ||
| currentStep = rooms?.length === 0 ? STEPS.CONFIRM_CONVERT : STEPS.LIST_ROOMS, | ||
| }) => { | ||
| const [step, setStep] = useState(currentStep); | ||
| const [selectedRooms, setSelectedRooms] = useState< | ||
| BaseConvertToChannelModalProps['selectedRooms'] | ||
| >({}); | ||
|
|
||
| const onContinue = useMutableCallback(() => setStep(STEPS.CONFIRM_CONVERT)); | ||
| const onReturn = useMutableCallback(() => setStep(STEPS.LIST_ROOMS)); | ||
|
|
||
| const eligibleRooms = rooms; | ||
|
|
||
| const onChangeRoomSelection = useCallback((room) => { | ||
| setSelectedRooms((selectedRooms) => { | ||
| if (selectedRooms[room._id]) { | ||
| delete selectedRooms[room._id]; | ||
| return { ...selectedRooms }; | ||
| } | ||
| return { ...selectedRooms, [room._id]: room }; | ||
| }); | ||
| }, []); | ||
|
|
||
| const onToggleAllRooms = useMutableCallback(() => { | ||
| if (Object.values(selectedRooms).filter(Boolean).length === 0 && eligibleRooms) { | ||
| return setSelectedRooms(Object.fromEntries(eligibleRooms.map((room) => [room._id, room]))); | ||
| } | ||
| setSelectedRooms({}); | ||
| }); | ||
|
|
||
| if (step === STEPS.CONFIRM_CONVERT) { | ||
| return ( | ||
| <SecondStep | ||
| onConfirm={onConfirm} | ||
| onClose={onClose} | ||
| onCancel={rooms && rooms.length > 0 ? onReturn : onCancel} | ||
| deletedRooms={selectedRooms} | ||
| rooms={rooms} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <FirstStep | ||
| onConfirm={onContinue} | ||
| onClose={onClose} | ||
| onCancel={onCancel} | ||
| rooms={rooms} | ||
| selectedRooms={selectedRooms} | ||
| onToggleAllRooms={onToggleAllRooms} | ||
| onChangeRoomSelection={onChangeRoomSelection} | ||
| eligibleRoomsLength={eligibleRooms?.length} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default BaseConvertToChannelModal; | ||
58 changes: 58 additions & 0 deletions
58
client/views/teams/ConvertToChannelModal/ConvertToChannelModal.tsx
This file contains hidden or 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,58 @@ | ||
| import { Skeleton } from '@rocket.chat/fuselage'; | ||
| import React, { FC, useMemo } from 'react'; | ||
|
|
||
| import { IRoom } from '../../../../definition/IRoom'; | ||
| import GenericModal from '../../../components/GenericModal'; | ||
| import { useTranslation } from '../../../contexts/TranslationContext'; | ||
| import { useEndpointData } from '../../../hooks/useEndpointData'; | ||
| import { AsyncStatePhase } from '../../../lib/asyncState'; | ||
| import BaseConvertToChannelModal from './BaseConvertToChannelModal'; | ||
|
|
||
| type ConvertToChannelModalProps = { | ||
| onClose: () => void; | ||
| onCancel: () => void; | ||
| onConfirm: () => Array<IRoom>; | ||
| teamId: string; | ||
| userId: string; | ||
| }; | ||
|
|
||
| const ConvertToChannelModal: FC<ConvertToChannelModalProps> = ({ | ||
| onClose, | ||
| onCancel, | ||
| onConfirm, | ||
| teamId, | ||
| userId, | ||
| }) => { | ||
| const t = useTranslation(); | ||
|
|
||
| const { value, phase } = useEndpointData( | ||
| 'teams.listRoomsOfUser', | ||
| useMemo(() => ({ teamId, userId, canUserDelete: true }), [teamId, userId]), | ||
| ); | ||
|
|
||
| if (phase === AsyncStatePhase.LOADING) { | ||
| return ( | ||
| <GenericModal | ||
| variant='warning' | ||
| onClose={onClose} | ||
| title={<Skeleton width='50%' />} | ||
| confirmText={t('Cancel')} | ||
| onConfirm={onClose} | ||
| > | ||
| <Skeleton width='full' /> | ||
| </GenericModal> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <BaseConvertToChannelModal | ||
| onClose={onClose} | ||
| onCancel={onCancel} | ||
| onConfirm={onConfirm} | ||
| rooms={value?.rooms} | ||
| selectedRooms={{}} | ||
|
dougfabris marked this conversation as resolved.
Outdated
|
||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default ConvertToChannelModal; | ||
67 changes: 67 additions & 0 deletions
67
client/views/teams/ConvertToChannelModal/ModalSteps/FirstStep.tsx
This file contains hidden or 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,67 @@ | ||
| import { Box } from '@rocket.chat/fuselage'; | ||
| import React, { FC } from 'react'; | ||
|
|
||
| import { IRoom } from '../../../../../definition/IRoom'; | ||
| import GenericModal from '../../../../components/GenericModal'; | ||
| import { useTranslation } from '../../../../contexts/TranslationContext'; | ||
| import ChannelDesertionTable from '../../ChannelDesertionTable'; | ||
|
|
||
| type FirstStepProps = { | ||
| onClose: () => void; | ||
| onCancel: () => void; | ||
| onConfirm: () => void; | ||
| onToggleAllRooms: () => void; | ||
| onChangeRoomSelection: (room: IRoom) => void; | ||
| rooms: Array<IRoom & { isLastOwner?: string }> | undefined; | ||
| eligibleRoomsLength: number | undefined; | ||
| selectedRooms: { [key: string]: IRoom }; | ||
| }; | ||
|
|
||
| const FirstStep: FC<FirstStepProps> = ({ | ||
| onClose, | ||
| onCancel, | ||
| onConfirm, | ||
| rooms, | ||
| onToggleAllRooms, | ||
| onChangeRoomSelection, | ||
| selectedRooms, | ||
| eligibleRoomsLength, | ||
| ...props | ||
| }) => { | ||
| const t = useTranslation(); | ||
|
|
||
| return ( | ||
| <GenericModal | ||
| variant='warning' | ||
| icon='warning' | ||
| title={t('Converting_team_to_channel')} | ||
| cancelText={t('Cancel')} | ||
| confirmText={t('Continue')} | ||
| onClose={onClose} | ||
| onCancel={onCancel} | ||
| onConfirm={onConfirm} | ||
| {...props} | ||
| > | ||
| <Box mbe='x24' fontScale='p1'> | ||
| {t('Select_the_teams_channels_you_would_like_to_delete')} | ||
| </Box> | ||
|
|
||
| <Box mbe='x24' fontScale='p1'> | ||
| {t('Notice_that_public_channels_will_be_public_and_visible_to_everyone')} | ||
| </Box> | ||
|
|
||
| <ChannelDesertionTable | ||
| lastOwnerWarning={undefined} | ||
| onToggleAllRooms={onToggleAllRooms} | ||
| rooms={rooms} | ||
| params={{}} | ||
|
dougfabris marked this conversation as resolved.
Outdated
|
||
| onChangeParams={(): void => undefined} | ||
|
dougfabris marked this conversation as resolved.
Outdated
|
||
| onChangeRoomSelection={onChangeRoomSelection} | ||
| selectedRooms={selectedRooms} | ||
| eligibleRoomsLength={eligibleRoomsLength} | ||
| /> | ||
| </GenericModal> | ||
| ); | ||
| }; | ||
|
|
||
| export default FirstStep; | ||
45 changes: 45 additions & 0 deletions
45
client/views/teams/ConvertToChannelModal/ModalSteps/SecondStep.tsx
This file contains hidden or 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,45 @@ | ||
| import { Icon } from '@rocket.chat/fuselage'; | ||
| import React, { FC } from 'react'; | ||
|
|
||
| import { IRoom } from '../../../../../definition/IRoom'; | ||
| import GenericModal from '../../../../components/GenericModal'; | ||
| import { useTranslation } from '../../../../contexts/TranslationContext'; | ||
|
|
||
| type SecondStepsProps = { | ||
| onClose: () => void; | ||
| onCancel: () => void; | ||
| onConfirm: (deletedRooms: { [key: string]: IRoom }) => void; | ||
| deletedRooms: { | ||
| [key: string]: IRoom; | ||
| }; | ||
| rooms: Array<IRoom & { isLastOwner?: string }> | undefined; | ||
| }; | ||
|
|
||
| const SecondStep: FC<SecondStepsProps> = ({ | ||
| onClose, | ||
| onCancel, | ||
| onConfirm, | ||
| deletedRooms = {}, | ||
| rooms = [], | ||
| ...props | ||
| }) => { | ||
| const t = useTranslation(); | ||
|
|
||
| return ( | ||
| <GenericModal | ||
| {...props} | ||
| variant='warning' | ||
| icon={<Icon name='modal-warning' size={24} color='warning' />} | ||
| cancelText={rooms?.length > 0 ? t('Back') : t('Cancel')} | ||
| confirmText={t('Convert')} | ||
| title={t('Confirmation')} | ||
| onClose={onClose} | ||
| onCancel={onCancel} | ||
| onConfirm={(): void => onConfirm(deletedRooms)} | ||
| > | ||
| {t('You_are_converting_team_to_channel')} | ||
| </GenericModal> | ||
| ); | ||
| }; | ||
|
|
||
| export default SecondStep; |
This file contains hidden or 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 @@ | ||
| export { default } from './ConvertToChannelModal'; |
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.
Uh oh!
There was an error while loading. Please reload this page.