From 39252b1a01dc070f87b818238372d6d3c143305a Mon Sep 17 00:00:00 2001 From: Devansh Date: Sun, 22 Dec 2024 00:16:15 +0530 Subject: [PATCH] Added a feature to copy messages --- .../src/views/Message/MessageToolbox.jsx | 7 +++++++ .../src/views/ThemeLab/LayoutSetting.jsx | 8 ++++++++ packages/react/src/views/Message/Message.js | 18 ++++++++++++++++++ .../react/src/views/Message/MessageToolbox.js | 11 +++++++++++ 4 files changed, 44 insertions(+) diff --git a/packages/layout_editor/src/views/Message/MessageToolbox.jsx b/packages/layout_editor/src/views/Message/MessageToolbox.jsx index fbad6209c..0f4f347d5 100644 --- a/packages/layout_editor/src/views/Message/MessageToolbox.jsx +++ b/packages/layout_editor/src/views/Message/MessageToolbox.jsx @@ -148,6 +148,13 @@ export const MessageToolbox = ({ variantStyles = {}, ...props }) => { iconName: 'edit', visible: true, }, + copy: { + label: 'Copy message', + id: 'copy', + onClick: () => {}, + iconName: 'copy', + visible: true, + }, delete: { label: 'Delete', id: 'delete', diff --git a/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx b/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx index 0eba8d6ea..53d3874e4 100644 --- a/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx +++ b/packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx @@ -356,6 +356,14 @@ const LayoutSetting = () => { }, iconName: 'edit', }, + copy: { + label: 'Copy message', + id: 'copy', + onClick: () => { + addMessageSurfaceItem('copy'); + }, + iconName: 'copy', + }, delete: { label: 'Delete', id: 'delete', diff --git a/packages/react/src/views/Message/Message.js b/packages/react/src/views/Message/Message.js index e460adad0..795c1e48f 100644 --- a/packages/react/src/views/Message/Message.js +++ b/packages/react/src/views/Message/Message.js @@ -114,6 +114,23 @@ const Message = ({ } }; + const handleCopyMessage = async (msg) => { + navigator.clipboard + .writeText(msg.msg) + .then(() => { + dispatchToastMessage({ + type: 'success', + message: 'Message copied successfully', + }); + }) + .catch(() => { + dispatchToastMessage({ + type: 'error', + message: 'Error in copying message', + }); + }); + }; + const handleDeleteMessage = async (msg) => { const res = await RCInstance.deleteMessage(msg._id); @@ -209,6 +226,7 @@ const Message = ({ authenticatedUserId={authenticatedUserId} userRoles={userRoles} pinRoles={pinRoles} + handleCopyMessage={handleCopyMessage} handleOpenThread={handleOpenThread} handleDeleteMessage={handleDeleteMessage} handleStarMessage={handleStarMessage} diff --git a/packages/react/src/views/Message/MessageToolbox.js b/packages/react/src/views/Message/MessageToolbox.js index 55af7f64d..2bdafa18d 100644 --- a/packages/react/src/views/Message/MessageToolbox.js +++ b/packages/react/src/views/Message/MessageToolbox.js @@ -29,6 +29,7 @@ export const MessageToolbox = ({ handleStarMessage, handleDeleteMessage, handlerReportMessage, + handleCopyMessage, handleEditMessage, handleQuoteMessage, isEditing = false, @@ -38,6 +39,7 @@ export const MessageToolbox = ({ 'reply', 'quote', 'star', + 'copy', 'pin', 'edit', 'delete', @@ -124,6 +126,13 @@ export const MessageToolbox = ({ color: isEditing ? 'secondary' : 'default', ghost: !isEditing, }, + copy: { + label: 'Copy message', + id: 'copy', + onClick: () => handleCopyMessage(message), + iconName: 'copy', + visible: true, + }, delete: { label: 'Delete', id: 'delete', @@ -152,6 +161,8 @@ export const MessageToolbox = ({ handlePinMessage, handleEditMessage, handlerReportMessage, + handleCopyMessage, + isAllowedToPin, ] );