fix: validate before saving
This commit is contained in:
parent
b757a0170a
commit
dde6d3736f
@ -46,12 +46,14 @@
|
||||
{
|
||||
"fieldname": "exotel_number",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Exotel Number"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2025-01-15 16:19:21.965415",
|
||||
"modified": "2025-01-15 20:03:31.162162",
|
||||
"modified_by": "Administrator",
|
||||
"module": "FCRM",
|
||||
"name": "CRM Exotel Agent",
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
>
|
||||
<div>{{ __('Telephony Settings') }}</div>
|
||||
<Badge
|
||||
v-if="twilio.isDirty || exotel.isDirty"
|
||||
v-if="twilio.isDirty || exotel.isDirty || mediumChanged"
|
||||
:label="__('Not Saved')"
|
||||
variant="subtle"
|
||||
theme="orange"
|
||||
@ -59,8 +59,10 @@
|
||||
</div>
|
||||
<div class="flex justify-between gap-2">
|
||||
<div>
|
||||
<ErrorMessage class="mt-2" :message="twilio.save.error" />
|
||||
<ErrorMessage class="mt-2" :message="exotel.save.error" />
|
||||
<ErrorMessage
|
||||
class="mt-2"
|
||||
:message="twilio.save.error || exotel.save.error || error"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
:loading="twilio.save.loading || exotel.save.loading"
|
||||
@ -84,7 +86,7 @@ import {
|
||||
} from 'frappe-ui'
|
||||
import { defaultCallingMedium } from '@/composables/settings'
|
||||
import { createToast, getRandom } from '@/utils'
|
||||
import { computed } from 'vue'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
|
||||
const twilioFields = createResource({
|
||||
url: 'crm.api.doc.get_fields',
|
||||
@ -260,10 +262,17 @@ const exotelTabs = computed(() => {
|
||||
return _tabs
|
||||
})
|
||||
|
||||
async function update() {
|
||||
call('crm.integrations.api.set_default_calling_medium', {
|
||||
medium: defaultCallingMedium.value,
|
||||
})
|
||||
const mediumChanged = ref(false)
|
||||
|
||||
watch(defaultCallingMedium, () => {
|
||||
mediumChanged.value = true
|
||||
})
|
||||
|
||||
function update() {
|
||||
if (!validateIfDefaultMediumIsEnabled()) return
|
||||
if (mediumChanged.value) {
|
||||
updateMedium()
|
||||
}
|
||||
if (twilio.isDirty) {
|
||||
twilio.save.submit()
|
||||
}
|
||||
@ -271,4 +280,32 @@ async function update() {
|
||||
exotel.save.submit()
|
||||
}
|
||||
}
|
||||
|
||||
async function updateMedium() {
|
||||
await call('crm.integrations.api.set_default_calling_medium', {
|
||||
medium: defaultCallingMedium.value,
|
||||
})
|
||||
mediumChanged.value = false
|
||||
error.value = ''
|
||||
createToast({
|
||||
title: __('Success'),
|
||||
text: __('Default calling medium updated successfully'),
|
||||
icon: 'check',
|
||||
iconClasses: 'text-ink-green-3',
|
||||
})
|
||||
}
|
||||
|
||||
const error = ref('')
|
||||
|
||||
function validateIfDefaultMediumIsEnabled() {
|
||||
if (defaultCallingMedium.value === 'Twilio' && !twilio.doc.enabled) {
|
||||
error.value = __('Twilio is not enabled')
|
||||
return false
|
||||
}
|
||||
if (defaultCallingMedium.value === 'Exotel' && !exotel.doc.enabled) {
|
||||
error.value = __('Exotel is not enabled')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user