40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
/**
|
|
* @file quoteAutomat.js
|
|
* @description Manages cached sales quotes (Angebote) (`GET /api/quote`)
|
|
* 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 { quote as quoteApi } from '../api';
|
|
import { createListAutomat } from './createListAutomat';
|
|
|
|
/**
|
|
* @typedef {Object} QuoteSummary
|
|
* @property {string|number} id Quote id.
|
|
* @property {string} number Quote number.
|
|
* @property {string} type Always `'quote'`.
|
|
* @property {string|number|null} entityId Customer id.
|
|
* @property {string} date Expiry date (ISO).
|
|
*/
|
|
|
|
/**
|
|
* Company sales quotes (`GET /api/quote`).
|
|
*
|
|
* @type {import('react-automat').Automat<import('./createListAutomat').ListAutomatState>}
|
|
*/
|
|
export const quoteAutomat = createListAutomat({
|
|
name: 'quote',
|
|
fetch: async () => {
|
|
const data = await quoteApi.list();
|
|
return data.quotes ?? [];
|
|
},
|
|
sort: (items) =>
|
|
[...items].sort((a, b) => String(b.date).localeCompare(String(a.date))),
|
|
});
|
|
|
|
export default quoteAutomat;
|