Skip to content

Commit

Permalink
Short-cut with an error throw
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Dec 24, 2024
1 parent 3177864 commit 4adc1d4
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import { useTranslation } from 'react-i18next';
import ConvertToChannelModal from './ConvertToChannelModal';
import { useEndpointAction } from '../../../../hooks/useEndpointAction';

export const useConvertToChannel = (room: IRoom) => {
export const useConvertToChannel = ({ _id, teamId }: IRoom) => {
const { t } = useTranslation();
const setModal = useSetModal();
const userId = useUserId();
const canEdit = usePermission('edit-team-channel', room._id);
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: room.teamId!,
teamId,
roomsToRemove: Object.keys(roomsToRemove),
});

Expand All @@ -37,8 +41,8 @@ export const useConvertToChannel = (room: IRoom) => {
onClose={() => setModal(null)}
onCancel={() => setModal(null)}
onConfirm={onConfirm}
teamId={room.teamId!}
userId={userId!}
teamId={teamId}
userId={userId}
/>,
);
});
Expand Down

0 comments on commit 4adc1d4

Please sign in to comment.