fix: handle new document for call log
This commit is contained in:
parent
3b73432d8c
commit
832323f25e
@ -250,7 +250,7 @@
|
|||||||
</span>
|
</span>
|
||||||
<span v-if="activity.type">{{ __(activity.type) }}</span>
|
<span v-if="activity.type">{{ __(activity.type) }}</span>
|
||||||
<span
|
<span
|
||||||
v-if="activity.data.field_label"
|
v-if="activity.data?.field_label"
|
||||||
class="max-w-xs truncate font-medium text-ink-gray-8"
|
class="max-w-xs truncate font-medium text-ink-gray-8"
|
||||||
>
|
>
|
||||||
{{ __(activity.data.field_label) }}
|
{{ __(activity.data.field_label) }}
|
||||||
@ -307,7 +307,7 @@
|
|||||||
>
|
>
|
||||||
<div class="inline-flex flex-wrap gap-1 text-ink-gray-5">
|
<div class="inline-flex flex-wrap gap-1 text-ink-gray-5">
|
||||||
<span
|
<span
|
||||||
v-if="activity.data.field_label"
|
v-if="activity.data?.field_label"
|
||||||
class="max-w-xs truncate text-ink-gray-5"
|
class="max-w-xs truncate text-ink-gray-5"
|
||||||
>
|
>
|
||||||
{{ __(activity.data.field_label) }}
|
{{ __(activity.data.field_label) }}
|
||||||
|
|||||||
@ -91,10 +91,8 @@ function createCallLog() {
|
|||||||
let doctype = props.doctype
|
let doctype = props.doctype
|
||||||
let docname = props.doc.data?.name
|
let docname = props.doc.data?.name
|
||||||
callLog.value = {
|
callLog.value = {
|
||||||
data: {
|
reference_doctype: doctype,
|
||||||
reference_doctype: doctype,
|
reference_docname: docname,
|
||||||
reference_docname: docname,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
showCallLogModal.value = true
|
showCallLogModal.value = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,7 @@
|
|||||||
v-model:callLogModal="showCallLogModal"
|
v-model:callLogModal="showCallLogModal"
|
||||||
v-model:callLog="callLog"
|
v-model:callLog="callLog"
|
||||||
/>
|
/>
|
||||||
<CallLogModal v-model="showCallLogModal" v-model:callLog="callLog" />
|
<CallLogModal v-model="showCallLogModal" v-model:callLog="callLog.data" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
|
|||||||
@ -3,13 +3,19 @@
|
|||||||
<template #body>
|
<template #body>
|
||||||
<div class="px-4 pt-5 pb-6 bg-surface-modal sm:px-6">
|
<div class="px-4 pt-5 pb-6 bg-surface-modal sm:px-6">
|
||||||
<div class="flex items-center justify-between mb-5">
|
<div class="flex items-center justify-between mb-5">
|
||||||
<div>
|
<div class="flex items-center gap-2">
|
||||||
<h3 class="text-2xl font-semibold leading-6 text-ink-gray-9">
|
<h3 class="text-2xl font-semibold leading-6 text-ink-gray-9">
|
||||||
{{ __(dialogOptions.title) || __('Untitled') }}
|
{{ __(dialogOptions.title) || __('Untitled') }}
|
||||||
</h3>
|
</h3>
|
||||||
|
<Badge v-if="callLog.isDirty" :label="'Not Saved'" theme="orange" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-1">
|
<div class="flex items-center gap-1">
|
||||||
<Button v-if="isManager() && !isMobileView" variant="ghost" class="w-7" @click="openQuickEntryModal">
|
<Button
|
||||||
|
v-if="isManager() && !isMobileView"
|
||||||
|
variant="ghost"
|
||||||
|
class="w-7"
|
||||||
|
@click="openQuickEntryModal"
|
||||||
|
>
|
||||||
<EditIcon class="w-4 h-4" />
|
<EditIcon class="w-4 h-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" class="w-7" @click="show = false">
|
<Button variant="ghost" class="w-7" @click="show = false">
|
||||||
@ -18,19 +24,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="tabs.data">
|
<div v-if="tabs.data">
|
||||||
<FieldLayout :tabs="tabs.data" :data="_callLog" doctype="CRM Call Log" />
|
<FieldLayout
|
||||||
|
:tabs="tabs.data"
|
||||||
|
:data="callLog.doc"
|
||||||
|
doctype="CRM Call Log"
|
||||||
|
/>
|
||||||
<ErrorMessage class="mt-8" :message="error" />
|
<ErrorMessage class="mt-8" :message="error" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-4 pt-4 pb-7 sm:px-6">
|
<div class="px-4 pt-4 pb-7 sm:px-6">
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<Button class="w-full" v-for="action in dialogOptions.actions" :key="action.label" v-bind="action"
|
<Button
|
||||||
:label="__(action.label)" :loading="loading" />
|
class="w-full"
|
||||||
|
v-for="action in dialogOptions.actions"
|
||||||
|
:key="action.label"
|
||||||
|
v-bind="action"
|
||||||
|
:label="__(action.label)"
|
||||||
|
:loading="loading"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
<QuickEntryModal v-if="showQuickEntryModal" v-model="showQuickEntryModal" doctype="CRM Call Log" />
|
<QuickEntryModal
|
||||||
|
v-if="showQuickEntryModal"
|
||||||
|
v-model="showQuickEntryModal"
|
||||||
|
doctype="CRM Call Log"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@ -41,14 +61,21 @@ import { usersStore } from '@/stores/users'
|
|||||||
import { isMobileView } from '@/composables/settings'
|
import { isMobileView } from '@/composables/settings'
|
||||||
import { getRandom } from '@/utils'
|
import { getRandom } from '@/utils'
|
||||||
import { capture } from '@/telemetry'
|
import { capture } from '@/telemetry'
|
||||||
import { FeatherIcon, createResource, ErrorMessage } from 'frappe-ui'
|
import { useDocument } from '@/data/document'
|
||||||
|
import {
|
||||||
|
FeatherIcon,
|
||||||
|
createResource,
|
||||||
|
ErrorMessage,
|
||||||
|
Badge,
|
||||||
|
call,
|
||||||
|
} from 'frappe-ui'
|
||||||
import { ref, nextTick, watch, computed } from 'vue'
|
import { ref, nextTick, watch, computed } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
options: {
|
options: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: {
|
default: {
|
||||||
afterInsert: () => { },
|
afterInsert: () => {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -56,26 +83,14 @@ const props = defineProps({
|
|||||||
const { isManager } = usersStore()
|
const { isManager } = usersStore()
|
||||||
|
|
||||||
const show = defineModel()
|
const show = defineModel()
|
||||||
const callLog = defineModel('callLog')
|
const _callLog = defineModel('callLog')
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref(null)
|
const error = ref(null)
|
||||||
const title = ref(null)
|
const title = ref(null)
|
||||||
const editMode = ref(false)
|
const editMode = ref(false)
|
||||||
|
|
||||||
let _callLog = ref({
|
const callLog = ref(null)
|
||||||
name: '',
|
|
||||||
type: '',
|
|
||||||
from: '',
|
|
||||||
to: '',
|
|
||||||
medium: '',
|
|
||||||
duration: '',
|
|
||||||
caller: '',
|
|
||||||
receiver: '',
|
|
||||||
status: '',
|
|
||||||
recording_url: '',
|
|
||||||
telephony_medium: 'Manual',
|
|
||||||
})
|
|
||||||
|
|
||||||
const dialogOptions = computed(() => {
|
const dialogOptions = computed(() => {
|
||||||
let title = !editMode.value ? __('New Call Log') : __('Edit Call Log')
|
let title = !editMode.value ? __('New Call Log') : __('Edit Call Log')
|
||||||
@ -99,41 +114,28 @@ const tabs = createResource({
|
|||||||
auto: true,
|
auto: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
let doc = ref({})
|
const callBacks = {
|
||||||
|
onSuccess: (doc) => {
|
||||||
function updateCallLog() {
|
|
||||||
error.value = null
|
|
||||||
const old = { ...doc.value }
|
|
||||||
const newCallLog = { ..._callLog.value }
|
|
||||||
|
|
||||||
const dirty = JSON.stringify(old) !== JSON.stringify(newCallLog)
|
|
||||||
|
|
||||||
if (!dirty) {
|
|
||||||
show.value = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
loading.value = true
|
|
||||||
updateCallLogValues.submit({
|
|
||||||
doctype: 'CRM Call Log',
|
|
||||||
name: _callLog.value.name,
|
|
||||||
fieldname: newCallLog,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateCallLogValues = createResource({
|
|
||||||
url: 'frappe.client.set_value',
|
|
||||||
onSuccess(doc) {
|
|
||||||
loading.value = false
|
loading.value = false
|
||||||
if (doc.name) {
|
handleCallLogUpdate(doc)
|
||||||
handleCallLogUpdate(doc)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onError(err) {
|
onError: (err) => {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
|
if (err.exc_type == 'MandatoryError') {
|
||||||
|
const errorMessage = err.messages
|
||||||
|
.map((msg) => msg.split('Log:')[1].trim())
|
||||||
|
.join(', ')
|
||||||
|
error.value = `These fields are required: ${errorMessage}`
|
||||||
|
return
|
||||||
|
}
|
||||||
error.value = err
|
error.value = err
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
|
async function updateCallLog() {
|
||||||
|
loading.value = true
|
||||||
|
await callLog.value.save.submit(null, callBacks)
|
||||||
|
}
|
||||||
|
|
||||||
const createCallLog = createResource({
|
const createCallLog = createResource({
|
||||||
url: 'frappe.client.insert',
|
url: 'frappe.client.insert',
|
||||||
@ -143,7 +145,7 @@ const createCallLog = createResource({
|
|||||||
doctype: 'CRM Call Log',
|
doctype: 'CRM Call Log',
|
||||||
id: getRandom(6),
|
id: getRandom(6),
|
||||||
telephony_medium: 'Manual',
|
telephony_medium: 'Manual',
|
||||||
..._callLog.value,
|
...callLog.value.doc,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -155,15 +157,7 @@ const createCallLog = createResource({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError(err) {
|
onError(err) {
|
||||||
loading.value = false
|
callBacks.onError(err)
|
||||||
if (err.exc_type == 'MandatoryError') {
|
|
||||||
const errorMessage = err.messages
|
|
||||||
.map(msg => msg.split('Log:')[1].trim())
|
|
||||||
.join(', ')
|
|
||||||
error.value = `These fields are required: ${errorMessage}`
|
|
||||||
return
|
|
||||||
}
|
|
||||||
error.value = err
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -177,15 +171,16 @@ watch(
|
|||||||
(value) => {
|
(value) => {
|
||||||
if (!value) return
|
if (!value) return
|
||||||
editMode.value = false
|
editMode.value = false
|
||||||
nextTick(() => {
|
|
||||||
// TODO: Issue with FormControl
|
let docname = _callLog.value?.name
|
||||||
// title.value.el.focus()
|
const { document } = useDocument('CRM Call Log', docname)
|
||||||
doc.value = callLog.value?.data || {}
|
callLog.value = document
|
||||||
_callLog.value = { ...doc.value }
|
|
||||||
if (_callLog.value.name) {
|
if (docname) {
|
||||||
editMode.value = true
|
editMode.value = true
|
||||||
}
|
} else {
|
||||||
})
|
callLog.value.doc = { ..._callLog.value }
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@
|
|||||||
/>
|
/>
|
||||||
<CallLogModal
|
<CallLogModal
|
||||||
v-model="showCallLogModal"
|
v-model="showCallLogModal"
|
||||||
v-model:callLog="callLog"
|
v-model:callLog="callLog.data"
|
||||||
:options="{ afterInsert: () => callLogs.reload() }"
|
:options="{ afterInsert: () => callLogs.reload() }"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user