refactor: removed contact store from MultiSelectInput

This commit is contained in:
Shariq Ansari 2024-03-13 12:53:29 +05:30
parent d37db923a3
commit 5d4272a572

View File

@ -93,7 +93,6 @@ import {
ComboboxOption, ComboboxOption,
} from '@headlessui/vue' } from '@headlessui/vue'
import UserAvatar from '@/components/UserAvatar.vue' import UserAvatar from '@/components/UserAvatar.vue'
import { contactsStore } from '@/stores/contacts'
import { Popover, createResource } from 'frappe-ui' import { Popover, createResource } from 'frappe-ui'
import { ref, computed, nextTick } from 'vue' import { ref, computed, nextTick } from 'vue'
import { watchDebounced } from '@vueuse/core' import { watchDebounced } from '@vueuse/core'
@ -111,8 +110,6 @@ const props = defineProps({
const values = defineModel() const values = defineModel()
const { getContactByName } = contactsStore()
const emails = ref([]) const emails = ref([])
const search = ref(null) const search = ref(null)
const error = ref(null) const error = ref(null)
@ -153,13 +150,13 @@ const filterOptions = createResource({
transform: (data) => { transform: (data) => {
let allData = data let allData = data
.filter((c) => { .filter((c) => {
return getContactByName(c.value).email_id return c.description.split(', ')[1]
}) })
.map((option) => { .map((option) => {
let c = getContactByName(option.value) let email = option.description.split(', ')[1]
return { return {
label: c.full_name || c.email_id, label: option.label || email,
value: c.email_id, value: email,
} }
}) })
return allData return allData
@ -222,19 +219,19 @@ const removeValue = (value) => {
const removeLastValue = () => { const removeLastValue = () => {
if (query.value) return if (query.value) return
let emailRef = emails.value[emails.value.length - 1].$el let emailRef = emails.value[emails.value.length - 1]?.$el
if (document.activeElement === emailRef) { if (document.activeElement === emailRef) {
values.value.pop() values.value.pop()
nextTick(() => { nextTick(() => {
if (values.value.length) { if (values.value.length) {
emailRef = emails.value[emails.value.length - 1].$el emailRef = emails.value[emails.value.length - 1].$el
emailRef.focus() emailRef?.focus()
} else { } else {
setFocus() setFocus()
} }
}) })
} else { } else {
emailRef.focus() emailRef?.focus()
} }
} }