u
This commit is contained in:
31
src/automats/entityAutomat.js
Normal file
31
src/automats/entityAutomat.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { entity as entityApi } from '../api';
|
||||
import { createListAutomat } from './createListAutomat';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Entity
|
||||
* @property {string|number} id Entity id.
|
||||
* @property {string|number} customergroupId Owning customer group id.
|
||||
* @property {string|null} firstName First name.
|
||||
* @property {string} name Last / company name.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Company customers and contacts (`GET /api/entity`).
|
||||
*
|
||||
* @type {import('react-automat').Automat<import('./createListAutomat').ListAutomatState>}
|
||||
*/
|
||||
export const entityAutomat = createListAutomat({
|
||||
name: 'entity',
|
||||
fetch: async () => {
|
||||
const data = await entityApi.list();
|
||||
return data.entities ?? [];
|
||||
},
|
||||
sort: (items) =>
|
||||
[...items].sort((a, b) => {
|
||||
const byName = String(a.name).localeCompare(String(b.name), 'de');
|
||||
if (byName !== 0) return byName;
|
||||
return String(a.firstName ?? '').localeCompare(String(b.firstName ?? ''), 'de');
|
||||
}),
|
||||
});
|
||||
|
||||
export default entityAutomat;
|
||||
Reference in New Issue
Block a user