Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Box, Sidebar, Dropdown } from '@rocket.chat/fuselage';
import { useAtLeastOnePermission } from '@rocket.chat/ui-contexts';
import React, { useRef } from 'react';
import React, { HTMLAttributes, useRef, VFC } from 'react';
import { createPortal } from 'react-dom';

import { useDropdownVisibility } from '../hooks/useDropdownVisibility';
import CreateRoomList from './CreateRoomList';

const CREATE_ROOM_PERMISSIONS = ['create-c', 'create-p', 'create-d', 'start-discussion', 'start-discussion-other-user'];

const CreateRoom = (props) => {
const CreateRoom: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const reference = useRef(null);
const target = useRef(null);
const { isVisible, toggle } = useDropdownVisibility({ reference, target });
Expand All @@ -19,13 +19,13 @@ const CreateRoom = (props) => {
<>
{showCreate && (
<Box ref={reference}>
<Sidebar.TopBar.Action {...props} icon='edit-rounded' onClick={toggle} />
<Sidebar.TopBar.Action {...props} icon='edit-rounded' onClick={(): void => toggle()} />
</Box>
)}
{isVisible &&
createPortal(
<Dropdown reference={reference} ref={target}>
<CreateRoomList closeList={() => toggle(false)} />
<CreateRoomList closeList={(): void => toggle(false)} />
</Dropdown>,
document.body,
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OptionTitle } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useSetModal, useSetting, useAtLeastOnePermission, useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { FC } from 'react';

import { popover } from '../../../../app/ui-utils/client';
import CreateDiscussion from '../../../components/CreateDiscussion';
Expand All @@ -19,23 +19,27 @@ const style = {
textTransform: 'uppercase',
};

const useReactModal = (Component) => {
type CreateRoomListProps = {
closeList: () => void;
};

const useReactModal = (Component: FC<any>): ((e: React.MouseEvent<HTMLElement>) => void) => {
const setModal = useSetModal();

return useMutableCallback((e) => {
popover.close();

e.preventDefault();

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

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

function CreateRoomList({ closeList }) {
const CreateRoomList: FC<CreateRoomListProps> = ({ closeList }) => {
const t = useTranslation();

const canCreateChannel = useAtLeastOnePermission(CREATE_CHANNEL_PERMISSIONS);
Expand All @@ -52,15 +56,15 @@ function CreateRoomList({ closeList }) {

return (
<>
<OptionTitle pb='x8' style={style}>
<OptionTitle pb='x8' {...({ style } as any)}>
{t('Create_new')}
</OptionTitle>
<ul className='rc-popover__list'>
{canCreateChannel && (
<ListItem
icon='hashtag'
text={t('Channel')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createChannel(e);
closeList();
}}
Expand All @@ -70,7 +74,7 @@ function CreateRoomList({ closeList }) {
<ListItem
icon='team'
text={t('Team')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createTeam(e);
closeList();
}}
Expand All @@ -80,7 +84,7 @@ function CreateRoomList({ closeList }) {
<ListItem
icon='balloon'
text={t('Direct_Messages')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createDirectMessage(e);
closeList();
}}
Expand All @@ -90,7 +94,7 @@ function CreateRoomList({ closeList }) {
<ListItem
icon='discussion'
text={t('Discussion')}
action={(e) => {
action={(e: React.MouseEvent<HTMLElement>): void => {
createDiscussion(e);
closeList();
}}
Expand All @@ -99,6 +103,6 @@ function CreateRoomList({ closeList }) {
</ul>
</>
);
}
};

export default CreateRoomList;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useLayout, useRoute } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { HTMLAttributes, VFC } from 'react';

const Directory = (props) => {
const Directory: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const directoryRoute = useRoute('directory');
const { sidebar } = useLayout();
const handleDirectory = useMutableCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useLayout, useRoute, useSetting } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { HTMLAttributes, VFC } from 'react';

const Home = (props) => {
const SidebarHeaderActionHome: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const homeRoute = useRoute('home');
const { sidebar } = useLayout();
const showHome = useSetting('Layout_Show_Home_Button');
Expand All @@ -15,4 +15,4 @@ const Home = (props) => {
return showHome ? <Sidebar.TopBar.Action {...props} icon='home' onClick={handleHome} /> : null;
};

export default Home;
export default SidebarHeaderActionHome;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useSessionDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { HTMLAttributes, VFC } from 'react';

const Login = (props) => {
const Login: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const setForceLogin = useSessionDispatch('forceLogin');
const t = useTranslation();

Expand All @@ -13,7 +13,7 @@ const Login = (props) => {
ghost={false}
icon='login'
title={t('Sign_in_to_start_talking')}
onClick={() => setForceLogin(true)}
onClick={(): void => setForceLogin(true)}
/>
);
};
Expand Down
6 changes: 2 additions & 4 deletions apps/meteor/client/sidebar/header/actions/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Sidebar } from '@rocket.chat/fuselage';
import { useMutableCallback, useOutsideClick } from '@rocket.chat/fuselage-hooks';
import React, { useState, useEffect, useRef, ReactElement, ComponentProps } from 'react';
import React, { useState, useEffect, useRef, VFC, HTMLAttributes } from 'react';
import tinykeys from 'tinykeys';

import SearchList from '../../search/SearchList';

type SearchProps = Omit<ComponentProps<typeof Sidebar.TopBar.Action>, 'icon'>;

const Search = (props: SearchProps): ReactElement => {
const Search: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const [searchOpen, setSearchOpen] = useState(false);

const ref = useRef<HTMLElement>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Box, Sidebar, Dropdown } from '@rocket.chat/fuselage';
import React, { useRef } from 'react';
import React, { VFC, useRef, HTMLAttributes } from 'react';
import { createPortal } from 'react-dom';

import SortList from '../../../components/SortList';
import { useDropdownVisibility } from '../hooks/useDropdownVisibility';

const Sort = (props) => {
const Sort: VFC<Omit<HTMLAttributes<HTMLElement>, 'is'>> = (props) => {
const reference = useRef(null);
const target = useRef(null);
const { isVisible, toggle } = useDropdownVisibility({ reference, target });

return (
<>
<Box ref={reference}>
<Sidebar.TopBar.Action {...props} icon='sort' onClick={toggle} />
<Sidebar.TopBar.Action {...props} icon='sort' onClick={(): void => toggle()} />
</Box>
{isVisible &&
createPortal(
Expand Down