mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 21:41:16 +00:00
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
import { getClientId } from "@/modules/shared/queries/profile"
|
|
import { getInvoices, getProductTemplates, peekNextInvoiceNumber } from "@/modules/shared/queries/invoices"
|
|
import { getStammdaten } from "@/modules/shared/queries/stammdaten"
|
|
import { BillingDialog, type BillingPrefill } from "@/modules/shared/ui/components/billing-dialog"
|
|
import { InvoicesTable } from "@/modules/shared/ui/components/invoices-table"
|
|
|
|
type Stammdaten = Awaited<ReturnType<typeof getStammdaten>>
|
|
|
|
async function AdminBillingDialog({ profileId, stammdaten }: { profileId: string; stammdaten: Stammdaten }) {
|
|
const [templates, nextInvoiceNumber] = await Promise.all([
|
|
getProductTemplates(),
|
|
peekNextInvoiceNumber(),
|
|
])
|
|
|
|
const client = stammdaten.client
|
|
const prefill: BillingPrefill | null = client
|
|
? {
|
|
companyName: client.company_name,
|
|
billingStreet: client.billing_street ?? client.street,
|
|
billingPostalCode: client.billing_postal_code ?? client.postal_code,
|
|
billingCity: client.billing_city ?? client.city,
|
|
billingCountry: client.billing_country ?? client.country,
|
|
}
|
|
: null
|
|
|
|
return (
|
|
<BillingDialog
|
|
profileId={profileId}
|
|
prefill={prefill}
|
|
nextInvoiceNumber={nextInvoiceNumber}
|
|
templates={templates}
|
|
recipientEmail={client?.contact_email ?? null}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export async function BillingPanel({
|
|
profileId,
|
|
isAdmin,
|
|
}: {
|
|
profileId: string
|
|
isAdmin: boolean
|
|
}) {
|
|
const clientId = await getClientId(profileId)
|
|
const [invoices, stammdaten] = await Promise.all([
|
|
clientId ? getInvoices(clientId) : [],
|
|
isAdmin ? getStammdaten(profileId) : null,
|
|
])
|
|
|
|
return (
|
|
<div className="flex w-full flex-col gap-6 md:gap-8">
|
|
<div className="flex w-full flex-wrap items-center justify-between gap-3">
|
|
<h1 className="text-2xl font-semibold md:text-3xl">Rechnungen</h1>
|
|
</div>
|
|
<InvoicesTable
|
|
profileId={profileId}
|
|
invoices={invoices}
|
|
isAdmin={isAdmin}
|
|
recipientEmail={stammdaten?.client?.contact_email ?? null}
|
|
actions={stammdaten ? <AdminBillingDialog profileId={profileId} stammdaten={stammdaten} /> : undefined}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|