refactor: organization modal code refactor
(cherry picked from commit 93629972464163a41063317c4337b77b24aaf166) # Conflicts: # frontend/src/components/Modals/OrganizationModal.vue
This commit is contained in:
parent
e623e0628f
commit
985c538044
@ -17,7 +17,16 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<<<<<<< HEAD
|
||||||
<FieldLayout v-if="tabs.data?.length" :tabs="tabs.data" :data="_organization" doctype="CRM Organization" />
|
<FieldLayout v-if="tabs.data?.length" :tabs="tabs.data" :data="_organization" doctype="CRM Organization" />
|
||||||
|
=======
|
||||||
|
<FieldLayout
|
||||||
|
v-if="tabs.data?.length"
|
||||||
|
:tabs="tabs.data"
|
||||||
|
:data="organization.doc"
|
||||||
|
doctype="CRM Organization"
|
||||||
|
/>
|
||||||
|
>>>>>>> 9362997 (refactor: organization modal code refactor)
|
||||||
<ErrorMessage class="mt-8" v-if="error" :message="__(error)" />
|
<ErrorMessage class="mt-8" v-if="error" :message="__(error)" />
|
||||||
</div>
|
</div>
|
||||||
<div class="px-4 pt-4 pb-7 sm:px-6">
|
<div class="px-4 pt-4 pb-7 sm:px-6">
|
||||||
@ -47,6 +56,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: {
|
||||||
@ -60,27 +73,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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -104,8 +109,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)
|
||||||
@ -123,13 +126,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] = []
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -139,10 +142,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() {
|
||||||
|
|||||||
@ -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),
|
||||||
|
|||||||
@ -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),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user