Files
dashfront/src/automats/deliveryAutomat.js
2026-10-04 22:47:26 +02:00

44 lines
1.4 KiB
JavaScript

/**
* @file deliveryAutomat.js
* @description Manages cached inbound goods receipts / deliveries (`GET /api/delivery`)
* for the active company. 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 { delivery as deliveryApi } from '../api';
import { createListAutomat } from './createListAutomat';
/**
* @typedef {Object} DeliverySummary
* @property {string|number} id Delivery id.
* @property {string} number Server-allocated manifest number.
* @property {string|null} externalNumber User-entered reference.
* @property {string} type Always `'delivery'`.
* @property {string|number|null} supplierId Supplier id.
* @property {string} date Delivery date (ISO).
*/
/**
* Company goods receipts (`GET /api/delivery`).
*
* Backs the delivery list page and the quote/order manifest lists share the
* same pattern through their own automats.
*
* @type {import('react-automat').Automat<import('./createListAutomat').ListAutomatState>}
*/
export const deliveryAutomat = createListAutomat({
name: 'delivery',
fetch: async () => {
const data = await deliveryApi.list();
return data.deliveries ?? [];
},
sort: (items) =>
[...items].sort((a, b) => String(b.date).localeCompare(String(a.date))),
});
export default deliveryAutomat;