Skip to content

Commit

Permalink
Merge pull request #406 from shariquerik/email-template-html-fix
Browse files Browse the repository at this point in the history
fix: Added content type instead of use html checkbox
  • Loading branch information
shariquerik authored Oct 11, 2024
2 parents 83d5b33 + 7a38433 commit 013906e
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions frontend/src/components/Modals/EmailTemplateModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,33 @@
:placeholder="__('Payment Reminder from Frappé - (#{{ name }})')"
/>
</div>
<div>
<div class="mb-1.5 text-sm text-gray-600">
{{ __('Content Type') }}
</div>
<Select
variant="outline"
v-model="_emailTemplate.content_type"
default="Rich Text"
:options="['Rich Text', 'HTML']"
:placeholder="__('Rich Text')"
/>
</div>
<div>
<div class="mb-1.5 text-sm text-gray-600">
{{ __('Content') }}
<span class="text-red-500">*</span>
</div>
<FormControl
v-if="_emailTemplate.use_html"
v-if="_emailTemplate.content_type === 'HTML'"
type="textarea"
variant="outline"
ref="content"
:rows="10"
v-model="_emailTemplate.response_html"
:placeholder="
__(
'<p>Dear {{ lead_name }},</p>\n\n<p>This is a reminder for the payment of {{ grand_total }}.</p>\n\n<p>Thanks,</p>\n<p>Frappé</p>'
'<p>Dear {{ lead_name }},</p>\n\n<p>This is a reminder for the payment of {{ grand_total }}.</p>\n\n<p>Thanks,</p>\n<p>Frappé</p>',
)
"
/>
Expand All @@ -78,17 +90,14 @@
@change="(val) => (_emailTemplate.response = val)"
:placeholder="
__(
'Dear {{ lead_name }}, \n\nThis is a reminder for the payment of {{ grand_total }}. \n\nThanks, \nFrappé'
'Dear {{ lead_name }}, \n\nThis is a reminder for the payment of {{ grand_total }}. \n\nThanks, \nFrappé',
)
"
/>
</div>
<div>
<Checkbox v-model="_emailTemplate.enabled" :label="__('Enabled')" />
</div>
<div>
<Checkbox v-model="_emailTemplate.use_html" :label="__('Use HTML')" />
</div>
<ErrorMessage :message="__(errorMessage)" />
</div>
</template>
Expand Down Expand Up @@ -116,7 +125,9 @@ const emit = defineEmits(['after'])
const subjectRef = ref(null)
const nameRef = ref(null)
const editMode = ref(false)
let _emailTemplate = ref({})
let _emailTemplate = ref({
content_type: 'Rich Text',
})
async function updateEmailTemplate() {
if (!validate()) return
Expand Down Expand Up @@ -184,6 +195,9 @@ function handleEmailTemplateUpdate(doc) {
}
function validate() {
_emailTemplate.value.use_html = Boolean(
_emailTemplate.value.content_type == 'HTML',
)
if (!_emailTemplate.value.name) {
errorMessage.value = 'Name is required'
return false
Expand All @@ -193,12 +207,17 @@ function validate() {
return false
}
if (
!_emailTemplate.value.response ||
_emailTemplate.value.response === '<p></p>'
!_emailTemplate.value.use_html &&
(!_emailTemplate.value.response ||
_emailTemplate.value.response === '<p></p>')
) {
errorMessage.value = 'Content is required'
return false
}
if (_emailTemplate.value.use_html && !_emailTemplate.value.response_html) {
errorMessage.value = 'Content is required'
return false
}
return true
}
Expand All @@ -215,10 +234,13 @@ watch(
nameRef.value.el.focus()
}
_emailTemplate.value = { ...props.emailTemplate }
_emailTemplate.value.content_type = _emailTemplate.value.use_html
? 'HTML'
: 'Rich Text'
if (_emailTemplate.value.name) {
editMode.value = true
}
})
}
},
)
</script>

0 comments on commit 013906e

Please sign in to comment.