Skip to content

Commit ee1213f

Browse files
fix: fix client filtering and opening update dialogs
1 parent 413ac1f commit ee1213f

File tree

12 files changed

+152
-52
lines changed

12 files changed

+152
-52
lines changed

packages/api/src/repositories/client.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,13 @@ function find({
7272
)
7373

7474
query = query
75-
.groupBy('clients.id')
75+
.select((seb) =>
76+
seb.cast<number>(seb.fn.count('id').over(), 'integer').as('total')
77+
)
7678
.limit(pagination.limit)
7779
.offset(pagination.offset)
7880
}
79-
80-
return query.select((seb) => [
81-
...select,
82-
seb.cast<number>(seb.fn.count('id'), 'integer').as('total')
83-
])
81+
return query.select((seb) => [...select])
8482
}
8583

8684
export async function findClient({

packages/api/src/trpc/admin/clients.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const adminClientRoutes = ({
6060
searchClients: procedure
6161
.input(
6262
z.object({
63-
name: z.string(),
63+
name: z.string().nullable(),
6464
pagination: z
6565
.object({
6666
limit: z.number(),

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@pinia/colada": "0.21.2",
5858
"@quasar/extras": "1.17.0",
5959
"@quasar/quasar-ui-qcalendar": "4.1.2",
60-
"@simsustech/quasar-components": "0.11.24",
60+
"@simsustech/quasar-components": "0.11.25",
6161
"@slimfact/api": "link:../api",
6262
"@trpc/client": "11.9.0",
6363
"@trpc/server": "11.9.0",

packages/app/src/components/invoice/InvoiceForm.vue

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<q-form ref="formRef">
2+
<q-form v-if="filteredClients && filteredCompanies" ref="formRef">
33
<div class="grid grid-cols-12 gap-3">
44
<company-select
55
v-model="modelValue.companyId"
@@ -231,7 +231,7 @@ import {
231231
type RawInvoiceSurcharge
232232
} from '@modular-api/fastify-checkout'
233233
import { useLang } from '../../lang/index.js'
234-
import { ref, toRefs, watch, nextTick, computed } from 'vue'
234+
import { ref, toRefs, watch, computed } from 'vue'
235235
import CompanySelect from '../company/CompanySelect.vue'
236236
import ClientSelect from '../client/ClientSelect.vue'
237237
import {
@@ -244,6 +244,7 @@ import NumberPrefixSelect from '../numberPrefix/NumberPrefixSelect.vue'
244244
import { NumberPrefix, Invoice, Company } from '@slimfact/api/zod'
245245
import ClientForm from '../client/ClientForm.vue'
246246
import { computeNumberPrefix } from 'src/tools.js'
247+
import { until } from '@vueuse/core'
247248
248249
export interface Props {
249250
filteredCompanies: Company[]
@@ -389,8 +390,22 @@ const submit: InstanceType<typeof ResponsiveDialog>['$props']['onSubmit'] = ({
389390
}
390391
const setValue = (newValue: RawNewInvoice) => {
391392
modelValue.value = extend(true, {}, initialValue, newValue)
392-
modelValue.value.companyId = newValue.companyId || newValue.companyDetails.id
393-
modelValue.value.clientId = newValue.clientId || newValue.clientDetails.id
393+
if (newValue.companyId && !Number.isNaN(newValue.companyId)) {
394+
modelValue.value.companyId = newValue.companyId
395+
} else if (
396+
newValue.companyDetails.id &&
397+
!Number.isNaN(newValue.companyDetails.id)
398+
) {
399+
modelValue.value.companyId = newValue.companyDetails.id
400+
}
401+
if (newValue.clientId && !Number.isNaN(newValue.clientId)) {
402+
modelValue.value.clientId = newValue.clientId
403+
} else if (
404+
newValue.clientDetails.id &&
405+
!Number.isNaN(newValue.clientDetails.id)
406+
) {
407+
modelValue.value.companyId = newValue.clientDetails.id
408+
}
394409
}
395410
396411
watch(
@@ -452,12 +467,13 @@ const currencySymbols = ref({
452467
const updateClientFormRef = ref<typeof ClientForm>()
453468
const updateDialogRef = ref<typeof ResponsiveDialog>()
454469
455-
const openUpdateClientDialog = () => {
470+
const openUpdateClientDialog = async () => {
456471
const data = modelValue.value.clientDetails
457472
updateDialogRef.value?.functions.open()
458-
nextTick(() => {
459-
updateClientFormRef.value?.functions.setValue(data)
460-
})
473+
474+
await until(updateClientFormRef).toBeTruthy()
475+
476+
updateClientFormRef.value?.functions.setValue(data)
461477
}
462478
463479
const submitClient: InstanceType<

packages/app/src/pages/admin/BillsPage/BillsPage.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
@submit="update"
6161
>
6262
<invoice-form
63+
v-if="filteredCompanies && filteredClients"
6364
ref="updateInvoiceFormRef"
6465
:filtered-companies="filteredCompanies"
6566
:filtered-clients="filteredClients"
@@ -77,6 +78,7 @@
7778
@submit="create"
7879
>
7980
<invoice-form
81+
v-if="filteredCompanies && filteredClients"
8082
ref="createInvoiceFormRef"
8183
:filtered-companies="filteredCompanies"
8284
:filtered-clients="filteredClients"
@@ -200,9 +202,17 @@ const createDialogRef = ref<typeof ResponsiveDialog>()
200202
const openUpdateDialog: InstanceType<
201203
typeof ResourcePage
202204
>['$props']['onUpdate'] = async ({ data }) => {
205+
// @ts-expect-error untyped
206+
companiesSearchPhrase.value = data?.companyDetails?.name
207+
clientName.value =
208+
// @ts-expect-error untyped
209+
data?.clientDetails?.contactPersonName ?? data?.clientDetails?.companyName
210+
203211
updateDialogRef.value?.functions.open()
204212
205-
await until(updateDialogRef).toBeTruthy()
213+
await until(updateInvoiceFormRef).toBeTruthy()
214+
await until(filteredClientsAsyncStatus).toBe('idle')
215+
await until(filteredCompaniesAsyncStatus).toBe('idle')
206216
207217
updateInvoiceFormRef.value?.functions.setValue(data)
208218
}
@@ -258,7 +268,8 @@ const createInvoice: InstanceType<
258268
const {
259269
companies: filteredCompanies,
260270
searchPhrase: companiesSearchPhrase,
261-
refetch: refetchFilteredCompanies
271+
refetch: refetchFilteredCompanies,
272+
asyncStatus: filteredCompaniesAsyncStatus
262273
} = useAdminSearchCompaniesQuery()
263274
264275
// const filteredCompanies = ref<CompanyDetails[]>([])
@@ -274,8 +285,10 @@ const onFilterCompanies: InstanceType<
274285
const {
275286
clients: filteredClients,
276287
name: clientName,
277-
refetch: refetchFilteredClients
288+
refetch: refetchFilteredClients,
289+
asyncStatus: filteredClientsAsyncStatus
278290
} = useAdminSearchClientsQuery()
291+
279292
// const filteredClients = ref<ClientDetails>([])
280293
const onFilterClients: InstanceType<
281294
typeof InvoiceForm

packages/app/src/pages/admin/ClientsPage/ClientsPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const openUpdateDialog: InstanceType<
133133
typeof ResourcePage
134134
>['$props']['onUpdate'] = async ({ data }) => {
135135
updateDialogRef.value?.functions.open()
136-
await until(updateDialogRef).toBeTruthy()
136+
await until(updateClientFormRef).toBeTruthy()
137137
138138
updateClientFormRef.value?.functions.setValue(data)
139139
}

packages/app/src/pages/admin/InvoicesPage/InvoicesPage.vue

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,7 @@
6262
@submit="update"
6363
>
6464
<invoice-form
65-
v-if="
66-
filteredCompanies &&
67-
filteredClients &&
68-
filteredCompaniesAsyncStatus === 'idle' &&
69-
filteredClientsAsyncStatus === 'idle'
70-
"
65+
v-if="filteredCompanies && filteredClients"
7166
ref="updateInvoiceFormRef"
7267
:filtered-companies="filteredCompanies"
7368
:filtered-clients="filteredClients"
@@ -85,12 +80,7 @@
8580
@submit="create"
8681
>
8782
<invoice-form
88-
v-if="
89-
filteredCompanies &&
90-
filteredClients &&
91-
filteredCompaniesAsyncStatus === 'idle' &&
92-
filteredClientsAsyncStatus === 'idle'
93-
"
83+
v-if="filteredCompanies && filteredClients"
9484
ref="createInvoiceFormRef"
9585
:filtered-companies="filteredCompanies"
9686
:filtered-clients="filteredClients"
@@ -247,6 +237,9 @@ const openUpdateDialog: InstanceType<
247237
updateDialogRef.value?.functions.open()
248238
249239
await until(updateInvoiceFormRef).toBeTruthy()
240+
await until(filteredClientsAsyncStatus).toBe('idle')
241+
await until(filteredCompaniesAsyncStatus).toBe('idle')
242+
250243
updateInvoiceFormRef.value?.functions.setValue(data)
251244
}
252245

packages/app/src/pages/admin/SubscriptionsPage/SubscriptionsPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const openUpdateDialog: InstanceType<
158158
>['$props']['onUpdate'] = async ({ data }) => {
159159
updateDialogRef.value?.functions.open()
160160
161-
await until(updateDialogRef).toBeTruthy()
161+
await until(updateSubscriptionFormRef).toBeTruthy()
162162
163163
updateSubscriptionFormRef.value?.functions.setValue(data)
164164
}

packages/app/src/pages/admin/settings/CompaniesPage/CompaniesPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const openUpdateDialog: InstanceType<
8383
typeof ResourcePage
8484
>['$props']['onUpdate'] = async ({ data }) => {
8585
updateDialogRef.value?.functions.open()
86-
await until(updateDialogRef).toBeTruthy()
86+
await until(updateCompanyFormRef).toBeTruthy()
8787
8888
updateCompanyFormRef.value?.functions.setValue(data)
8989
}

packages/app/src/queries/admin/clients.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ref, computed } from 'vue'
44
import { Client } from '@slimfact/api/zod'
55

66
export const useAdminSearchClientsQuery = defineQuery(() => {
7-
const name = ref<string>('')
7+
const name = ref<string | null>(null)
88
const page = ref(1)
99
const rowsPerPage = ref(5)
1010
const pagination = computed<{
@@ -20,8 +20,7 @@ export const useAdminSearchClientsQuery = defineQuery(() => {
2020
}))
2121

2222
const { data: clients, ...rest } = useQuery({
23-
enabled: () =>
24-
!import.meta.env.SSR && name.value !== '' && name.value !== null,
23+
enabled: () => !import.meta.env.SSR && name.value !== null,
2524
key: () => ['adminSearchClients', name.value, pagination.value],
2625
query: () =>
2726
trpc.admin.searchClients.query({

0 commit comments

Comments
 (0)