Tally UI

OrderEditForm

The order detail Edit tab, one field per call with conflict, refusal and locked states

Import

import { OrderEditForm } from '@tallyui/components';

Usage

The form only calls back: it never writes to the store itself. The host builds one row per field its connector can write (ADR-100) and maps each store answer to an OrderEditSaveResult. In an app, useOrderEdit from @tallyui/pos builds these rows from the connector. By hand:

// Illustrative: `orderEdit` is the connector's ADR-100 surface (`Connector.orderEdit`).
const toResult = (result: OrderEditResult): OrderEditSaveResult<string> =>
  result.status === 'conflict' ? { kind: 'conflict', fresh: result.snapshot.customerNote ?? '' }
  : result.status === 'refused' ? { kind: 'refused', message: result.message }
  : { kind: result.status };

<OrderEditForm
  note={snapshot.customerNote !== undefined
    ? { value: snapshot.customerNote,
        onSave: async ({ from, to }) => toResult(await orderEdit.update(context, orderId, { field: 'customerNote', from, to })) }
    : { value: snapshot.readOnly?.customerNote?.value ?? '', reason: snapshot.readOnly?.customerNote?.reason }}
  status={snapshot.status
    ? { value: order.status, label: statusLabel, options: snapshot.status.options, unavailable: snapshot.status.unavailable, onSave: saveStatus }
    : { value: order.status, label: statusLabel, options: [], reason: snapshot.readOnly?.status?.reason }}
  locked={orderEditLock({ online, storageDegraded, heldHere, storeOrderId: orderId, rows }) ?? undefined}
/>

Put it in an Edit tab of RecordTabs, after View:

<RecordTabs
  json={order}
  tabs={[
    { value: 'view', label: 'View', content: <OrderDetail {...detailProps} /> },
    { value: 'edit', label: 'Edit', content: <OrderEditForm {...editRows} /> },
  ]}
/>

How it behaves

Only the rows you pass. A row is drawn only when its prop is passed, so a field the connector does not list never shows. With no row props, the form shows only "Nothing on this order can be edited here." A row passed without onSave is read-only and shows its reason, in the connector's words. Pass the connector's snapshot.readOnly.<field>.reason there, as the example does for the note and the status; without it a read-only row shows no reason.

An explicit verb on every row. Picking a status or a customer only stages it: Update status and Change customer send it, because those writes have effects in the store. The customer note and each address have their own Save. A verb stays disabled until its draft differs from the row's base.

One call at a time. While any row's call is pending, every verb in the form is disabled, and a double press sends once.

What from is. Each call is { from, to }, and from is the row's base. The base starts as the row's value, becomes the store's fresh value after a conflict, and becomes the sent to after saved or already. When the host passes a new value (it re-read the order), the base follows it; a draft the cashier has not touched follows too, and a changed draft is kept.

Conflict. The row shows the store's fresh value under "Changed in the store since you opened it; nothing was saved." The note and address rows keep the cashier's draft in the input; the status and customer rows reset their pick to the fresh value. Saving again sends the fresh value as from, so the next write is a deliberate one. A conflict is announced (role="alert") like a refusal.

Refused. The store's message, or "The store refused this change." when there is none, shows under the row as an alert. The draft and the base are kept.

Failed. When onSave throws or rejects, the row shows "Could not save. Check the connection and try again." The draft and the base are kept.

Locked. locked disables every verb, the note input and the status select, and passes disabled to the customer picker, and shows its reason above the rows: 'offline', 'storage' (local storage degraded), 'held' (a live or parked sale on this till holds the reopened order; the cashier finishes or discards it) or 'reopen' (a reopened sale's update is still unsent). The host decides when. The billing and shipping parts are read-only too: AddressFields gets disabled, so its inputs take no typing and its Country and State pickers do not open.

Props

PropTypeDefaultDescription
customerOrderEditRow<OrderEditCustomer> and renderPicker?—The customer row. Editable only with both onSave and renderPicker; renderPicker receives selected, onSelect and disabled
statusOrderEditRow<string> and label, options, unavailable—The status row. Editable only with onSave and at least one option. unavailable lists targets the order cannot take now, each shown under the select as a muted line with its reason; a value in both lists is unavailable
noteOrderEditRow<string>—The customer note. Save sends the trimmed text
billingAddressOrderEditRow<CustomerAddress> and showEmail?—The billing address, with an Email input when showEmail
shippingAddressOrderEditRow<CustomerAddress>—The shipping address
locked'offline' | 'storage' | 'held' | 'reopen'—Disables editing and shows why
testIDstring'order-edit-form'Prefix of every row's testID (-customer, -status, -note, -billing, -shipping)
classNamestring—Override container styles

Rows draw in this order: customer, status, customer note, billing, shipping. Addresses compare by value, with an empty part read as absent.

OrderEditRow

interface OrderEditRow<T> {
  value: T;
  onSave?: (change: OrderEditChange<T>) => Promise<OrderEditSaveResult<T>>;
  /** Shown on a read-only row. */
  reason?: string;
}

interface OrderEditChange<T> { from: T; to: T }

OrderEditSaveResult

type OrderEditSaveResult<T> =
  | { kind: 'saved' }
  | { kind: 'already' }
  | { kind: 'conflict'; fresh: T }
  | { kind: 'refused'; message?: string };

OrderEditCustomer

interface OrderEditCustomer {
  /** null is a guest. */
  id: string | null;
  label: string;
}