2022-10-02 21:02:21 +03:00
|
|
|
import { Dropdown, Menu, MenuProps, Space, message, Modal as AntModal } from 'antd';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { FC, useState } from 'react';
|
2023-01-16 09:31:36 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
2022-10-02 21:02:21 +03:00
|
|
|
import { Modal } from '../../ui/Modal/Modal';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { ChatModerationDetailsModal } from '../ChatModerationDetailsModal/ChatModerationDetailsModal';
|
|
|
|
import styles from './ChatModerationActionMenu.module.scss';
|
2022-07-21 06:42:23 +03:00
|
|
|
import ChatModeration from '../../../services/moderation-service';
|
2022-07-17 03:30:05 +03:00
|
|
|
|
2022-10-02 21:02:21 +03:00
|
|
|
const { confirm } = AntModal;
|
2022-07-17 03:30:05 +03:00
|
|
|
|
2023-01-16 09:31:36 +03:00
|
|
|
// Lazy loaded components
|
|
|
|
|
|
|
|
const CloseCircleOutlined = dynamic(() => import('@ant-design/icons/CloseCircleOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ExclamationCircleOutlined = dynamic(
|
|
|
|
() => import('@ant-design/icons/ExclamationCircleOutlined'),
|
|
|
|
{
|
|
|
|
ssr: false,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
const EyeInvisibleOutlined = dynamic(() => import('@ant-design/icons/EyeInvisibleOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const SmallDashOutlined = dynamic(() => import('@ant-design/icons/SmallDashOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export type ChatModerationActionMenuProps = {
|
2022-07-17 03:30:05 +03:00
|
|
|
accessToken: string;
|
|
|
|
messageID: string;
|
|
|
|
userID: string;
|
|
|
|
userDisplayName: string;
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
2022-07-17 03:30:05 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const ChatModerationActionMenu: FC<ChatModerationActionMenuProps> = ({
|
|
|
|
messageID,
|
|
|
|
userID,
|
|
|
|
userDisplayName,
|
|
|
|
accessToken,
|
|
|
|
}) => {
|
2022-07-17 03:30:05 +03:00
|
|
|
const [showUserDetailsModal, setShowUserDetailsModal] = useState(false);
|
|
|
|
|
|
|
|
const handleBanUser = async () => {
|
|
|
|
try {
|
2022-07-21 06:42:23 +03:00
|
|
|
await ChatModeration.banUser(userID, accessToken);
|
2022-07-17 03:30:05 +03:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
2022-07-21 06:42:23 +03:00
|
|
|
message.error(e);
|
2022-07-17 03:30:05 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleHideMessage = async () => {
|
|
|
|
try {
|
2022-07-21 06:42:23 +03:00
|
|
|
await ChatModeration.removeMessage(messageID, accessToken);
|
2022-07-17 03:30:05 +03:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
2022-07-21 06:42:23 +03:00
|
|
|
message.error(e);
|
2022-07-17 03:30:05 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const confirmHideMessage = async () => {
|
|
|
|
confirm({
|
|
|
|
icon: <ExclamationCircleOutlined />,
|
|
|
|
content: `Are you sure you want to remove this message from ${userDisplayName}?`,
|
|
|
|
onOk() {
|
|
|
|
handleHideMessage();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const confirmBanUser = async () => {
|
|
|
|
confirm({
|
|
|
|
icon: <ExclamationCircleOutlined />,
|
|
|
|
content: `Are you sure you want to ban ${userDisplayName} from chat?`,
|
|
|
|
onOk() {
|
|
|
|
handleBanUser();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onMenuClick: MenuProps['onClick'] = ({ key }) => {
|
|
|
|
if (key === 'hide-message') {
|
|
|
|
confirmHideMessage();
|
|
|
|
} else if (key === 'ban-user') {
|
|
|
|
confirmBanUser();
|
|
|
|
} else if (key === 'more-info') {
|
|
|
|
setShowUserDetailsModal(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const menu = (
|
|
|
|
<Menu
|
|
|
|
onClick={onMenuClick}
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
label: (
|
|
|
|
<div>
|
2022-09-07 10:00:28 +03:00
|
|
|
<span className={styles.icon}>
|
2022-07-17 03:30:05 +03:00
|
|
|
<EyeInvisibleOutlined />
|
|
|
|
</span>
|
|
|
|
Hide Message
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
key: 'hide-message',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
|
|
|
<div>
|
2022-09-07 10:00:28 +03:00
|
|
|
<span className={styles.icon}>
|
2022-07-17 03:30:05 +03:00
|
|
|
<CloseCircleOutlined />
|
|
|
|
</span>
|
|
|
|
Ban User
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
key: 'ban-user',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <div>More Info...</div>,
|
|
|
|
key: 'more-info',
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Dropdown overlay={menu} trigger={['click']}>
|
|
|
|
<button type="button" onClick={e => e.preventDefault()}>
|
|
|
|
<Space>
|
|
|
|
<SmallDashOutlined />
|
|
|
|
</Space>
|
|
|
|
</button>
|
|
|
|
</Dropdown>
|
|
|
|
<Modal
|
2022-10-02 21:02:21 +03:00
|
|
|
title={userDisplayName}
|
2022-10-11 03:11:29 +03:00
|
|
|
open={showUserDetailsModal}
|
2022-10-02 21:02:21 +03:00
|
|
|
handleCancel={() => {
|
2022-07-17 03:30:05 +03:00
|
|
|
setShowUserDetailsModal(false);
|
|
|
|
}}
|
|
|
|
>
|
2022-07-21 06:42:23 +03:00
|
|
|
<ChatModerationDetailsModal userId={userID} accessToken={accessToken} />
|
2022-07-17 03:30:05 +03:00
|
|
|
</Modal>
|
|
|
|
</>
|
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|