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'
233233import { useLang } from ' ../../lang/index.js'
234- import { ref , toRefs , watch , nextTick , computed } from ' vue'
234+ import { ref , toRefs , watch , computed } from ' vue'
235235import CompanySelect from ' ../company/CompanySelect.vue'
236236import ClientSelect from ' ../client/ClientSelect.vue'
237237import {
@@ -244,6 +244,7 @@ import NumberPrefixSelect from '../numberPrefix/NumberPrefixSelect.vue'
244244import { NumberPrefix , Invoice , Company } from ' @slimfact/api/zod'
245245import ClientForm from ' ../client/ClientForm.vue'
246246import { computeNumberPrefix } from ' src/tools.js'
247+ import { until } from ' @vueuse/core'
247248
248249export interface Props {
249250 filteredCompanies: Company []
@@ -389,8 +390,22 @@ const submit: InstanceType<typeof ResponsiveDialog>['$props']['onSubmit'] = ({
389390}
390391const 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
396411watch (
@@ -452,12 +467,13 @@ const currencySymbols = ref({
452467const updateClientFormRef = ref <typeof ClientForm >()
453468const 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
463479const submitClient: InstanceType <
0 commit comments