diff --git a/src/components/Container/ManageEmailsPage.vue b/src/components/Container/ManageEmailsPage.vue index d685a9b1b..3f7225777 100644 --- a/src/components/Container/ManageEmailsPage.vue +++ b/src/components/Container/ManageEmailsPage.vue @@ -346,16 +346,36 @@ export default { template = template || {}; this.currentTemplate = template; const {openSideModal} = useModal(); - this.$nextTick(() => - openSideModal(EditTemplateModal, { + + this.$nextTick(() => { + // Remove use group field if current mailable does not support specifying user group access + if (!this.currentMailable.canAssignUserGroupToTemplates) { + this.currentTemplateForm.fields = + this.currentTemplateForm.value.fields.filter( + (field) => field.name !== 'userGroupIds', + ); + } else { + const userGroupField = this.currentTemplateForm.fields.find( + (field) => field.name === 'userGroupIds', + ); + userGroupField.assignableUserGroups = + this.currentMailable['assignableTemplateUserGroups']; + userGroupField.assignedUserGroupIds = this.currentTemplate + ? this.currentTemplate['assignedUserGroupIds'] + : []; + } + + return openSideModal(EditTemplateModal, { title: this.currentTemplate ? t('manager.mailables.editTemplate') : t('manager.emails.addEmail'), currentTemplateForm: this.currentTemplateForm, + canAssignUserGroups: + this.currentMailable.canAssignUserGroupToTemplates, onUpdateCurrentTemplateForm: this.updateCurrentTemplateForm, onTemplateSaved: this.templateSaved, - }), - ); + }); + }); }, /** diff --git a/src/components/Form/FormGroup.vue b/src/components/Form/FormGroup.vue index ce7b6087c..d427190b1 100644 --- a/src/components/Form/FormGroup.vue +++ b/src/components/Form/FormGroup.vue @@ -78,6 +78,7 @@ import FieldTextarea from './fields/FieldTextarea.vue'; import FieldUpload from './fields/FieldUpload.vue'; import FieldSlider from './fields/FieldSlider.vue'; import FieldUploadImage from './fields/FieldUploadImage.vue'; +import FieldEmailTemplateUserGroupSettings from './fields/FieldEmailTemplateUserGroupSettings.vue'; import {shouldShowFieldWithinGroup} from './formHelpers'; @@ -109,6 +110,7 @@ export default { FieldSlider, FieldUpload, FieldUploadImage, + FieldEmailTemplateUserGroupSettings, }, props: { id: String, diff --git a/src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue b/src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue new file mode 100644 index 000000000..e936f54a2 --- /dev/null +++ b/src/components/Form/fields/FieldEmailTemplateUserGroupSettings.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/src/pages/manageEmails/EditTemplateModal.vue b/src/pages/manageEmails/EditTemplateModal.vue index 0ae12712d..9579f0fd6 100644 --- a/src/pages/manageEmails/EditTemplateModal.vue +++ b/src/pages/manageEmails/EditTemplateModal.vue @@ -23,6 +23,7 @@ import PkpForm from '@/components/Form/Form.vue'; defineProps({ title: {type: String, required: true}, currentTemplateForm: {required: true, type: Object}, + canAssignUserGroups: {default: false, type: Boolean}, }); const emit = defineEmits(['updateCurrentTemplateForm', 'templateSaved']);