fix: removed unnessary code from organization & contact modal
This commit is contained in:
parent
9f9fbebdfe
commit
4432e1b582
@ -1,11 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dialog v-model="show" :options="dialogOptions">
|
<Dialog v-model="show" :options="{ size: 'xl' }">
|
||||||
<template #body>
|
<template #body>
|
||||||
<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>
|
||||||
<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') }}
|
{{ __('New Contact') }}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-1">
|
<div class="flex items-center gap-1">
|
||||||
@ -34,10 +34,10 @@
|
|||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<Button
|
<Button
|
||||||
class="w-full"
|
class="w-full"
|
||||||
v-for="action in dialogOptions.actions"
|
variant="solid"
|
||||||
:key="action.label"
|
:label="__('Create')"
|
||||||
v-bind="action"
|
:loading="loading"
|
||||||
:label="__(action.label)"
|
@click="createContact"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -75,35 +75,14 @@ const { isManager } = usersStore()
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const show = defineModel()
|
const show = defineModel()
|
||||||
|
|
||||||
const editMode = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
let _contact = ref({})
|
let _contact = ref({})
|
||||||
let _address = ref({})
|
let _address = ref({})
|
||||||
|
|
||||||
const showAddressModal = ref(false)
|
const showAddressModal = ref(false)
|
||||||
|
|
||||||
async function updateContact() {
|
async function createContact() {
|
||||||
if (!dirty.value) {
|
|
||||||
show.value = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const values = { ..._contact.value }
|
|
||||||
|
|
||||||
let name = await callSetValue(values)
|
|
||||||
|
|
||||||
handleContactUpdate({ name })
|
|
||||||
}
|
|
||||||
|
|
||||||
async function callSetValue(values) {
|
|
||||||
const d = await call('frappe.client.set_value', {
|
|
||||||
doctype: 'Contact',
|
|
||||||
name: props.contact.data.name,
|
|
||||||
fieldname: values,
|
|
||||||
})
|
|
||||||
return d.name
|
|
||||||
}
|
|
||||||
|
|
||||||
async function callInsertDoc() {
|
|
||||||
if (_contact.value.email_id) {
|
if (_contact.value.email_id) {
|
||||||
_contact.value.email_ids = [{ email_id: _contact.value.email_id }]
|
_contact.value.email_ids = [{ email_id: _contact.value.email_id }]
|
||||||
delete _contact.value.email_id
|
delete _contact.value.email_id
|
||||||
@ -138,22 +117,6 @@ function handleContactUpdate(doc) {
|
|||||||
props.options.afterInsert && props.options.afterInsert(doc)
|
props.options.afterInsert && props.options.afterInsert(doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialogOptions = computed(() => {
|
|
||||||
let title = !editMode.value ? 'New Contact' : _contact.value.full_name
|
|
||||||
|
|
||||||
let size = 'xl'
|
|
||||||
let actions = [
|
|
||||||
{
|
|
||||||
label: editMode.value ? 'Save' : 'Create',
|
|
||||||
variant: 'solid',
|
|
||||||
disabled: !dirty.value,
|
|
||||||
onClick: () => (editMode.value ? updateContact() : callInsertDoc()),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
return { title, size, actions }
|
|
||||||
})
|
|
||||||
|
|
||||||
const tabs = createResource({
|
const tabs = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
cache: ['QuickEntry', 'Contact'],
|
cache: ['QuickEntry', 'Contact'],
|
||||||
@ -199,20 +162,12 @@ const filteredSections = computed(() => {
|
|||||||
return [{ no_tabs: true, sections: allSections }]
|
return [{ no_tabs: true, sections: allSections }]
|
||||||
})
|
})
|
||||||
|
|
||||||
const dirty = computed(() => {
|
|
||||||
return JSON.stringify(props.contact.data) !== JSON.stringify(_contact.value)
|
|
||||||
})
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => show.value,
|
() => show.value,
|
||||||
(value) => {
|
(value) => {
|
||||||
if (!value) return
|
if (!value) return
|
||||||
editMode.value = false
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
_contact.value = { ...props.contact.data }
|
_contact.value = { ...props.contact.data }
|
||||||
if (_contact.value.name) {
|
|
||||||
editMode.value = true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dialog v-model="show" :options="dialogOptions">
|
<Dialog v-model="show" :options="{ size: 'xl' }">
|
||||||
<template #body>
|
<template #body>
|
||||||
<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>
|
||||||
<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') }}
|
{{ __('New Organization') }}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-1">
|
<div class="flex items-center gap-1">
|
||||||
@ -34,11 +34,10 @@
|
|||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<Button
|
<Button
|
||||||
class="w-full"
|
class="w-full"
|
||||||
v-for="action in dialogOptions.actions"
|
variant="solid"
|
||||||
:key="action.label"
|
:label="__('Create')"
|
||||||
v-bind="action"
|
|
||||||
:label="__(action.label)"
|
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
@click="createOrganization"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -75,8 +74,9 @@ const organization = defineModel('organization')
|
|||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const title = ref(null)
|
const title = ref(null)
|
||||||
const editMode = ref(false)
|
|
||||||
let _address = ref({})
|
let _address = ref({})
|
||||||
|
|
||||||
let _organization = ref({
|
let _organization = ref({
|
||||||
organization_name: '',
|
organization_name: '',
|
||||||
website: '',
|
website: '',
|
||||||
@ -89,54 +89,7 @@ const showAddressModal = ref(false)
|
|||||||
|
|
||||||
let doc = ref({})
|
let doc = ref({})
|
||||||
|
|
||||||
async function updateOrganization() {
|
async function createOrganization() {
|
||||||
const old = { ...doc.value }
|
|
||||||
const newOrg = { ..._organization.value }
|
|
||||||
|
|
||||||
const nameChanged = old.organization_name !== newOrg.organization_name
|
|
||||||
delete old.organization_name
|
|
||||||
delete newOrg.organization_name
|
|
||||||
|
|
||||||
const otherFieldChanged = JSON.stringify(old) !== JSON.stringify(newOrg)
|
|
||||||
const values = newOrg
|
|
||||||
|
|
||||||
if (!nameChanged && !otherFieldChanged) {
|
|
||||||
show.value = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let name
|
|
||||||
loading.value = true
|
|
||||||
if (nameChanged) {
|
|
||||||
name = await callRenameDoc()
|
|
||||||
}
|
|
||||||
if (otherFieldChanged) {
|
|
||||||
name = await callSetValue(values)
|
|
||||||
}
|
|
||||||
handleOrganizationUpdate({ name }, nameChanged)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function callRenameDoc() {
|
|
||||||
const d = await call('frappe.client.rename_doc', {
|
|
||||||
doctype: 'CRM Organization',
|
|
||||||
old_name: doc.value?.organization_name,
|
|
||||||
new_name: _organization.value.organization_name,
|
|
||||||
})
|
|
||||||
loading.value = false
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
async function callSetValue(values) {
|
|
||||||
const d = await call('frappe.client.set_value', {
|
|
||||||
doctype: 'CRM Organization',
|
|
||||||
name: _organization.value.name,
|
|
||||||
fieldname: values,
|
|
||||||
})
|
|
||||||
loading.value = false
|
|
||||||
return d.name
|
|
||||||
}
|
|
||||||
|
|
||||||
async function callInsertDoc() {
|
|
||||||
const doc = await call('frappe.client.insert', {
|
const doc = await call('frappe.client.insert', {
|
||||||
doc: {
|
doc: {
|
||||||
doctype: 'CRM Organization',
|
doctype: 'CRM Organization',
|
||||||
@ -150,35 +103,19 @@ async function callInsertDoc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleOrganizationUpdate(doc, renamed = false) {
|
function handleOrganizationUpdate(doc) {
|
||||||
if (doc.name && (props.options.redirect || renamed)) {
|
if (doc.name && props.options.redirect) {
|
||||||
router.push({
|
router.push({
|
||||||
name: 'Organization',
|
name: 'Organization',
|
||||||
params: { organizationId: doc.name },
|
params: { organizationId: doc.name },
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
organization.value.reload?.()
|
organization.value?.reload?.()
|
||||||
}
|
}
|
||||||
show.value = false
|
show.value = false
|
||||||
props.options.afterInsert && props.options.afterInsert(doc)
|
props.options.afterInsert && props.options.afterInsert(doc)
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialogOptions = computed(() => {
|
|
||||||
let title = !editMode.value
|
|
||||||
? __('New Organization')
|
|
||||||
: __(_organization.value.organization_name)
|
|
||||||
let size = 'xl'
|
|
||||||
let actions = [
|
|
||||||
{
|
|
||||||
label: editMode.value ? __('Save') : __('Create'),
|
|
||||||
variant: 'solid',
|
|
||||||
onClick: () => (editMode.value ? updateOrganization() : callInsertDoc()),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
return { title, size, actions }
|
|
||||||
})
|
|
||||||
|
|
||||||
const tabs = createResource({
|
const tabs = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
|
||||||
cache: ['QuickEntry', 'CRM Organization'],
|
cache: ['QuickEntry', 'CRM Organization'],
|
||||||
@ -228,15 +165,11 @@ watch(
|
|||||||
() => show.value,
|
() => show.value,
|
||||||
(value) => {
|
(value) => {
|
||||||
if (!value) return
|
if (!value) return
|
||||||
editMode.value = false
|
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
// TODO: Issue with FormControl
|
// TODO: Issue with FormControl
|
||||||
// title.value.el.focus()
|
// title.value.el.focus()
|
||||||
doc.value = organization.value?.doc || organization.value || {}
|
doc.value = organization.value?.doc || organization.value || {}
|
||||||
_organization.value = { ...doc.value }
|
_organization.value = { ...doc.value }
|
||||||
if (_organization.value.name) {
|
|
||||||
editMode.value = true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user