diff --git a/ee/app/canned-responses/server/methods/saveCannedResponse.js b/ee/app/canned-responses/server/methods/saveCannedResponse.js index 75ef452c5bb..f8cf69cf602 100644 --- a/ee/app/canned-responses/server/methods/saveCannedResponse.js +++ b/ee/app/canned-responses/server/methods/saveCannedResponse.js @@ -33,11 +33,16 @@ Meteor.methods({ if (!canSaveAll && !canSaveDepartment && ['department'].includes(responseData.scope)) { throw new Meteor.Error('error-not-allowed', 'Not allowed to modify canned responses on *department* scope', { method: 'saveCannedResponse' }); } + + // to avoid inconsistencies + if (responseData.scope === 'user') { + delete responseData.departmentId; + } // TODO: check if the department i'm trying to save is a department i can interact with // check if the response already exists and we're not updating one const duplicateShortcut = CannedResponse.findOneByShortcut(responseData.shortcut, { fields: { _id: 1 } }); - if ((!_id && duplicateShortcut) || (_id && duplicateShortcut._id !== _id)) { + if ((!_id && duplicateShortcut) || (_id && duplicateShortcut && duplicateShortcut._id !== _id)) { throw new Meteor.Error('error-invalid-shortcut', 'Shortcut provided already exists', { method: 'saveCannedResponse' }); } @@ -55,7 +60,6 @@ Meteor.methods({ throw new Meteor.Error('error-canned-response-not-found', 'Canned Response not found', { method: 'saveCannedResponse' }); } - responseData.scope = cannedResponse.scope; responseData.createdBy = cannedResponse.createdBy; } else { const user = Users.findOneById(Meteor.userId()); diff --git a/ee/client/omnichannel/cannedResponses/CannedResponseEdit.tsx b/ee/client/omnichannel/cannedResponses/CannedResponseEdit.tsx index 0ef4deb440e..58905943e05 100644 --- a/ee/client/omnichannel/cannedResponses/CannedResponseEdit.tsx +++ b/ee/client/omnichannel/cannedResponses/CannedResponseEdit.tsx @@ -105,7 +105,10 @@ const CannedResponseEdit: FC<{ ...(tags.length > 0 && { tags }), ...(departmentId && { departmentId: departmentId.value }), }); - dispatchToastMessage({ type: 'success', message: t('Canned_Response_Created') }); + dispatchToastMessage({ + type: 'success', + message: t(_id ? 'Canned_Response_Updated' : 'Canned_Response_Created'), + }); Route.push({ context: '', }); diff --git a/ee/client/omnichannel/components/CannedResponse/modals/CreateCannedResponse/index.tsx b/ee/client/omnichannel/components/CannedResponse/modals/CreateCannedResponse/index.tsx index c0fc7850820..978b5003274 100644 --- a/ee/client/omnichannel/components/CannedResponse/modals/CreateCannedResponse/index.tsx +++ b/ee/client/omnichannel/components/CannedResponse/modals/CreateCannedResponse/index.tsx @@ -92,7 +92,10 @@ const WrapCreateCannedResponseModal: FC<{ data?: any; reloadCannedList?: any }> ...(tags.length > 0 && { tags }), ...(departmentId && { departmentId: departmentId.value }), }); - dispatchToastMessage({ type: 'success', message: t('Canned_Response_Created') }); + dispatchToastMessage({ + type: 'success', + message: t(_id ? 'Canned_Response_Updated' : 'Canned_Response_Created'), + }); closeModal(null); reloadCannedList && reloadCannedList(); } catch (error) { diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 14700d4a307..32b9551ae54 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -701,7 +701,8 @@ "Cancel_message_input": "Cancel", "Canceled": "Canceled", "Canned Responses": "Canned Responses", - "Canned_Response_Created": "Canned Response Created", + "Canned_Response_Created": "Canned Response created", + "Canned_Response_Updated": "Canned Response updated", "Canned_Response_Delete_Warning": "Deleting a canned response cannot be undone.", "Canned_Response_Removed": "Canned Response Removed", "Canned_Response_Sharing_Department_Description": "Anyone in the selected department can access this canned response",