/** * @file orderAutomat.js * @description Manages cached company sales orders (`GET /api/order`). * Built via `createListAutomat`. * * Upstream Triggers: * - `authAutomat`: Via `createListAutomat` — triggers `load()` on `'authed'` with * a `selectedCompanyId`, and `reset()` on `'anon'`. * - UI / Routes: Manual calls to `load()` or `reload()`. */ import { order as orderApi } from '../api'; import { createListAutomat } from './createListAutomat'; /** * @typedef {Object} OrderSummary * @property {string|number} id Order id. * @property {string} number Order number. * @property {string} type Always `'order'`. * @property {string|number|null} entityId Customer id. * @property {string} date Delivery date (ISO). */ /** * Company sales orders (`GET /api/order`). * * @type {import('react-automat').Automat} */ export const orderAutomat = createListAutomat({ name: 'order', fetch: async () => { const data = await orderApi.list(); return data.orders ?? []; }, sort: (items) => [...items].sort((a, b) => String(b.date).localeCompare(String(a.date))), }); export default orderAutomat;