feat: email template update and deletion
This commit is contained in:
@@ -25,21 +25,36 @@
|
||||
v-model="template.name"
|
||||
type="text"
|
||||
:required="true"
|
||||
:placeholder="__('Batch Enrollment Confirmation')"
|
||||
/>
|
||||
<FormControl
|
||||
:label="__('Subject')"
|
||||
v-model="template.subject"
|
||||
type="text"
|
||||
:required="true"
|
||||
:placeholder="__('Your enrollment in {{ batch_name }} is confirmed')"
|
||||
/>
|
||||
<FormControl
|
||||
:label="__('Use HTML')"
|
||||
v-model="template.use_html"
|
||||
type="checkbox"
|
||||
/>
|
||||
<div>
|
||||
<FormControl
|
||||
v-if="template.use_html"
|
||||
:label="__('Content')"
|
||||
v-model="template.response_html"
|
||||
type="textarea"
|
||||
:required="true"
|
||||
:rows="10"
|
||||
:placeholder="
|
||||
__(
|
||||
'<p>Dear {{ member_name }},</p>\n\n<p>You have been enrolled in our upcoming batch {{ batch_name }}.</p>\n\n<p>Thanks,</p>\n<p>Frappe Learning</p>'
|
||||
)
|
||||
"
|
||||
/>
|
||||
<div v-else>
|
||||
<div class="text-xs text-ink-gray-5 mb-2">
|
||||
{{ __('Response') }}
|
||||
{{ __('Content') }}
|
||||
<span class="text-ink-red-3">*</span>
|
||||
</div>
|
||||
<TextEditor
|
||||
@@ -47,6 +62,11 @@
|
||||
@change="(val) => (template.response = val)"
|
||||
:editable="true"
|
||||
:fixedMenu="true"
|
||||
:placeholder="
|
||||
__(
|
||||
'Dear {{ member_name }},\n\nYou have been enrolled in our upcoming batch {{ batch_name }}.\n\nThanks,\nFrappe Learning'
|
||||
)
|
||||
"
|
||||
editorClass="prose-sm max-w-none border-b border-x bg-surface-gray-2 rounded-b-md py-1 px-2 min-h-[7rem] max-h-[18rem] overflow-y-auto"
|
||||
/>
|
||||
</div>
|
||||
@@ -55,8 +75,8 @@
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { Dialog, FormControl, TextEditor, toast } from 'frappe-ui'
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { call, Dialog, FormControl, TextEditor, toast } from 'frappe-ui'
|
||||
import { reactive, watch } from 'vue'
|
||||
import { cleanError } from '@/utils'
|
||||
|
||||
const props = defineProps({
|
||||
@@ -66,8 +86,6 @@ const props = defineProps({
|
||||
},
|
||||
})
|
||||
|
||||
console.log(props.templateID)
|
||||
|
||||
const show = defineModel()
|
||||
const emailTemplates = defineModel('emailTemplates')
|
||||
const template = reactive({
|
||||
@@ -75,6 +93,7 @@ const template = reactive({
|
||||
subject: '',
|
||||
use_html: false,
|
||||
response: '',
|
||||
response_html: '',
|
||||
})
|
||||
|
||||
const saveTemplate = (close) => {
|
||||
@@ -88,19 +107,17 @@ const saveTemplate = (close) => {
|
||||
const createNewTemplate = (close) => {
|
||||
emailTemplates.value.insert.submit(
|
||||
{
|
||||
__newname: template.value.name,
|
||||
...template.value,
|
||||
__newname: template.name,
|
||||
...template,
|
||||
},
|
||||
{
|
||||
onSuccess() {
|
||||
emailTemplates.value.reload()
|
||||
close()
|
||||
refreshForm()
|
||||
refreshForm(close)
|
||||
toast.success(__('Email Template created successfully'))
|
||||
},
|
||||
onError(err) {
|
||||
close()
|
||||
refreshForm()
|
||||
refreshForm(close)
|
||||
toast.error(
|
||||
cleanError(err.messages[0]) || __('Error creating email template')
|
||||
)
|
||||
@@ -109,27 +126,42 @@ const createNewTemplate = (close) => {
|
||||
)
|
||||
}
|
||||
|
||||
const updateTemplate = (close) => {
|
||||
console.log(show)
|
||||
emailTemplates.value.setValue.submit({
|
||||
name: props.templateID,
|
||||
...template,
|
||||
}),
|
||||
const updateTemplate = async (close) => {
|
||||
if (props.templateID != template.name) {
|
||||
await renameDoc()
|
||||
}
|
||||
setValue(close)
|
||||
}
|
||||
|
||||
const setValue = (close) => {
|
||||
emailTemplates.value.setValue.submit(
|
||||
{
|
||||
...template,
|
||||
name: template.name,
|
||||
},
|
||||
{
|
||||
onSuccess() {
|
||||
emailTemplates.value.reload()
|
||||
close()
|
||||
refreshForm()
|
||||
refreshForm(close)
|
||||
console.log('template', template)
|
||||
toast.success(__('Email Template updated successfully'))
|
||||
},
|
||||
onError(err) {
|
||||
close()
|
||||
refreshForm()
|
||||
refreshForm(close)
|
||||
toast.error(
|
||||
cleanError(err.messages[0]) || __('Error updating email template')
|
||||
)
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const renameDoc = async () => {
|
||||
await call('frappe.client.rename_doc', {
|
||||
doctype: 'Email Template',
|
||||
old_name: props.templateID,
|
||||
new_name: template.name,
|
||||
})
|
||||
}
|
||||
|
||||
watch(
|
||||
@@ -142,6 +174,7 @@ watch(
|
||||
template.subject = row.subject
|
||||
template.use_html = row.use_html
|
||||
template.response = row.response
|
||||
template.response_html = row.response_html
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -149,10 +182,12 @@ watch(
|
||||
{ flush: 'post' }
|
||||
)
|
||||
|
||||
const refreshForm = () => {
|
||||
const refreshForm = (close) => {
|
||||
close()
|
||||
template.name = ''
|
||||
template.subject = ''
|
||||
template.use_html = false
|
||||
template.response = ''
|
||||
template.response_html = ''
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user