fix: Duplicate email template
(cherry picked from commit 7e6d5c3e544b784b07ae0975b4ae784fb9f9ee46)
This commit is contained in:
parent
ab6ea90c66
commit
3f51da59ad
@ -1,5 +1,9 @@
|
||||
<template>
|
||||
<NewEmailTemplate v-if="step === 'new-template'" @updateStep="updateStep" />
|
||||
<NewEmailTemplate
|
||||
v-if="step === 'new-template'"
|
||||
:templateData="template"
|
||||
@updateStep="updateStep"
|
||||
/>
|
||||
<EmailTemplates
|
||||
v-else-if="step === 'template-list'"
|
||||
@updateStep="updateStep"
|
||||
|
||||
@ -197,7 +197,14 @@ function toggleEmailTemplate(template) {
|
||||
|
||||
function deleteTemplate(template) {
|
||||
confirmDelete.value = false
|
||||
templates.delete.submit(template.name)
|
||||
templates.delete.submit(template.name, {
|
||||
onSuccess: () => {
|
||||
toast.success(__('Template deleted successfully'))
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(error.messages[0] || __('Failed to delete template'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function getDropdownOptions(template) {
|
||||
@ -209,9 +216,7 @@ function getDropdownOptions(template) {
|
||||
option: __('Edit'),
|
||||
icon: 'edit-2',
|
||||
active: props.active,
|
||||
onClick: () => {
|
||||
emit('updateStep', 'edit-template', { ...template })
|
||||
},
|
||||
onClick: () => emit('updateStep', 'edit-template', { ...template }),
|
||||
}),
|
||||
},
|
||||
{
|
||||
@ -221,7 +226,7 @@ function getDropdownOptions(template) {
|
||||
option: __('Duplicate'),
|
||||
icon: 'copy',
|
||||
active: props.active,
|
||||
onClick: () => {},
|
||||
onClick: () => emit('updateStep', 'new-template', { ...template }),
|
||||
}),
|
||||
},
|
||||
{
|
||||
|
||||
@ -10,12 +10,16 @@
|
||||
@click="() => emit('updateStep', 'template-list')"
|
||||
>
|
||||
<FeatherIcon name="chevron-left" class="size-5" />
|
||||
<span class="text-xl font-semibold">{{ __('New Template') }}</span>
|
||||
<span class="text-xl font-semibold">
|
||||
{{
|
||||
templateData?.name ? __('Duplicate template') : __('New template')
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex item-center space-x-2 w-3/12 justify-end">
|
||||
<Button
|
||||
:label="__('Create')"
|
||||
:label="templateData?.name ? __('Duplicate') : __('Create')"
|
||||
icon-left="plus"
|
||||
variant="solid"
|
||||
@click="createTemplate"
|
||||
@ -126,7 +130,14 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { TextEditor, FormControl, Switch, toast } from 'frappe-ui'
|
||||
import { inject, ref } from 'vue'
|
||||
import { inject, onMounted, ref } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
templateData: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['updateStep'])
|
||||
const errorMessage = ref('')
|
||||
@ -176,4 +187,12 @@ const createTemplate = () => {
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (props.templateData) {
|
||||
Object.assign(template.value, props.templateData)
|
||||
template.value.name = template.value.name + ' - Copy'
|
||||
template.value.enabled = false // Default to disabled for new templates
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user