u
This commit is contained in:
30
src/automats/customergroupAutomat.js
Normal file
30
src/automats/customergroupAutomat.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { customergroup as customergroupApi } from '../api';
|
||||
import { createListAutomat } from './createListAutomat';
|
||||
|
||||
/**
|
||||
* @typedef {Object} CustomerGroup
|
||||
* @property {string|number} id Customer group id.
|
||||
* @property {string} name Group name.
|
||||
* @property {number} sort Sort index.
|
||||
* @property {boolean} editable False for reserved POS / Lieferanten groups.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Company customer groups (`GET /api/customergroup`).
|
||||
*
|
||||
* Reserved groups (`POS`, `Lieferanten`) are flagged `editable: false` and must
|
||||
* not be renamed or deleted by the UI.
|
||||
*
|
||||
* @type {import('react-automat').Automat<import('./createListAutomat').ListAutomatState>}
|
||||
*/
|
||||
export const customergroupAutomat = createListAutomat({
|
||||
name: 'customergroup',
|
||||
fetch: async () => {
|
||||
const data = await customergroupApi.list();
|
||||
return data.customergroups ?? [];
|
||||
},
|
||||
sort: (items) =>
|
||||
[...items].sort((a, b) => (Number(a.sort) || 0) - (Number(b.sort) || 0)),
|
||||
});
|
||||
|
||||
export default customergroupAutomat;
|
||||
Reference in New Issue
Block a user