This commit is contained in:
seb
2026-10-15 21:04:37 +02:00
parent beed294cb0
commit fafeec93b6
5 changed files with 538 additions and 348 deletions

View File

@@ -8,7 +8,7 @@ export const shipment = {
// #region GET /api/shipment — list
list(params = {}) {
const q = new URLSearchParams();
if (params.offset != null) q.set('offset', String(params.offset));
if (params.offset) q.set('offset', String(params.offset));
if (params.limit != null) q.set('limit', String(params.limit));
if (params.search) q.set('search', String(params.search));
if (params.state) q.set('state', String(params.state));

View File

@@ -47,6 +47,7 @@ import orderAutomat from './orderAutomat';
* @property {string} filter
* @property {string} stateFilter
* @property {number} seekMonths
* @property {number} seekYears
* @property {'idle'|'loading'|'ready'|'failed'} status
* @property {Error|string|null} error
*/
@@ -58,6 +59,7 @@ const initialState = {
filter: '',
stateFilter: '',
seekMonths: 0,
seekYears: 0,
status: 'idle',
error: null,
};
@@ -69,7 +71,6 @@ let debounceTimer = null;
// #region fetch helper
async function fetchShipments(state) {
const params = {
offset: 0,
limit: 100,
};
if (state.filter && state.filter.trim()) {
@@ -78,8 +79,9 @@ async function fetchShipments(state) {
if (state.stateFilter) {
params.state = state.stateFilter;
}
if (state.seekMonths) {
params.seekMonths = state.seekMonths;
const totalMonths = (state.seekMonths || 0) + (state.seekYears || 0) * 12;
if (totalMonths > 0) {
params.seekMonths = totalMonths;
}
const res = await shipmentApi.list(params);
@@ -164,7 +166,22 @@ const actions = {
},
setSeekMonths(months) {
automat.setState({ seekMonths: months });
automat.setState({ seekMonths: months, seekYears: 0 });
void automat.actions.load().catch(() => {});
},
addSeekMonth() {
automat.setState((s) => ({ seekMonths: (s.seekMonths ?? 0) + 1 }));
void automat.actions.load().catch(() => {});
},
addSeekYear() {
automat.setState((s) => ({ seekYears: (s.seekYears ?? 0) + 1 }));
void automat.actions.load().catch(() => {});
},
resetNegativeSeek() {
automat.setState({ seekMonths: 0, seekYears: 0 });
void automat.actions.load().catch(() => {});
},
// #endregion
@@ -205,16 +222,31 @@ const actions = {
void orderAutomat.actions.reload().catch(() => {});
},
reset() {
if (debounceTimer) clearTimeout(debounceTimer);
inflightLoad = null;
automat.setState({ ...initialState });
},
// #endregion
};
reset() {
if (debounceTimer) clearTimeout(debounceTimer);
inflightLoad = null;
automat.setState({ ...initialState });
},
// #endregion
};
automat = new Automat(initialState, actions, { name: 'shipment' });
// MARK: filter key & items helpers
export function getFilterKey(state = automat?.state || initialState) {
return `${state.filter || ''}|${state.stateFilter || ''}|${state.seekMonths || 0}|${state.seekYears || 0}`;
}
export function getItems() {
if (automat.state.status === 'idle') {
void automat.actions.load().catch(() => {});
}
return automat.state.items;
}
automat.getFilterKey = getFilterKey;
automat.getItems = getItems;
// #region authAutomat synchronization
let lastCompanyId = null;
authAutomat.subscribe((auth) => {

View File

@@ -171,10 +171,12 @@ class AppSidebar extends PureComponent {
</ListItemIcon>
<ListItemText
primary={label}
primaryTypographyProps={{
fontSize: { xs: '0.8rem', sm: '0.875rem' },
fontWeight: active ? 600 : 500,
noWrap: true,
slotProps={{
primary: {
fontSize: { xs: '0.8rem', sm: '0.875rem' },
fontWeight: active ? 600 : 500,
noWrap: true,
},
}}
sx={{
m: { xs: 0, lg: 'initial' },

View File

@@ -167,7 +167,9 @@ class UserMenu extends PureComponent {
<ListItemText
primary="Update verfügbar"
secondary="Jetzt aktualisieren"
primaryTypographyProps={{ fontWeight: 600, color: 'primary.main' }}
slotProps={{
primary: { fontWeight: 600, color: 'primary.main' },
}}
/>
</MenuItem>
)}

File diff suppressed because it is too large Load Diff