Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions client/sidebar/header/actions/CreateRoomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import React from 'react';
import { Box, Margins } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';


import { modal } from '../../../../app/ui-utils';
import { modal, popover } from '../../../../app/ui-utils';
import { useTranslation } from '../../../contexts/TranslationContext';
import { useAtLeastOnePermission, usePermission } from '../../../contexts/AuthorizationContext';
import { useSetting } from '../../../contexts/SettingsContext';
Expand All @@ -21,6 +20,7 @@ const style = {

const useAction = (title, content) => useMutableCallback((e) => {
e.preventDefault();
popover.close();
modal.open({
title,
content,
Expand All @@ -36,27 +36,32 @@ const useAction = (title, content) => useMutableCallback((e) => {
});
});

const useReactModal = (setModal, Component) => useMutableCallback((e) => {
e.preventDefault();
const useReactModal = (Component) => {
const setModal = useSetModal();

const handleClose = () => {
setModal(null);
};
return useMutableCallback((e) => {
popover.close();

setModal(() => <Component
onClose={handleClose}
/>);
});
e.preventDefault();

const handleClose = () => {
setModal(null);
};

setModal(() => <Component
onClose={handleClose}
/>);
});
};

function CreateRoomList() {
const t = useTranslation();
const setModal = useSetModal();

const canCreateChannel = useAtLeastOnePermission(CREATE_CHANNEL_PERMISSIONS);
const canCreateDirectMessages = usePermission('create-d');
const canCreateDiscussion = useAtLeastOnePermission(CREATE_DISCUSSION_PERMISSIONS);

const createChannel = useReactModal(setModal, CreateChannel);
const createChannel = useReactModal(CreateChannel);
const createDirectMessage = useAction(t('Direct_Messages'), 'CreateDirectMessage');
const createDiscussion = useAction(t('Discussion_title'), 'CreateDiscussion');

Expand Down