mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 12:11:08 -04:00
added mark as default changes in estimate and invoice template
This commit is contained in:
@ -31,6 +31,10 @@ const props = defineProps({
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
isMarkAsDefault: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
const modalStore = useModalStore()
|
||||
@ -38,6 +42,17 @@ const modalStore = useModalStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
function openTemplateModal() {
|
||||
let markAsDefaultDescription = ''
|
||||
if (props.storeProp == 'newEstimate') {
|
||||
markAsDefaultDescription = t(
|
||||
'estimates.mark_as_default_estimate_template_description'
|
||||
)
|
||||
} else if (props.storeProp == 'newInvoice') {
|
||||
markAsDefaultDescription = t(
|
||||
'invoices.mark_as_default_invoice_template_description'
|
||||
)
|
||||
}
|
||||
|
||||
modalStore.openModal({
|
||||
title: t('general.choose_template'),
|
||||
componentName: 'SelectTemplate',
|
||||
@ -45,6 +60,8 @@ function openTemplateModal() {
|
||||
templates: props.store.templates,
|
||||
store: props.store,
|
||||
storeProp: props.storeProp,
|
||||
isMarkAsDefault: props.isMarkAsDefault,
|
||||
markAsDefaultDescription,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -58,7 +58,18 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!modalStore.data.store.isEdit" class="z-0 flex ml-3 pt-5">
|
||||
<BaseCheckbox
|
||||
v-model="modalStore.data.isMarkAsDefault"
|
||||
:set-initial-value="false"
|
||||
variant="primary"
|
||||
:label="$t('general.mark_as_default')"
|
||||
:description="modalStore.data.markAsDefaultDescription"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid">
|
||||
<BaseButton class="mr-3" variant="primary-outline" @click="closeModal">
|
||||
{{ $t('general.cancel') }}
|
||||
@ -76,8 +87,10 @@
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { useModalStore } from '@/scripts/stores/modal'
|
||||
import { useUserStore } from '@/scripts/admin/stores/user'
|
||||
|
||||
const modalStore = useModalStore()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const selectedTemplate = ref('')
|
||||
|
||||
@ -100,6 +113,22 @@ function setData() {
|
||||
|
||||
async function chooseTemplate() {
|
||||
await modalStore.data.store.setTemplate(selectedTemplate.value)
|
||||
// update default estimate or invoice template
|
||||
if (!modalStore.data.store.isEdit && modalStore.data.isMarkAsDefault) {
|
||||
if (modalStore.data.storeProp == 'newEstimate') {
|
||||
await userStore.updateUserSettings({
|
||||
settings: {
|
||||
default_estimate_template: selectedTemplate.value,
|
||||
},
|
||||
})
|
||||
} else if (modalStore.data.storeProp == 'newInvoice') {
|
||||
await userStore.updateUserSettings({
|
||||
settings: {
|
||||
default_invoice_template: selectedTemplate.value,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
closeModal()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user