Skip to content

Commit

Permalink
Added a feature to copy messages
Browse files Browse the repository at this point in the history
  • Loading branch information
devanshkansagra committed Dec 21, 2024
1 parent 1058405 commit 39252b1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/layout_editor/src/views/Message/MessageToolbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions packages/layout_editor/src/views/ThemeLab/LayoutSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ const LayoutSetting = () => {
},
iconName: 'edit',
},
copy: {
label: 'Copy message',
id: 'copy',
onClick: () => {
addMessageSurfaceItem('copy');
},
iconName: 'copy',
},
delete: {
label: 'Delete',
id: 'delete',
Expand Down
18 changes: 18 additions & 0 deletions packages/react/src/views/Message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -209,6 +226,7 @@ const Message = ({
authenticatedUserId={authenticatedUserId}
userRoles={userRoles}
pinRoles={pinRoles}
handleCopyMessage={handleCopyMessage}
handleOpenThread={handleOpenThread}
handleDeleteMessage={handleDeleteMessage}
handleStarMessage={handleStarMessage}
Expand Down
11 changes: 11 additions & 0 deletions packages/react/src/views/Message/MessageToolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const MessageToolbox = ({
handleStarMessage,
handleDeleteMessage,
handlerReportMessage,
handleCopyMessage,
handleEditMessage,
handleQuoteMessage,
isEditing = false,
Expand All @@ -38,6 +39,7 @@ export const MessageToolbox = ({
'reply',
'quote',
'star',
'copy',
'pin',
'edit',
'delete',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -152,6 +161,8 @@ export const MessageToolbox = ({
handlePinMessage,
handleEditMessage,
handlerReportMessage,
handleCopyMessage,
isAllowedToPin,
]
);

Expand Down

0 comments on commit 39252b1

Please sign in to comment.