-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tasso Evangelista <[email protected]>
- Loading branch information
1 parent
cc381e1
commit c7eedf8
Showing
14 changed files
with
223 additions
and
212 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
File renamed without changes.
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
File renamed without changes.
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
93 changes: 12 additions & 81 deletions
93
apps/meteor/client/views/teams/contextualBar/info/TeamsInfoWithData.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 |
---|---|---|
@@ -1,102 +1,33 @@ | ||
import type { IRoom, Serialized } from '@rocket.chat/core-typings'; | ||
import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; | ||
import { useSetModal, useToastMessageDispatch, useUserId, usePermission, useRouter } from '@rocket.chat/ui-contexts'; | ||
import React, { useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
import { usePermission } from '@rocket.chat/ui-contexts'; | ||
import React, { useCallback, useState } from 'react'; | ||
|
||
import LeaveTeam from './LeaveTeam'; | ||
import TeamsInfo from './TeamsInfo'; | ||
import { useEndpointAction } from '../../../../hooks/useEndpointAction'; | ||
import { useHideRoomAction } from '../../../../hooks/useHideRoomAction'; | ||
import { useDeleteRoom } from '../../../hooks/roomActions/useDeleteRoom'; | ||
import { useRoom } from '../../../room/contexts/RoomContext'; | ||
import { useRoomToolbox } from '../../../room/contexts/RoomToolboxContext'; | ||
import ConvertToChannelModal from '../../ConvertToChannelModal'; | ||
import EditChannelWithData from '../../../room/contextualBar/Info/EditRoomInfo'; | ||
|
||
type TeamsInfoWithLogicProps = { | ||
openEditing: () => void; | ||
}; | ||
|
||
const TeamsInfoWithLogic = ({ openEditing }: TeamsInfoWithLogicProps) => { | ||
const TeamsInfoWithData = () => { | ||
const room = useRoom(); | ||
const [editing, setEditing] = useState(false); | ||
const { openTab, closeTab } = useRoomToolbox(); | ||
const { t } = useTranslation(); | ||
const userId = useUserId(); | ||
|
||
const dispatchToastMessage = useToastMessageDispatch(); | ||
const setModal = useSetModal(); | ||
const closeModal = useMutableCallback(() => setModal()); | ||
|
||
const leaveTeam = useEndpointAction('POST', '/v1/teams.leave'); | ||
const convertTeamToChannel = useEndpointAction('POST', '/v1/teams.convertToChannel'); | ||
|
||
const hideTeam = useHideRoomAction({ rid: room._id, type: room.t, name: room.name ?? '' }); | ||
|
||
const router = useRouter(); | ||
|
||
const canEdit = usePermission('edit-team-channel', room._id); | ||
|
||
// const canLeave = usePermission('leave-team'); /* && room.cl !== false && joined */ | ||
|
||
const { handleDelete, canDeleteRoom } = useDeleteRoom(room); | ||
|
||
const onClickLeave = useMutableCallback(() => { | ||
const onConfirm = async (selectedRooms: { [key: string]: Serialized<IRoom> & { isLastOwner?: boolean } } = {}) => { | ||
const roomsLeft = Object.keys(selectedRooms); | ||
const roomsToLeave = Array.isArray(roomsLeft) && roomsLeft.length > 0 ? roomsLeft : []; | ||
|
||
try { | ||
await leaveTeam({ | ||
teamId: room.teamId!, | ||
...(roomsToLeave.length && { rooms: roomsToLeave }), | ||
}); | ||
dispatchToastMessage({ type: 'success', message: t('Teams_left_team_successfully') }); | ||
router.navigate('/home'); | ||
} catch (error) { | ||
dispatchToastMessage({ type: 'error', message: error }); | ||
} finally { | ||
closeModal(); | ||
} | ||
}; | ||
|
||
setModal(<LeaveTeam onConfirm={onConfirm} onCancel={closeModal} teamId={room.teamId!} />); | ||
}); | ||
|
||
const onClickBack = useEffectEvent(() => setEditing(false)); | ||
const onClickViewChannels = useCallback(() => openTab('team-channels'), [openTab]); | ||
|
||
const onClickConvertToChannel = useMutableCallback(() => { | ||
const onConfirm = async (roomsToRemove: { [key: string]: Serialized<IRoom> }) => { | ||
try { | ||
await convertTeamToChannel({ | ||
teamId: room.teamId!, | ||
roomsToRemove: Object.keys(roomsToRemove), | ||
}); | ||
|
||
dispatchToastMessage({ type: 'success', message: t('Success') }); | ||
} catch (error) { | ||
dispatchToastMessage({ type: 'error', message: error }); | ||
} finally { | ||
closeModal(); | ||
} | ||
}; | ||
|
||
setModal( | ||
<ConvertToChannelModal onClose={closeModal} onCancel={closeModal} onConfirm={onConfirm} teamId={room.teamId!} userId={userId!} />, | ||
); | ||
}); | ||
if (editing) { | ||
return <EditChannelWithData onClickBack={onClickBack} />; | ||
} | ||
|
||
return ( | ||
<TeamsInfo | ||
room={room} | ||
onClickEdit={canEdit ? openEditing : undefined} | ||
onClickEdit={canEdit ? () => setEditing(true) : undefined} | ||
onClickClose={closeTab} | ||
onClickDelete={canDeleteRoom ? handleDelete : undefined} | ||
onClickLeave={onClickLeave} | ||
onClickHide={hideTeam} | ||
onClickViewChannels={onClickViewChannels} | ||
onClickConvertToChannel={canEdit ? onClickConvertToChannel : undefined} | ||
/> | ||
); | ||
}; | ||
|
||
export default TeamsInfoWithLogic; | ||
export default TeamsInfoWithData; |
18 changes: 0 additions & 18 deletions
18
apps/meteor/client/views/teams/contextualBar/info/TeamsInfoWithRooms.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
apps/meteor/client/views/teams/contextualBar/info/useConvertToChannel.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,51 @@ | ||
import type { IRoom, Serialized } from '@rocket.chat/core-typings'; | ||
import { useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
import { usePermission, useSetModal, useToastMessageDispatch, useUserId } from '@rocket.chat/ui-contexts'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import ConvertToChannelModal from './ConvertToChannelModal'; | ||
import { useEndpointAction } from '../../../../hooks/useEndpointAction'; | ||
|
||
export const useConvertToChannel = ({ _id, teamId }: IRoom) => { | ||
const { t } = useTranslation(); | ||
const setModal = useSetModal(); | ||
const userId = useUserId(); | ||
const canEdit = usePermission('edit-team-channel', _id); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
|
||
const convertTeamToChannel = useEndpointAction('POST', '/v1/teams.convertToChannel'); | ||
|
||
const onClickConvertToChannel = useEffectEvent(() => { | ||
if (!userId || !teamId) { | ||
throw new Error('Invalid teamId or userId'); | ||
} | ||
|
||
const onConfirm = async (roomsToRemove: { [key: string]: Serialized<IRoom> }) => { | ||
try { | ||
await convertTeamToChannel({ | ||
teamId, | ||
roomsToRemove: Object.keys(roomsToRemove), | ||
}); | ||
|
||
dispatchToastMessage({ type: 'success', message: t('Success') }); | ||
} catch (error) { | ||
dispatchToastMessage({ type: 'error', message: error }); | ||
} finally { | ||
setModal(null); | ||
} | ||
}; | ||
|
||
setModal( | ||
<ConvertToChannelModal | ||
onClose={() => setModal(null)} | ||
onCancel={() => setModal(null)} | ||
onConfirm={onConfirm} | ||
teamId={teamId} | ||
userId={userId} | ||
/>, | ||
); | ||
}); | ||
|
||
return canEdit ? onClickConvertToChannel : undefined; | ||
}; |
Oops, something went wrong.