-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] Convert Team to Channel (#22476)
* wip * Add extra param to listRoomsOfUser to filter rooms user can delete * update the way permission was being checked * new: convert team to channel * fix: lastOwner warning * fix: review * improve: convert ChannelDesertationTable to ts * Remove unused prop Co-authored-by: Douglas Fabris <[email protected]> Co-authored-by: Kevin Aleman <[email protected]> Co-authored-by: Tasso Evangelista <[email protected]>
- Loading branch information
1 parent
f4e3d00
commit 6357447
Showing
21 changed files
with
378 additions
and
49 deletions.
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
17 changes: 17 additions & 0 deletions
17
client/contexts/ServerContext/endpoints/v1/teams/listRoomsOfUser.ts
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,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 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
79 changes: 79 additions & 0 deletions
79
client/views/teams/ConvertToChannelModal/BaseConvertToChannelModal.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,79 @@ | ||
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 }>; | ||
}; | ||
|
||
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<{ [key: string]: IRoom }>({}); | ||
|
||
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; |
57 changes: 57 additions & 0 deletions
57
client/views/teams/ConvertToChannelModal/ConvertToChannelModal.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,57 @@ | ||
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} | ||
/> | ||
); | ||
}; | ||
|
||
export default ConvertToChannelModal; |
65 changes: 65 additions & 0 deletions
65
client/views/teams/ConvertToChannelModal/ModalSteps/FirstStep.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,65 @@ | ||
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} | ||
onChangeRoomSelection={onChangeRoomSelection} | ||
selectedRooms={selectedRooms} | ||
eligibleRoomsLength={eligibleRoomsLength} | ||
/> | ||
</GenericModal> | ||
); | ||
}; | ||
|
||
export default FirstStep; |
Oops, something went wrong.