Forms
Two rules hold for every form in the app: when Save can be pressed, and what the unsaved changes dialog offers when the user leaves a form with edits.
When Save can be pressed
Save (the submit button) is disabled while any of these is true:
| Case | Why |
|---|---|
| A field has an error | The error shows next to the field, so the user sees what to fix. Save waits until it is fixed. |
| Nothing changed (edit forms only) | There is nothing to save. A create form has no “unchanged” state. |
| A save is running | The button shows a spinner. A second press cannot send a second save. |
Show the field error as text under the field (the error prop of Input), not
as a toast. A toast is for a save that the server or the database refused.
<Button type="submit" disabled={!!nameError || !isDirty || isPending} isLoading={isPending}> {t('common.save')}</Button>The unsaved changes dialog
When the user leaves a form that has edits (a tab, Back, or another location’s page), the app asks first. The dialog has three buttons, in this order:
| Button | Variant | What it does |
|---|---|---|
| Cancel | neutral-outline | Closes the dialog. The user stays, and the edits stay. |
| Discard | destructive-outline | Leaves without saving. The edits are lost. |
| Save | primary | Saves, then goes where the user was going. |
- Save is the one solid button, on the right. Discard is outline, because it sits next to a solid button. It uses the destructive color, because it loses the edits and cannot be undone.
- Save follows the first rule. It is disabled while a field has an error or a save is running.
- Save runs the same save as the page’s own Save button. It goes where the user pressed, not to the place the page’s own Save goes after a save.
- While the save runs, Save shows a spinner, every button is disabled, and the dialog stays open.
- If the save fails, the usual error toast shows and the dialog stays open. The user can try again, Discard, or Cancel.
- If the save needs to ask something first (the item page’s converted amounts dialog), that dialog opens on top of this one. Confirm saves and then leaves. Cancel closes only the top dialog, and this one shows again.
In code, use the shared UnsavedChangesDialog
(apps/web/src/components/shared/UnsavedChangesDialog). Do not build a new copy.
Section headings
A heading that folds is a left-aligned accordion trigger. A heading that does not fold is centered, with a line on each side.
| Heading | Looks like | Example | In code |
|---|---|---|---|
| folds (opens and closes) | left-aligned, with a chevron | the quick edit dialog’s Stock settings | Accordion and AccordionTrigger |
| does not fold | centered, text-sm font-medium uppercase, a line on the left and the right | the item Info tab’s Stock Settings, the bulk edit dialog’s three sections, the Add Item dialog | SectionHeading |
- Never mix the two at one level of a form. A reader cannot tell which headings open.
SectionHeadingis anh3by default. Useas="h2"on a page whose title is theh1, and keeph3inside a dialog.- Pass the spacing with
className:pt-2in item forms,my-2in lists of choices.
import { SectionHeading } from '@/components/shared/SectionHeading'
<SectionHeading as="h2" className="pt-2"> {t('items.form.stockSettingsHeading')}</SectionHeading>