Quote builder
A quote with line items, discounts and totals in minor units, sent for acceptance. It loads its data on the server through the block's client.
pnpm dev:example) to see it.Add the components
terminal npx shadcn add card skeleton tableInstall the glue
Install the block with
npx better-supabase add quotes. The glue items are copied into your app, so edit them as you need.None: the page calls the block's client on the server.
Write the screen
React and shadcn
View in the examplequote-builder.tsx /** * Render inside `<Suspense>`: a quote's detail page, with its line items and * totals. A draft (or a quote with changes requested) is editable; the status * decides what comes next: send, record the customer's answer, or revise. */ export async function QuoteBuilder({ id }: { id: string }) { const [t, locale, permissions] = await Promise.all([ getExtracted("crm"), getLocale(), getPermissions(), ]); if (!can(permissions, "quotes.read")) { forbidden(); } const loaded = await settle(() => getQuote(id)); if (loaded.kind === "no-organization") { return null; } if (loaded.kind === "error") { return <CrmLoadError title={t("The quote didn't load")} />; } const quote = loaded.data; if (!quote) { notFound(); } const canWrite = can(permissions, "quotes.write"); const editable = canWrite && (quote.status === "draft" || quote.status === "changes_requested"); const totals = [ { label: t("Subtotal"), value: quote.subtotal }, { label: t("Discount"), value: quote.discountTotal }, { label: t("Tax"), value: quote.taxTotal }, ]; const lines = editable ? ( <QuoteLinesEditor key={quote.lines .map((line) => `${line.description}:${line.unitAmount.amount}`) .join(",")} quoteId={quote.id} currency={quote.currency} initialLines={quote.lines} /> ) : ( <Table> <TableHeader> <TableRow> <TableHead>{t("Description")}</TableHead> <TableHead className="text-right">{t("Qty")}</TableHead> <TableHead className="text-right">{t("Unit price")}</TableHead> <TableHead className="text-right">{t("Discount %")}</TableHead> <TableHead className="text-right">{t("Tax %")}</TableHead> </TableRow> </TableHeader> <TableBody> {quote.lines.length === 0 ? ( <TableRow> <TableCell colSpan={5} className="text-center text-sm text-muted-foreground" > {t("This quote has no lines.")} </TableCell> </TableRow> ) : null} {quote.lines.map((line) => ( <TableRow key={line.position}> <TableCell>{line.description}</TableCell> <TableCell className="text-right tabular-nums"> {line.quantity} </TableCell> <TableCell className="text-right tabular-nums"> {formatMoney(line.unitAmount, locale)} </TableCell> <TableCell className="text-right tabular-nums"> {line.discountBps / 100} </TableCell> <TableCell className="text-right tabular-nums"> {line.taxRateBps / 100} </TableCell> </TableRow> ))} </TableBody> </Table> ); return ( <div data-recipe="quote-builder"> <RecordDetailFrame title={quote.title} description={t("{identifier} rev. {revision, number}", { identifier: quote.identifier, revision: quote.revision, })} status={<QuoteStatusBadge status={quote.status} />} actions={ canWrite ? ( <QuoteStatusActions quoteId={quote.id} status={quote.status} hasLines={quote.lines.length > 0} /> ) : undefined } aside={ <Card size="sm"> <CardHeader> <CardTitle>{t("Totals")}</CardTitle> {quote.validUntil ? ( <CardDescription> {t("Valid until {date}", { date: Temporal.PlainDate.from( quote.validUntil, ).toLocaleString(locale, { dateStyle: "medium" }), })} </CardDescription> ) : null} </CardHeader> <CardContent> <dl className="grid grid-cols-[1fr_auto] gap-x-6 gap-y-1 text-sm"> {totals.map((total) => ( <div key={total.label} className="contents"> <dt className="text-muted-foreground">{total.label}</dt> <dd className="text-right tabular-nums"> {formatMoney(total.value, locale)} </dd> </div> ))} <dt className="font-semibold">{t("Total")}</dt> <dd className="text-right font-semibold tabular-nums"> {formatMoney(quote.total, locale)} </dd> </dl> </CardContent> </Card> } > <DocumentFlow label={t("Quote flow")} steps={[ { label: t("Draft"), state: "done" }, { label: t("Sent"), state: quote.status === "draft" ? "current" : "done", }, { label: t("Accepted"), state: quote.status === "accepted" ? "done" : quote.status === "sent" || quote.status === "viewed" ? "current" : "todo", }, { label: t("Order"), state: "todo", href: "/shop/orders" }, ]} /> <Card> <CardHeader> <CardTitle>{t("Line items")}</CardTitle> <CardDescription> {editable ? t("Edit the lines, then send the quote for acceptance.") : t("This quote is no longer editable.")} </CardDescription> </CardHeader> <CardContent>{lines}</CardContent> </Card> </RecordDetailFrame> </div> ); }