2023-07-13 23:28:12 +03:00
|
|
|
import { Dropdown, 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';
|
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();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-07-13 23:28:12 +03:00
|
|
|
const items: MenuProps['items'] = [
|
|
|
|
{
|
|
|
|
icon: <EyeInvisibleOutlined />,
|
|
|
|
label: 'Hide Message',
|
|
|
|
key: 'hide-message',
|
|
|
|
onClick: confirmHideMessage,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: <CloseCircleOutlined />,
|
|
|
|
label: 'Ban User',
|
|
|
|
key: 'ban-user',
|
|
|
|
onClick: confirmBanUser,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'More Info...',
|
|
|
|
key: 'more-info',
|
|
|
|
onClick: () => setShowUserDetailsModal(true),
|
|
|
|
},
|
|
|
|
];
|
2022-07-17 03:30:05 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-07-13 23:28:12 +03:00
|
|
|
<Dropdown menu={{ items }} trigger={['click']}>
|
2022-07-17 03:30:05 +03:00
|
|
|
<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
|
|
|
};
|