diff --git a/app/both/collections/groups.js b/app/both/collections/groups.js index c2cfc645c..b590f61b0 100644 --- a/app/both/collections/groups.js +++ b/app/both/collections/groups.js @@ -12,6 +12,10 @@ var GroupsSchema = new SimpleSchema({ Groups.attachSchema(GroupsSchema); +Meteor.startup(()=>{ + Groups._ensureIndex({ name: 1 }, { unique: true }); +}) + Groups.helpers({ 'homes': function () { // Get group ID diff --git a/app/client/views/groups/modal/autoform.js b/app/client/views/groups/modal/autoform.js index c308db215..a359d6a32 100644 --- a/app/client/views/groups/modal/autoform.js +++ b/app/client/views/groups/modal/autoform.js @@ -2,10 +2,16 @@ AutoForm.addHooks(['groupForm'], { onSuccess: function() { // Hide the modal dialogue Modal.hide('newGroup'); - FlashMessages.clear(); }, - onError: function(formType, error) { - FlashMessages.sendError(' ' + error.message, { + onError: function(formType, errorObj) { + const { error } = errorObj; + let message = errorObj.message; + + if (error === 500) { + message = TAPi18n.__('homes-addNewGroup-duplicateName-errorMessage'); + } + + FlashMessages.sendError(' ' + message, { autoHide: true, hideDelay: 3000 }); diff --git a/app/lib/i18n/en.i18n.json b/app/lib/i18n/en.i18n.json index 19614d679..c47b74934 100644 --- a/app/lib/i18n/en.i18n.json +++ b/app/lib/i18n/en.i18n.json @@ -174,6 +174,7 @@ "homes-header": "Homes", "users-deactivateOn-label": "Deactivate on", "homes-header-addNewButton-group": "Add Group", + "homes-addNewGroup-duplicateName-errorMessage": "Error creating data. Make sure the group name is not duplicated.", "homes-homeGroup-addNewButton-home": "Add Home", "homes-homeGroup-assignManagerButton-home": "Assign Manager", "noDataToDisplay": "No data to display",