fix: save copy of all contacts

This commit is contained in:
Shariq Ansari 2024-01-24 23:21:53 +05:30
parent 234f443107
commit c39588e228
2 changed files with 10 additions and 2 deletions

View File

@ -110,7 +110,7 @@ const props = defineProps({
const values = defineModel()
const { contacts } = contactsStore()
const { getContacts } = contactsStore()
const emails = ref([])
const search = ref(null)
@ -119,8 +119,9 @@ const query = ref('')
const showOptions = ref(false)
const emailList = computed(() => {
let contacts = getContacts() || []
return (
contacts.data
contacts
?.filter((contact) => contact.email_id)
.map((contact) => {
return {

View File

@ -6,6 +6,7 @@ export const contactsStore = defineStore('crm-contacts', () => {
let contactsByPhone = reactive({})
let contactsByName = reactive({})
let leadContactsByPhone = reactive({})
let allContacts = reactive([])
const contacts = createResource({
url: 'crm.api.session.get_contacts',
@ -20,6 +21,7 @@ export const contactsStore = defineStore('crm-contacts', () => {
contactsByPhone[contact.mobile_no] = contact
contactsByName[contact.name] = contact
}
allContacts = [...contacts]
return contacts
},
onError(error) {
@ -63,8 +65,13 @@ export const contactsStore = defineStore('crm-contacts', () => {
return leadContactsByPhone[mobile_no]
}
function getContacts() {
return allContacts || contacts?.data || []
}
return {
contacts,
getContacts,
getContact,
getContactByName,
getLeadContact,