u
This commit is contained in:
21
src/automats/accountAutomat.js
Normal file
21
src/automats/accountAutomat.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @file accountAutomat.js
|
||||
* @description Manages cached payment accounts (`GET /api/account`) for the selected company.
|
||||
*/
|
||||
|
||||
import { createListAutomat } from './createListAutomat';
|
||||
import { account as accountApi } from '../api';
|
||||
|
||||
export const accountAutomat = createListAutomat({
|
||||
name: 'account',
|
||||
fetch: async () => {
|
||||
const res = await accountApi.list();
|
||||
return Array.isArray(res?.accounts) ? res.accounts : [];
|
||||
},
|
||||
sort: (items) =>
|
||||
[...items].sort((a, b) =>
|
||||
String(a.name ?? '').localeCompare(String(b.name ?? ''), 'de')
|
||||
),
|
||||
});
|
||||
|
||||
export default accountAutomat;
|
||||
@@ -81,8 +81,10 @@ export {
|
||||
export { default as entityAutomat } from './entityAutomat';
|
||||
export { default as customergroupAutomat } from './customergroupAutomat';
|
||||
export { default as numberAutomat } from './numberAutomat';
|
||||
export { default as accountAutomat } from './accountAutomat';
|
||||
export { createListAutomat, selectListItems, selectListStatus } from './createListAutomat';
|
||||
|
||||
|
||||
/** Per-SKU article detail views keyed by SKU. */
|
||||
export { articleHistoryAutomat, articleSupplierAutomat } from './articleDetailAutomat';
|
||||
|
||||
|
||||
@@ -74,9 +74,10 @@ export function isOrderPaid(order) {
|
||||
}
|
||||
|
||||
export function isOrderDelivered(order) {
|
||||
return Boolean(order.delivered ?? order.isDelivered ?? order.is_delivered ?? order.deliveredAt);
|
||||
return Boolean(order.shipped ?? order.delivered ?? order.isDelivered ?? order.is_delivered ?? order.deliveredAt);
|
||||
}
|
||||
|
||||
|
||||
export function getOrderDate(order) {
|
||||
const raw = order.date || order.createdAt;
|
||||
if (!raw) return null;
|
||||
|
||||
@@ -32,6 +32,8 @@ import warehouseAutomat from './warehouseAutomat';
|
||||
import attributeAutomat from './attributeAutomat';
|
||||
import propertyAutomat from './propertyAutomat';
|
||||
import supplierAutomat from './supplierAutomat';
|
||||
import orderAutomat from './orderAutomat';
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} SseState
|
||||
@@ -236,6 +238,18 @@ function connect() {
|
||||
});
|
||||
});
|
||||
|
||||
addTrackedListener(es, 'order', () => {
|
||||
void orderAutomat.actions.reload().catch((err) => {
|
||||
console.error('[sse] order refresh failed', err);
|
||||
});
|
||||
});
|
||||
|
||||
addTrackedListener(es, 'shipment', () => {
|
||||
void orderAutomat.actions.reload().catch((err) => {
|
||||
console.error('[sse] shipment refresh failed', err);
|
||||
});
|
||||
});
|
||||
|
||||
addTrackedListener(es, 'open', () => {
|
||||
sseAutomat.setState({ status: 'connected' });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user