Create product dialog
Add a product or service in a dialog, starting in the organisation's default currency (or a given one, optionally locked, e.g. an invoice's). Checks the fields before saving, shows the API's field errors beside their fields, and refreshes the catalogue and open product pickers afterwards.
Dialog: a modal you open from your own screen. You control when it opens with its props. Pages vs components
Ready to connect to Dolfin. Loads data through SDK hooks, with appearance and behaviour you can customise. Requires DolfinProvider.
Installation
Needs the Dolfin registry token. The CLI copies the source into your app.
bunx --bun shadcn@4.23.0 add @dolfin/ar-create-product-dialogAlso installs: button, dialog, base-theme, ar-product-form, ui-ar-create-product-dialog.
Usage
import { ArCreateProductDialog } from "@/components/dolfin/ar/create-product-dialog";
// Place it anywhere inside your <DolfinProvider>.
<ArCreateProductDialog open={open} onOpenChange={handleOpenChange} />Renders inside DolfinProvider (set it up once). By default it loads its own data through the SDK. Supplied-data examples show how to override that behavior.
API reference
| Prop | Type | Description |
|---|---|---|
open required | boolean | |
onOpenChange required | (open: boolean) => void | |
onCreated | (product: Product) => void | After the product was created; the dialog has closed. |
defaultCurrency | string | Pre-selected currency (e.g. the invoice's); takes priority over the organisation's default. |
lockCurrency | boolean | Keep the currency fixed at `defaultCurrency` (a product made for an invoice must match it). |
initialValues | Partial<ProductFormValue> | Prefill (e.g. a name typed into a picker). Applied each time the dialog opens. |
transformRequest | (body: CreateProductRequest) => CreateProductRequest | Adjust the request before it is sent, e.g. to add the values of your `fields`. |
onSubmit | (body: CreateProductRequest) => Promise<Product | void> | void | Saves it yourself instead of the SDK. The dialog closes once it resolves and shows the error in place if it rejects. |
submitting | boolean | Your own save is running. |
currencies | readonly { id?: string; code: string; name: string; symbol: string; decimalPlaces?: number | string; }[] | The currencies to offer, instead of loading them. |
fields | string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re… | Extra fields after the type (e.g. an income account); pair with `transformRequest`. |
title | string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re… | |
description | string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.Re… | |
className | string |
Customisation
Without editing the source, you can change:
- Class names
className- Messages
ar.products
Or edit the installed file directly: it is your code. See theming for colours and fonts.
Hooks
The SDK hooks this dialog uses. Use them directly from @dolfinai/react to build your own version.
useMessagesuseProductCurrenciesuseProductMutationsFiles
Written to your app by the install command:
components/dolfin/ar/create-product-dialog.tsx160 lines