2024-10-17 03:10:27 +08:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
import { ChatEvents } from '/imports/ui/core/enums/chat';
|
|
|
|
import Icon from '/imports/ui/components/common/icon/component';
|
2024-10-18 00:30:52 +08:00
|
|
|
import {
|
|
|
|
Cancel, Highlighted, Left, Root,
|
|
|
|
} from './styles';
|
2024-10-17 03:10:27 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
editing: {
|
|
|
|
id: 'app.chat.toolbar.edit.editing',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
id: 'app.chat.toolbar.edit.cancel',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const CANCEL_KEY_LABEL = 'esc';
|
|
|
|
|
|
|
|
const ChatEditingWarning = () => {
|
|
|
|
const [show, setShow] = useState(false);
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const handleEditingMessage = (e: Event) => {
|
|
|
|
if (e instanceof CustomEvent) {
|
|
|
|
setShow(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCancelEditingMessage = (e: Event) => {
|
|
|
|
if (e instanceof CustomEvent) {
|
|
|
|
setShow(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.addEventListener(ChatEvents.CHAT_EDIT_REQUEST, handleEditingMessage);
|
|
|
|
window.addEventListener(ChatEvents.CHAT_CANCEL_EDIT_REQUEST, handleCancelEditingMessage);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener(ChatEvents.CHAT_EDIT_REQUEST, handleEditingMessage);
|
|
|
|
window.removeEventListener(ChatEvents.CHAT_CANCEL_EDIT_REQUEST, handleCancelEditingMessage);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!show) return null;
|
|
|
|
|
2024-10-18 00:30:52 +08:00
|
|
|
const cancelMessage = intl.formatMessage(intlMessages.cancel, { 0: CANCEL_KEY_LABEL });
|
2024-10-17 03:10:27 +08:00
|
|
|
const editingMessage = intl.formatMessage(intlMessages.editing);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Root role="note" aria-describedby="cancel-editing-msg">
|
|
|
|
<Left>
|
|
|
|
<Icon iconName="pen_tool" />
|
|
|
|
{editingMessage}
|
|
|
|
</Left>
|
2024-10-18 00:30:52 +08:00
|
|
|
<Cancel
|
|
|
|
onClick={() => {
|
|
|
|
window.dispatchEvent(new CustomEvent(ChatEvents.CHAT_CANCEL_EDIT_REQUEST));
|
|
|
|
}}
|
|
|
|
>
|
2024-10-17 03:10:27 +08:00
|
|
|
{cancelMessage.split(CANCEL_KEY_LABEL)[0]}
|
|
|
|
|
|
|
|
<Highlighted>{CANCEL_KEY_LABEL}</Highlighted>
|
|
|
|
|
|
|
|
{cancelMessage.split(CANCEL_KEY_LABEL)[1]}
|
2024-10-18 00:30:52 +08:00
|
|
|
</Cancel>
|
2024-10-17 03:10:27 +08:00
|
|
|
<span className="sr-only" id="cancel-editing-msg">
|
|
|
|
{`${editingMessage} ${cancelMessage}`}
|
|
|
|
</span>
|
|
|
|
</Root>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChatEditingWarning;
|