feat: email template update and deletion
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-5">
|
||||
<Button @click="() => (showForm = true)">
|
||||
<Button @click="openTemplateForm('new')">
|
||||
<template #prefix>
|
||||
<Plus class="h-3 w-3 stroke-1.5" />
|
||||
</template>
|
||||
@@ -26,9 +26,7 @@
|
||||
:options="{
|
||||
showTooltip: false,
|
||||
onRowClick: (row) => {
|
||||
if (readOnlyMode) return
|
||||
selectedTemplate = row.name
|
||||
showForm = true
|
||||
openTemplateForm(row.name)
|
||||
},
|
||||
}"
|
||||
>
|
||||
@@ -50,20 +48,26 @@
|
||||
<ListRow :row="row" v-for="row in emailTemplates.data">
|
||||
<template #default="{ column, item }">
|
||||
<ListRowItem :item="row[column.key]" :align="column.align">
|
||||
<div v-if="column.key == 'use_html'">
|
||||
<FormControl
|
||||
v-model="row[column.key]"
|
||||
type="checkbox"
|
||||
:disabled="true"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="leading-5 text-sm">
|
||||
<div class="leading-5 text-sm">
|
||||
{{ row[column.key] }}
|
||||
</div>
|
||||
</ListRowItem>
|
||||
</template>
|
||||
</ListRow>
|
||||
</ListRows>
|
||||
|
||||
<ListSelectBanner>
|
||||
<template #actions="{ unselectAll, selections }">
|
||||
<div class="flex gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
@click="removeTemplate(selections, unselectAll)"
|
||||
>
|
||||
<Trash2 class="h-4 w-4 stroke-1.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</ListSelectBanner>
|
||||
</ListView>
|
||||
</div>
|
||||
</div>
|
||||
@@ -75,16 +79,17 @@
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
call,
|
||||
createListResource,
|
||||
ListView,
|
||||
ListHeader,
|
||||
ListHeaderItem,
|
||||
ListSelectBanner,
|
||||
FormControl,
|
||||
ListRows,
|
||||
ListRow,
|
||||
ListRowItem,
|
||||
Button,
|
||||
toast,
|
||||
} from 'frappe-ui'
|
||||
import { computed, ref } from 'vue'
|
||||
import { Plus, Trash2 } from 'lucide-vue-next'
|
||||
@@ -107,29 +112,48 @@ const selectedTemplate = ref(null)
|
||||
|
||||
const emailTemplates = createListResource({
|
||||
doctype: 'Email Template',
|
||||
fields: ['name', 'subject', 'use_html', 'response'],
|
||||
fields: ['name', 'subject', 'use_html', 'response', 'response_html'],
|
||||
auto: true,
|
||||
orderBy: 'modified desc',
|
||||
cache: 'email-templates',
|
||||
})
|
||||
|
||||
const removeTemplate = (selections, unselectAll) => {
|
||||
call('lms.lms.api.delete_documents', {
|
||||
doctype: 'Email Template',
|
||||
documents: Array.from(selections),
|
||||
})
|
||||
.then(() => {
|
||||
emailTemplates.reload()
|
||||
toast.success(__('Email Templates deleted successfully'))
|
||||
unselectAll()
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error(
|
||||
cleanError(err.messages[0]) || __('Error deleting email templates')
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const openTemplateForm = (templateID) => {
|
||||
if (readOnlyMode) {
|
||||
return
|
||||
}
|
||||
selectedTemplate.value = templateID
|
||||
showForm.value = true
|
||||
}
|
||||
|
||||
const columns = computed(() => {
|
||||
return [
|
||||
{
|
||||
label: 'Name',
|
||||
key: 'name',
|
||||
width: '15rem',
|
||||
width: '20rem',
|
||||
},
|
||||
{
|
||||
label: 'Subject',
|
||||
key: 'subject',
|
||||
width: '18rem',
|
||||
},
|
||||
{
|
||||
label: 'Use HTML',
|
||||
key: 'use_html',
|
||||
width: '10rem',
|
||||
align: 'right',
|
||||
width: '25rem',
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
:description="activeTab.description"
|
||||
/>
|
||||
<PaymentSettings
|
||||
v-else-if="activeTab.label === 'Payment'"
|
||||
v-else-if="activeTab.label === 'Payment Gateway'"
|
||||
:label="activeTab.label"
|
||||
:description="activeTab.description"
|
||||
:data="data"
|
||||
@@ -176,7 +176,7 @@ const tabsStructure = computed(() => {
|
||||
hideLabel: true,
|
||||
items: [
|
||||
{
|
||||
label: 'Payment',
|
||||
label: 'Payment Gateway',
|
||||
icon: 'DollarSign',
|
||||
description:
|
||||
'Configure the payment gateway and other payment related settings',
|
||||
|
||||
@@ -67,7 +67,7 @@ const paymentGateway = createResource({
|
||||
})
|
||||
|
||||
const arrangeFields = (fields) => {
|
||||
fields = data.fields.sort((a, b) => {
|
||||
fields = fields.sort((a, b) => {
|
||||
if (a.type === 'Upload' && b.type !== 'Upload') {
|
||||
return 1
|
||||
} else if (a.type !== 'Upload' && b.type === 'Upload') {
|
||||
|
||||
@@ -153,6 +153,11 @@
|
||||
doctype="Email Template"
|
||||
:label="__('Email Template')"
|
||||
v-model="batch.confirmation_email_template"
|
||||
:onCreate="
|
||||
(value, close) => {
|
||||
openSettings('Email Templates', close)
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-5">
|
||||
|
||||
Reference in New Issue
Block a user