refactor: organization modal code refactor

This commit is contained in:
Shariq Ansari 2025-06-05 16:08:13 +05:30
parent 28ea88f61e
commit 9362997246
3 changed files with 16 additions and 22 deletions

View File

@ -25,7 +25,7 @@
<FieldLayout <FieldLayout
v-if="tabs.data?.length" v-if="tabs.data?.length"
:tabs="tabs.data" :tabs="tabs.data"
:data="_organization.doc" :data="organization.doc"
doctype="CRM Organization" doctype="CRM Organization"
/> />
<ErrorMessage class="mt-8" v-if="error" :message="__(error)" /> <ErrorMessage class="mt-8" v-if="error" :message="__(error)" />
@ -63,6 +63,10 @@ import { ref, nextTick, onMounted } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
const props = defineProps({ const props = defineProps({
data: {
type: Object,
default: () => ({}),
},
options: { options: {
type: Object, type: Object,
default: { default: {
@ -76,27 +80,19 @@ const { isManager } = usersStore()
const router = useRouter() const router = useRouter()
const show = defineModel() const show = defineModel()
const organization = defineModel('organization')
const loading = ref(false) const loading = ref(false)
const title = ref(null)
const { document: _organization } = useDocument('CRM Organization')
if (Object.keys(_organization.doc).length != 0) {
_organization.doc = { no_of_employees: '1-10' }
}
let doc = ref({})
const error = ref(null) const error = ref(null)
const { document: organization } = useDocument('CRM Organization')
async function createOrganization() { async function createOrganization() {
const doc = await call( const doc = await call(
'frappe.client.insert', 'frappe.client.insert',
{ {
doc: { doc: {
doctype: 'CRM Organization', doctype: 'CRM Organization',
..._organization.doc, ...organization.doc,
}, },
}, },
{ {
@ -120,8 +116,6 @@ function handleOrganizationUpdate(doc) {
name: 'Organization', name: 'Organization',
params: { organizationId: doc.name }, params: { organizationId: doc.name },
}) })
} else {
organization.value?.reload?.()
} }
show.value = false show.value = false
props.options.afterInsert && props.options.afterInsert(doc) props.options.afterInsert && props.options.afterInsert(doc)
@ -139,13 +133,13 @@ const tabs = createResource({
column.fields.forEach((field) => { column.fields.forEach((field) => {
if (field.fieldname == 'address') { if (field.fieldname == 'address') {
field.create = (value, close) => { field.create = (value, close) => {
_organization.doc.address = value organization.doc.address = value
openAddressModal() openAddressModal()
close() close()
} }
field.edit = (address) => openAddressModal(address) field.edit = (address) => openAddressModal(address)
} else if (field.fieldtype === 'Table') { } else if (field.fieldtype === 'Table') {
_organization.doc[field.fieldname] = [] organization.doc[field.fieldname] = []
} }
}) })
}) })
@ -155,10 +149,8 @@ const tabs = createResource({
}) })
onMounted(() => { onMounted(() => {
Object.assign( organization.doc = { no_of_employees: '1-10' }
_organization.doc, Object.assign(organization.doc, props.data)
organization.value?.doc || organization.value || {},
)
}) })
function openQuickEntryModal() { function openQuickEntryModal() {

View File

@ -272,8 +272,9 @@
:errorMessage="errorMessage" :errorMessage="errorMessage"
/> />
<OrganizationModal <OrganizationModal
v-if="showOrganizationModal"
v-model="showOrganizationModal" v-model="showOrganizationModal"
v-model:organization="_organization" :data="_organization"
:options="{ :options="{
redirect: false, redirect: false,
afterInsert: (doc) => updateField('organization', doc.name), afterInsert: (doc) => updateField('organization', doc.name),

View File

@ -214,8 +214,9 @@
</Tabs> </Tabs>
</div> </div>
<OrganizationModal <OrganizationModal
v-if="showOrganizationModal"
v-model="showOrganizationModal" v-model="showOrganizationModal"
v-model:organization="_organization" :data="_organization"
:options="{ :options="{
redirect: false, redirect: false,
afterInsert: (doc) => updateField('organization', doc.name), afterInsert: (doc) => updateField('organization', doc.name),