fix: create/edit contact
This commit is contained in:
parent
e7bc5a900e
commit
9bd4b79ea0
@ -25,7 +25,7 @@ def get_contacts():
|
|||||||
|
|
||||||
contacts = frappe.qb.get_query(
|
contacts = frappe.qb.get_query(
|
||||||
"Contact",
|
"Contact",
|
||||||
fields=['name', 'full_name', 'image', 'email_id', 'mobile_no', 'phone', 'salutation'],
|
fields=['name', 'first_name', 'last_name', 'full_name', 'image', 'email_id', 'mobile_no', 'phone', 'salutation', 'company_name'],
|
||||||
order_by="first_name asc",
|
order_by="first_name asc",
|
||||||
distinct=True,
|
distinct=True,
|
||||||
).run(as_dict=1)
|
).run(as_dict=1)
|
||||||
|
|||||||
136
frontend/src/components/ContactModal.vue
Normal file
136
frontend/src/components/ContactModal.vue
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
<template>
|
||||||
|
<Dialog
|
||||||
|
v-model="show"
|
||||||
|
:options="{
|
||||||
|
title: editMode ? 'Edit contact' : 'New contact',
|
||||||
|
size: 'xl',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
label: editMode ? 'Update' : 'Create',
|
||||||
|
variant: 'solid',
|
||||||
|
disabled: !dirty,
|
||||||
|
onClick: ({ close }) => updateContact(close),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<template #body-content>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<FormControl
|
||||||
|
type="text"
|
||||||
|
size="md"
|
||||||
|
variant="outline"
|
||||||
|
label="Salutation"
|
||||||
|
v-model="_contact.salutation"
|
||||||
|
/>
|
||||||
|
<div class="flex gap-4">
|
||||||
|
<FormControl
|
||||||
|
class="flex-1"
|
||||||
|
variant="outline"
|
||||||
|
size="md"
|
||||||
|
type="text"
|
||||||
|
label="First Name"
|
||||||
|
v-model="_contact.first_name"
|
||||||
|
/>
|
||||||
|
<FormControl
|
||||||
|
class="flex-1"
|
||||||
|
variant="outline"
|
||||||
|
size="md"
|
||||||
|
type="text"
|
||||||
|
label="Last Name"
|
||||||
|
v-model="_contact.last_name"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FormControl
|
||||||
|
type="text"
|
||||||
|
variant="outline"
|
||||||
|
size="md"
|
||||||
|
label="Organisation"
|
||||||
|
v-model="_contact.company_name"
|
||||||
|
/>
|
||||||
|
<div class="flex gap-4">
|
||||||
|
<FormControl
|
||||||
|
class="flex-1"
|
||||||
|
variant="outline"
|
||||||
|
size="md"
|
||||||
|
type="text"
|
||||||
|
label="Mobile no"
|
||||||
|
v-model="_contact.mobile_no"
|
||||||
|
/>
|
||||||
|
<FormControl
|
||||||
|
class="flex-1"
|
||||||
|
variant="outline"
|
||||||
|
size="md"
|
||||||
|
type="email"
|
||||||
|
label="Email"
|
||||||
|
v-model="_contact.email_id"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { FormControl, Dialog, call } from 'frappe-ui'
|
||||||
|
import { ref, defineModel, nextTick, watch, computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
contact: {
|
||||||
|
type: Object,
|
||||||
|
default: {},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const show = defineModel()
|
||||||
|
const contacts = defineModel('reloadContacts')
|
||||||
|
|
||||||
|
const editMode = ref(false)
|
||||||
|
let _contact = ref({})
|
||||||
|
|
||||||
|
async function updateContact(close) {
|
||||||
|
if (JSON.stringify(props.contact) === JSON.stringify(_contact.value)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_contact.value.name) {
|
||||||
|
let d = await call('frappe.client.set_value', {
|
||||||
|
doctype: 'Contact',
|
||||||
|
name: _contact.value.name,
|
||||||
|
fieldname: _contact.value,
|
||||||
|
})
|
||||||
|
if (d.name) {
|
||||||
|
contacts.value.reload()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let d = await call('frappe.client.insert', {
|
||||||
|
doc: {
|
||||||
|
doctype: 'Contact',
|
||||||
|
..._contact.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (d.name) {
|
||||||
|
contacts.value.reload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
const dirty = computed(() => {
|
||||||
|
return JSON.stringify(props.contact) !== JSON.stringify(_contact.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => show.value,
|
||||||
|
(value) => {
|
||||||
|
if (!value) return
|
||||||
|
editMode.value = false
|
||||||
|
nextTick(() => {
|
||||||
|
_contact.value = { ...props.contact }
|
||||||
|
if (_contact.value.first_name) {
|
||||||
|
editMode.value = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</script>
|
||||||
@ -11,18 +11,31 @@
|
|||||||
{{ contact.salutation + ' ' + contact.full_name }}
|
{{ contact.salutation + ' ' + contact.full_name }}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2 text-base text-gray-700">
|
<div class="flex items-center gap-2 text-base text-gray-700">
|
||||||
<div class="flex items-center gap-1.5">
|
<div v-if="contact.email_id" class="flex items-center gap-1.5">
|
||||||
<EmailIcon class="h-4 w-4" />
|
<EmailIcon class="h-4 w-4" />
|
||||||
<span class="">{{ contact.email_id }}</span>
|
<span class="">{{ contact.email_id }}</span>
|
||||||
</div>
|
</div>
|
||||||
<span class="text-3xl leading-[0] text-gray-600">·</span>
|
<span
|
||||||
<div class="flex items-center gap-1.5">
|
v-if="contact.mobile_no"
|
||||||
|
class="text-3xl leading-[0] text-gray-600"
|
||||||
|
>·</span
|
||||||
|
>
|
||||||
|
<div v-if="contact.mobile_no" class="flex items-center gap-1.5">
|
||||||
<PhoneIcon class="h-4 w-4" />
|
<PhoneIcon class="h-4 w-4" />
|
||||||
<span class="">{{ contact.mobile_no }}</span>
|
<span class="">{{ contact.mobile_no }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<span
|
||||||
|
v-if="(contact.email_id || contact.mobile_no) && contact.company_name"
|
||||||
|
class="text-3xl leading-[0] text-gray-600"
|
||||||
|
>·</span
|
||||||
|
>
|
||||||
|
<div v-if="contact.company_name" class="flex items-center gap-1.5">
|
||||||
|
<Avatar :label="contact.company_name" size="xs" />
|
||||||
|
<span class="">{{ contact.company_name }}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1 flex gap-2">
|
<div class="mt-1 flex gap-2">
|
||||||
<Button label="Edit" size="sm">
|
<Button label="Edit" size="sm" @click="showContactModal = true">
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<EditIcon class="h-4 w-4" />
|
<EditIcon class="h-4 w-4" />
|
||||||
</template>
|
</template>
|
||||||
@ -39,14 +52,22 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ContactModal
|
||||||
|
v-model="showContactModal"
|
||||||
|
v-model:reloadContacts="contacts"
|
||||||
|
:contact="contact"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { FeatherIcon, Avatar } from 'frappe-ui'
|
import { FeatherIcon, Avatar } from 'frappe-ui'
|
||||||
|
import ContactModal from '@/components/ContactModal.vue'
|
||||||
import EmailIcon from '@/components/Icons/EmailIcon.vue'
|
import EmailIcon from '@/components/Icons/EmailIcon.vue'
|
||||||
import EditIcon from '@/components/Icons/EditIcon.vue'
|
import EditIcon from '@/components/Icons/EditIcon.vue'
|
||||||
import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
|
import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
|
||||||
|
import { contactsStore } from '@/stores/contacts.js'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
contact: {
|
contact: {
|
||||||
@ -54,4 +75,8 @@ const props = defineProps({
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { contacts } = contactsStore()
|
||||||
|
|
||||||
|
const showContactModal = ref(false)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
<Breadcrumbs :items="breadcrumbs" />
|
<Breadcrumbs :items="breadcrumbs" />
|
||||||
</template>
|
</template>
|
||||||
<template #right-header>
|
<template #right-header>
|
||||||
<Button variant="solid" label="Create">
|
<Button variant="solid" label="Create" @click="showContactModal = true">
|
||||||
<template #prefix><FeatherIcon name="plus" class="h-4" /></template>
|
<template #prefix><FeatherIcon name="plus" class="h-4" /></template>
|
||||||
</Button>
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
v-for="(contact, i) in contacts.data"
|
v-for="(contact, i) in contacts.data"
|
||||||
:key="i"
|
:key="i"
|
||||||
:class="[
|
:class="[
|
||||||
current_contact?.name === contact.name
|
currentContact?.name === contact.name
|
||||||
? 'bg-gray-50 hover:bg-gray-100'
|
? 'bg-gray-50 hover:bg-gray-100'
|
||||||
: 'hover:bg-gray-50',
|
: 'hover:bg-gray-50',
|
||||||
]"
|
]"
|
||||||
@ -33,7 +33,7 @@
|
|||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<router-view v-if="current_contact" :contact="current_contact" />
|
<router-view v-if="currentContact" :contact="currentContact" />
|
||||||
<div
|
<div
|
||||||
v-else
|
v-else
|
||||||
class="grid h-full place-items-center text-xl font-medium text-gray-500"
|
class="grid h-full place-items-center text-xl font-medium text-gray-500"
|
||||||
@ -45,20 +45,28 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ContactModal
|
||||||
|
v-model="showContactModal"
|
||||||
|
v-model:reloadContacts="contacts"
|
||||||
|
:contact="{}"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import LayoutHeader from '@/components/LayoutHeader.vue'
|
import LayoutHeader from '@/components/LayoutHeader.vue'
|
||||||
|
import ContactModal from '@/components/ContactModal.vue'
|
||||||
import ContactsIcon from '@/components/Icons/ContactsIcon.vue'
|
import ContactsIcon from '@/components/Icons/ContactsIcon.vue'
|
||||||
import { FeatherIcon, Breadcrumbs, Avatar } from 'frappe-ui'
|
import { FeatherIcon, Breadcrumbs, Avatar } from 'frappe-ui'
|
||||||
import { contactsStore } from '@/stores/contacts.js'
|
import { contactsStore } from '@/stores/contacts.js'
|
||||||
import { computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
const { contacts } = contactsStore()
|
const { contacts } = contactsStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const current_contact = computed(() => {
|
const showContactModal = ref(false)
|
||||||
|
|
||||||
|
const currentContact = computed(() => {
|
||||||
return contacts.data.find(
|
return contacts.data.find(
|
||||||
(contact) => contact.name === route.params.contactId
|
(contact) => contact.name === route.params.contactId
|
||||||
)
|
)
|
||||||
@ -66,12 +74,12 @@ const current_contact = computed(() => {
|
|||||||
|
|
||||||
const breadcrumbs = computed(() => {
|
const breadcrumbs = computed(() => {
|
||||||
let items = [{ label: 'Contacts', route: { name: 'Contacts' } }]
|
let items = [{ label: 'Contacts', route: { name: 'Contacts' } }]
|
||||||
if (!current_contact.value) return items
|
if (!currentContact.value) return items
|
||||||
items.push({
|
items.push({
|
||||||
label: current_contact.value.full_name,
|
label: currentContact.value.full_name,
|
||||||
route: {
|
route: {
|
||||||
name: 'Contact',
|
name: 'Contact',
|
||||||
params: { contactId: current_contact.value.name },
|
params: { contactId: currentContact.value.name },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return items
|
return items
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user