I have a dashboard with different leads that are also sorted under different statuses.
For now all the different leads get sorted under the different statuses and it looks like this in my setup(). The changeStatus is for dragging the leads in to other statuses. (They are sorted under different "cards")
const leads = ref<Leads[]>([])
const sellerFilter = ref<number | null>(null)
const statuses = useStore(leadStatuses)
const leadsByStatus = computed(() =>
Object.assign(
fromPairs(statuses.value.map(s => [s.id, []])),
groupBy(
leads.value.filter(lead => lead.id),
'idStatus',
),
),
)
const changeStatus = async (evt: any) => {
const idStatus = evt.target.getAttribute('status-id')
const id = evt.item.getAttribute('lead-id')
await ('lead/update', { id }, { idStatus })
const lead = find(leads.value, ['id', parseInt(id)])
assert(!!lead)
lead.idStatus = idStatus
}
This works just fine. But now I want to add the possibility to filter on the seller assigned to the lead and I can't manage to work together in the opportunities computed. I have a seller-select that I'm importing and using in the template:
<user-select
v-model="sellerFilter"
:label="$tc('Filter on sales person')"
/>
I've tried doing something like this in the "opportunities" computed:
const leadsByStatus = computed(() => {
function filterOnSeller(filterSeller: number | null, leadSeller: number | null) {
return filterSeller && filterSeller !== dealSeller
}
return Object.assign(
fromPairs(statuses.value.map(s => [s.id, []])),
groupBy(
opportunities.value.filter(lead => {
if (filterSeller(sellerFilter.value, lead.salesId)) {
return true
}
return lead.salesId
}),
'idStatus',
),
)
})
But I can't manage to get above work when I want to make the filter on seller part work.
In the template I'm also using a v-for to iterate through all the leads:
<v-card
v-for="lead in leadsByStatus[status.id]"
:key="lead.id"
:lead-id="lead.id"
>
So if there's anyone that's know what I'm doing wrong? :)