fix: handle new document for call log
(cherry picked from commit 832323f25ef9f1231eb97f721317f306a0a2eabc) # Conflicts: # frontend/src/components/Modals/CallLogModal.vue
This commit is contained in:
parent
3d48e12744
commit
1870ced3b1
@ -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>
|
||||||
|
|||||||
@ -1,12 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dialog v-model="show" :options="dialogOptions">
|
<Dialog v-model="show" :options="dialogOptions">
|
||||||
<template #body>
|
<template #body>
|
||||||
|
<<<<<<< HEAD
|
||||||
<div class="bg-surface-modal px-4 pb-6 pt-5 sm:px-6">
|
<div class="bg-surface-modal px-4 pb-6 pt-5 sm:px-6">
|
||||||
<div class="mb-5 flex items-center justify-between">
|
<div class="mb-5 flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
|
=======
|
||||||
|
<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 gap-2">
|
||||||
|
>>>>>>> 832323f (fix: handle new document for call log)
|
||||||
<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
|
<Button
|
||||||
@ -15,7 +22,11 @@
|
|||||||
class="w-7"
|
class="w-7"
|
||||||
@click="openQuickEntryModal"
|
@click="openQuickEntryModal"
|
||||||
>
|
>
|
||||||
|
<<<<<<< HEAD
|
||||||
<EditIcon class="h-4 w-4" />
|
<EditIcon class="h-4 w-4" />
|
||||||
|
=======
|
||||||
|
<EditIcon class="w-4 h-4" />
|
||||||
|
>>>>>>> 832323f (fix: handle new document for call log)
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" class="w-7" @click="show = false">
|
<Button variant="ghost" class="w-7" @click="show = false">
|
||||||
<FeatherIcon name="x" class="h-4 w-4" />
|
<FeatherIcon name="x" class="h-4 w-4" />
|
||||||
@ -25,10 +36,17 @@
|
|||||||
<div v-if="tabs.data">
|
<div v-if="tabs.data">
|
||||||
<FieldLayout
|
<FieldLayout
|
||||||
:tabs="tabs.data"
|
:tabs="tabs.data"
|
||||||
|
<<<<<<< HEAD
|
||||||
:data="_callLog"
|
:data="_callLog"
|
||||||
doctype="CRM Call Log"
|
doctype="CRM Call Log"
|
||||||
/>
|
/>
|
||||||
<ErrorMessage class="mt-2" :message="error" />
|
<ErrorMessage class="mt-2" :message="error" />
|
||||||
|
=======
|
||||||
|
:data="callLog.doc"
|
||||||
|
doctype="CRM Call Log"
|
||||||
|
/>
|
||||||
|
<ErrorMessage class="mt-8" :message="error" />
|
||||||
|
>>>>>>> 832323f (fix: handle new document for call log)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="px-4 pb-7 pt-4 sm:px-6">
|
<div class="px-4 pb-7 pt-4 sm:px-6">
|
||||||
@ -60,7 +78,14 @@ 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({
|
||||||
@ -75,26 +100,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')
|
||||||
@ -118,41 +131,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',
|
||||||
@ -162,7 +162,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,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -174,8 +174,12 @@ const createCallLog = createResource({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError(err) {
|
onError(err) {
|
||||||
|
<<<<<<< HEAD
|
||||||
loading.value = false
|
loading.value = false
|
||||||
error.value = err
|
error.value = err
|
||||||
|
=======
|
||||||
|
callBacks.onError(err)
|
||||||
|
>>>>>>> 832323f (fix: handle new document for call log)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -189,15 +193,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