fix: added basic contact page

This commit is contained in:
Shariq Ansari 2023-11-04 00:40:24 +05:30
parent 5caf5101e2
commit 4ef6d4cfb9
2 changed files with 31 additions and 7 deletions

View File

@ -1,4 +1,9 @@
<template> <template>
<LayoutHeader v-if="contact">
<template #left-header>
<Breadcrumbs :items="breadcrumbs" />
</template>
</LayoutHeader>
<div class="flex gap-6 p-5"> <div class="flex gap-6 p-5">
<FileUploader @success="changeContactImage" :validateFile="validateFile"> <FileUploader @success="changeContactImage" :validateFile="validateFile">
<template #default="{ openFileSelector, error }"> <template #default="{ openFileSelector, error }">
@ -107,30 +112,43 @@
<script setup> <script setup>
import { import {
FeatherIcon, FeatherIcon,
Breadcrumbs,
Avatar, Avatar,
FileUploader, FileUploader,
ErrorMessage, ErrorMessage,
Dropdown, Dropdown,
call, call,
} from 'frappe-ui' } from 'frappe-ui'
import LayoutHeader from '@/components/LayoutHeader.vue'
import ContactModal from '@/components/ContactModal.vue' 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 CameraIcon from '@/components/Icons/CameraIcon.vue' import CameraIcon from '@/components/Icons/CameraIcon.vue'
import { contactsStore } from '@/stores/contacts.js' import { contactsStore } from '@/stores/contacts.js'
import { ref } from 'vue' import { ref, computed } from 'vue'
const { getContactByName, contacts } = contactsStore()
const showContactModal = ref(false)
const props = defineProps({ const props = defineProps({
contact: { contactId: {
type: Object, type: String,
required: true, required: true,
}, },
}) })
const { contacts } = contactsStore() const contact = computed(() => getContactByName(props.contactId))
const showContactModal = ref(false) const breadcrumbs = computed(() => {
let items = [{ label: 'Contacts', route: { name: 'Contacts' } }]
items.push({
label: contact.value.full_name,
route: { name: 'Contact', params: { contactId: contact.value.name } },
})
return items
})
function validateFile(file) { function validateFile(file) {
let extn = file.name.split('.').pop().toLowerCase() let extn = file.name.split('.').pop().toLowerCase()
@ -142,7 +160,7 @@ function validateFile(file) {
async function changeContactImage(file) { async function changeContactImage(file) {
await call('frappe.client.set_value', { await call('frappe.client.set_value', {
doctype: 'Contact', doctype: 'Contact',
name: props.contact.name, name: props.contactId,
fieldname: 'image', fieldname: 'image',
value: file?.file_url || '', value: file?.file_url || '',
}) })
@ -161,7 +179,7 @@ async function deleteContact() {
async onClick({ close }) { async onClick({ close }) {
await call('frappe.client.delete', { await call('frappe.client.delete', {
doctype: 'Contact', doctype: 'Contact',
name: props.contact.name, name: props.contactId,
}) })
contacts.reload() contacts.reload()
close() close()

View File

@ -4,6 +4,7 @@ import { reactive } from 'vue'
export const contactsStore = defineStore('crm-contacts', () => { export const contactsStore = defineStore('crm-contacts', () => {
let contactsByPhone = reactive({}) let contactsByPhone = reactive({})
let contactsByName = reactive({})
const contacts = createResource({ const contacts = createResource({
url: 'crm.api.session.get_contacts', url: 'crm.api.session.get_contacts',
@ -12,6 +13,7 @@ export const contactsStore = defineStore('crm-contacts', () => {
transform(contacts) { transform(contacts) {
for (let contact of contacts) { for (let contact of contacts) {
contactsByPhone[contact.mobile_no] = contact contactsByPhone[contact.mobile_no] = contact
contactsByName[contact.name] = contact
} }
return contacts return contacts
}, },
@ -26,9 +28,13 @@ export const contactsStore = defineStore('crm-contacts', () => {
function getContact(mobile_no) { function getContact(mobile_no) {
return contactsByPhone[mobile_no] return contactsByPhone[mobile_no]
} }
function getContactByName(name) {
return contactsByName[name]
}
return { return {
contacts, contacts,
getContact, getContact,
getContactByName,
} }
}) })