Finish send mail dialog, fixes #12

This commit is contained in:
2025-11-19 14:30:24 +01:00
parent 856d4d52a9
commit 4da724816e
5 changed files with 57 additions and 31 deletions
@@ -163,7 +163,6 @@ watch(invoice,
if (newValue.customerId && newValue.customerId !== 0) {
// if (importCustomer.value != newValue.customer)
// console.warn('trigger importCustomer watcher')
console.log(newValue, newValue.customerId)
customers.value.find(customer => {
if (customer.id === newValue.customerId) {
if (invoice.value) invoice.value.customer = customer as Customer
@@ -413,8 +412,8 @@ const openReminderDialog = function () {
reminderDialogOpen.value = true
}
const sendReminder = async function (recipient: string | undefined) {
if (!recipient) return
const sendReminder = async function (to: string | undefined, cc: string | undefined) {
if (!to) return
if (!invoice.value || !invoice.value.id) return
// Close dialog
@@ -425,8 +424,12 @@ const sendReminder = async function (recipient: string | undefined) {
try {
// await axios call
await axios.get('/api/invoices/' + invoice.value.id + '/remind/' + recipient)
toast.success("Zahlungserinnerung gesendet", { description: recipient })
let request = '/api/invoices/' + invoice.value.id + '/remind?to=' + to
if (cc) request += '&cc=' + cc
await axios.get(request)
invoice.value.paymentStatus = 'reminded'
save()
toast.success("Zahlungserinnerung gesendet", { description: to })
} catch (error: any) {
toast.error(error?.title || 'Fehler', { description: error?.message || String(error) })
} finally {
@@ -819,7 +822,7 @@ const updateLineItems = (newItems: LineItem[]) => {
</Dialog>
<SendMailDialog v-model:open="reminderDialogOpen" title="Zahlungserinnerung senden?" description=""
:recipient="billingContactEmail" @send="(recipient: string | undefined) => sendReminder(recipient)" />
:to="billingContactEmail" @send="(to, cc) => sendReminder(to, cc)" />
</template>
@@ -9,17 +9,19 @@ import { Label } from "@/components/ui/label"
const props = defineProps<DialogRootProps & {
title: string,
description?: string,
recipient?: string
to?: string,
cc?: string
}>()
const recipient = ref<string | undefined>(props.recipient)
const to = ref<string | undefined>(props.to)
const cc = ref<string | undefined>(props.cc)
const emits = defineEmits<DialogRootEmits & {
send: [recipient: string | undefined]
send: [to: string | undefined, cc: string | undefined]
}>()
const forwarded = useForwardPropsEmits(props, emits)
watch(() => props.open,
(newValue, oldValue) => {
recipient.value = props.recipient
to.value = props.to
}
)
</script>
@@ -32,15 +34,15 @@ watch(() => props.open,
<DialogDescription v-if="props.description" v-html="props.description" />
</DialogHeader>
<div class="grid grid-cols-[min-content_1fr] gap-4 py-4">
<Label for="email" class="text-right text-muted-foreground">
<Label for="to" class="text-right text-muted-foreground">
An
</Label>
<Input id="email" required v-model="recipient" type="email" placeholder="E-Mail" />
<Input id="to" required v-model="to" type="email" placeholder="E-Mail" />
<Label for="email" class="text-right text-muted-foreground">
<Label for="cc" class="text-right text-muted-foreground">
Kopie
</Label>
<Input id="email" required :value="'buchhaltung@tooloop.de'" type="email" placeholder="E-Mail" />
<Input id="cc" v-model="cc" type="email" placeholder="E-Mail" />
</div>
<DialogFooter>
<DialogClose as-child>
@@ -48,7 +50,7 @@ watch(() => props.open,
Abbrechen
</Button>
</DialogClose>
<Button variant="destructive" @click="$emit('send', recipient)">
<Button variant="destructive" @click="$emit('send', to, cc)">
E-Mail senden
</Button>
</DialogFooter>