u
This commit is contained in:
28
src/automats/quoteAutomat.js
Normal file
28
src/automats/quoteAutomat.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user