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