2022-05-08 10:41:47 +03:00
|
|
|
import { Menu, Dropdown, Button, Space } from 'antd';
|
2022-05-22 15:20:11 +03:00
|
|
|
import {
|
|
|
|
CaretDownOutlined,
|
|
|
|
EditOutlined,
|
|
|
|
LockOutlined,
|
|
|
|
MessageOutlined,
|
|
|
|
UserOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2022-05-14 00:44:16 +03:00
|
|
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
2022-05-14 01:07:49 +03:00
|
|
|
import { useState } from 'react';
|
|
|
|
import Modal from '../../ui/Modal/Modal';
|
2022-05-14 00:44:16 +03:00
|
|
|
import { chatVisibilityAtom, chatDisplayNameAtom } from '../../stores/ClientConfigStore';
|
2022-05-08 10:41:47 +03:00
|
|
|
import { ChatState, ChatVisibilityState } from '../../../interfaces/application-state';
|
|
|
|
import s from './UserDropdown.module.scss';
|
2022-05-14 01:07:49 +03:00
|
|
|
import NameChangeModal from '../../modals/NameChangeModal';
|
2022-04-30 01:09:53 +03:00
|
|
|
|
|
|
|
interface Props {
|
2022-05-14 00:44:16 +03:00
|
|
|
username?: string;
|
2022-05-12 09:31:31 +03:00
|
|
|
chatState: ChatState;
|
2022-04-30 01:09:53 +03:00
|
|
|
}
|
2022-04-28 09:19:20 +03:00
|
|
|
|
2022-05-14 00:44:16 +03:00
|
|
|
export default function UserDropdown({ username: defaultUsername, chatState }: Props) {
|
2022-04-30 01:09:53 +03:00
|
|
|
const [chatVisibility, setChatVisibility] =
|
|
|
|
useRecoilState<ChatVisibilityState>(chatVisibilityAtom);
|
2022-05-14 00:44:16 +03:00
|
|
|
const username = defaultUsername || useRecoilValue(chatDisplayNameAtom);
|
2022-05-14 01:07:49 +03:00
|
|
|
const [showNameChangeModal, setShowNameChangeModal] = useState<boolean>(false);
|
2022-04-30 01:09:53 +03:00
|
|
|
|
|
|
|
const toggleChatVisibility = () => {
|
|
|
|
if (chatVisibility === ChatVisibilityState.Hidden) {
|
|
|
|
setChatVisibility(ChatVisibilityState.Visible);
|
|
|
|
} else {
|
|
|
|
setChatVisibility(ChatVisibilityState.Hidden);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-14 01:07:49 +03:00
|
|
|
const handleChangeName = () => {
|
|
|
|
setShowNameChangeModal(true);
|
|
|
|
};
|
|
|
|
|
2022-04-30 01:09:53 +03:00
|
|
|
const menu = (
|
|
|
|
<Menu>
|
2022-05-22 15:20:11 +03:00
|
|
|
<Menu.Item key="0" icon={<EditOutlined />} onClick={() => handleChangeName()}>
|
2022-05-14 01:07:49 +03:00
|
|
|
Change name
|
|
|
|
</Menu.Item>
|
2022-05-22 15:20:11 +03:00
|
|
|
<Menu.Item key="1" icon={<LockOutlined />}>
|
|
|
|
Authenticate
|
|
|
|
</Menu.Item>
|
2022-05-14 00:44:16 +03:00
|
|
|
{chatState === ChatState.Available && (
|
2022-05-22 15:20:11 +03:00
|
|
|
<Menu.Item key="3" icon={<MessageOutlined />} onClick={() => toggleChatVisibility()}>
|
2022-04-30 01:09:53 +03:00
|
|
|
Toggle chat
|
|
|
|
</Menu.Item>
|
|
|
|
)}
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2022-05-08 10:41:47 +03:00
|
|
|
<div className={`${s.root}`}>
|
|
|
|
<Dropdown overlay={menu} trigger={['click']}>
|
2022-05-22 09:36:52 +03:00
|
|
|
<Button icon={<UserOutlined style={{ marginRight: '.5rem' }} />}>
|
2022-05-08 10:41:47 +03:00
|
|
|
<Space>
|
|
|
|
{username}
|
2022-05-22 09:36:52 +03:00
|
|
|
<CaretDownOutlined />
|
2022-05-08 10:41:47 +03:00
|
|
|
</Space>
|
|
|
|
</Button>
|
|
|
|
</Dropdown>
|
2022-05-14 01:07:49 +03:00
|
|
|
<Modal
|
|
|
|
title="Change Chat Display Name"
|
|
|
|
visible={showNameChangeModal}
|
|
|
|
handleCancel={() => setShowNameChangeModal(false)}
|
|
|
|
>
|
|
|
|
<NameChangeModal />
|
|
|
|
</Modal>
|
2022-05-08 10:41:47 +03:00
|
|
|
</div>
|
2022-04-30 01:09:53 +03:00
|
|
|
);
|
2022-04-28 09:19:20 +03:00
|
|
|
}
|
2022-05-14 00:44:16 +03:00
|
|
|
|
|
|
|
UserDropdown.defaultProps = {
|
|
|
|
username: undefined,
|
|
|
|
};
|