Expense approval policy form dialog
Creates or edits an expense approval policy: the policy fields with Save, validated as the API validates, in a dialog titled with the version being edited (every save is a new version). Also ships ExpensePolicyForm for use on a page. Driven by useExpensePolicyMutations.
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/expenses-approval-policy-form-dialogAlso installs: button, dialog, expenses-approval-policy-fields, ui-expenses-approval-policy-form-dialog.
Usage
import { ExpensePolicyFormDialog } from "@/components/dolfin/expenses/expense-policy-form-dialog";
// Place it anywhere inside your <DolfinProvider>.
<ExpensePolicyFormDialog 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 | |
policy | { id: string; name: string; version: number | string; priorityOrder: number | string; active: boolean; amountGte?: null | number | string; a… | The policy to edit; without one the dialog creates a policy. |
defaultPriority | number | Priority for a new policy; defaults to after the last existing one. |
referenceData | ExpensePolicyReferenceData | |
onSaved | (policy: ExpensePolicy) => void | |
className | string | |
onSubmit | (request: ExpensePolicyRequest, draft: ExpensePolicyDraft) => void | Save it yourself: called with the request once the draft passes the API's checks. Nothing is sent then. |
submitting | boolean | |
currencies | readonly { id?: string; code: string; name: string; symbol: string; decimalPlaces?: number | string; }[] | Your currencies for the currency picker. Given, the list is not fetched. |
onChange | (draft: ExpensePolicyDraft) => void | |
values | ExpensePolicyDraft | Controlled draft; the form keeps its own when omitted. |
error | Error | Why the last save failed: shown in words under the form. |
members | readonly { id: string; label: string; }[] | Your members for the people and approver pickers. Given, they are not fetched. |
Customisation
Without editing the source, you can change:
- Class names
className- Messages
core.errorsexpenses.approvalPolicies
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.
useExpensePoliciesuseExpensePolicyFormatuseExpensePolicyMutationsuseExpensePolicyReferenceDatauseMessagesFiles
Written to your app by the install command:
components/dolfin/expenses/expense-policy-form-dialog.tsx276 lines