2021-06-10 14:48:44 +02:00
|
|
|
import React, { useCallback } from 'react';
|
2023-04-13 15:49:34 +03:00
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { useDispatch } from 'react-redux';
|
2021-01-12 15:24:55 +02:00
|
|
|
|
2023-04-03 13:49:19 +03:00
|
|
|
import Icon from '../../../base/icons/components/Icon';
|
|
|
|
|
import { IconCloseLarge } from '../../../base/icons/svg';
|
2021-02-24 14:26:00 +02:00
|
|
|
import { toggleChat } from '../../actions.web';
|
2021-01-12 15:24:55 +02:00
|
|
|
|
2023-04-13 15:49:34 +03:00
|
|
|
interface IProps {
|
2021-01-12 15:24:55 +02:00
|
|
|
|
2021-01-14 17:12:08 +01:00
|
|
|
/**
|
|
|
|
|
* An optional class name.
|
|
|
|
|
*/
|
2023-04-13 15:49:34 +03:00
|
|
|
className: string;
|
2021-06-10 14:48:44 +02:00
|
|
|
|
2021-09-10 21:57:36 +03:00
|
|
|
/**
|
|
|
|
|
* Whether the polls feature is enabled or not.
|
|
|
|
|
*/
|
2023-04-13 15:49:34 +03:00
|
|
|
isPollsEnabled: boolean;
|
2021-09-10 21:57:36 +03:00
|
|
|
|
2021-06-10 14:48:44 +02:00
|
|
|
/**
|
2023-04-13 15:49:34 +03:00
|
|
|
* Function to be called when pressing the close button.
|
2021-06-10 14:48:44 +02:00
|
|
|
*/
|
2023-04-13 15:49:34 +03:00
|
|
|
onCancel: Function;
|
|
|
|
|
}
|
2021-01-12 15:24:55 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom header of the {@code ChatDialog}.
|
|
|
|
|
*
|
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
|
*/
|
2023-04-13 15:49:34 +03:00
|
|
|
function ChatHeader({ className, isPollsEnabled }: IProps) {
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
const onCancel = useCallback(() => {
|
|
|
|
|
dispatch(toggleChat());
|
|
|
|
|
}, []);
|
2021-06-10 14:48:44 +02:00
|
|
|
|
|
|
|
|
const onKeyPressHandler = useCallback(e => {
|
|
|
|
|
if (onCancel && (e.key === ' ' || e.key === 'Enter')) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
onCancel();
|
|
|
|
|
}
|
2023-04-13 15:49:34 +03:00
|
|
|
}, []);
|
2021-06-10 14:48:44 +02:00
|
|
|
|
2021-01-12 15:24:55 +02:00
|
|
|
return (
|
|
|
|
|
<div
|
2023-02-28 15:52:06 +01:00
|
|
|
className = { className || 'chat-dialog-header' }>
|
|
|
|
|
<span
|
|
|
|
|
aria-level = { 1 }
|
|
|
|
|
role = 'heading'>
|
|
|
|
|
{ t(isPollsEnabled ? 'chat.titleWithPolls' : 'chat.title') }
|
|
|
|
|
</span>
|
2021-01-12 15:24:55 +02:00
|
|
|
<Icon
|
2021-06-10 14:48:44 +02:00
|
|
|
ariaLabel = { t('toolbar.closeChat') }
|
2021-01-12 15:24:55 +02:00
|
|
|
onClick = { onCancel }
|
2021-06-10 14:48:44 +02:00
|
|
|
onKeyPress = { onKeyPressHandler }
|
|
|
|
|
role = 'button'
|
2022-11-08 12:24:32 +02:00
|
|
|
src = { IconCloseLarge }
|
2021-06-10 14:48:44 +02:00
|
|
|
tabIndex = { 0 } />
|
2021-01-12 15:24:55 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 15:49:34 +03:00
|
|
|
export default ChatHeader;
|