u
This commit is contained in:
@@ -8,7 +8,7 @@ export const shipment = {
|
|||||||
// #region GET /api/shipment — list
|
// #region GET /api/shipment — list
|
||||||
list(params = {}) {
|
list(params = {}) {
|
||||||
const q = new URLSearchParams();
|
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.limit != null) q.set('limit', String(params.limit));
|
||||||
if (params.search) q.set('search', String(params.search));
|
if (params.search) q.set('search', String(params.search));
|
||||||
if (params.state) q.set('state', String(params.state));
|
if (params.state) q.set('state', String(params.state));
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import orderAutomat from './orderAutomat';
|
|||||||
* @property {string} filter
|
* @property {string} filter
|
||||||
* @property {string} stateFilter
|
* @property {string} stateFilter
|
||||||
* @property {number} seekMonths
|
* @property {number} seekMonths
|
||||||
|
* @property {number} seekYears
|
||||||
* @property {'idle'|'loading'|'ready'|'failed'} status
|
* @property {'idle'|'loading'|'ready'|'failed'} status
|
||||||
* @property {Error|string|null} error
|
* @property {Error|string|null} error
|
||||||
*/
|
*/
|
||||||
@@ -58,6 +59,7 @@ const initialState = {
|
|||||||
filter: '',
|
filter: '',
|
||||||
stateFilter: '',
|
stateFilter: '',
|
||||||
seekMonths: 0,
|
seekMonths: 0,
|
||||||
|
seekYears: 0,
|
||||||
status: 'idle',
|
status: 'idle',
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
@@ -69,7 +71,6 @@ let debounceTimer = null;
|
|||||||
// #region fetch helper
|
// #region fetch helper
|
||||||
async function fetchShipments(state) {
|
async function fetchShipments(state) {
|
||||||
const params = {
|
const params = {
|
||||||
offset: 0,
|
|
||||||
limit: 100,
|
limit: 100,
|
||||||
};
|
};
|
||||||
if (state.filter && state.filter.trim()) {
|
if (state.filter && state.filter.trim()) {
|
||||||
@@ -78,8 +79,9 @@ async function fetchShipments(state) {
|
|||||||
if (state.stateFilter) {
|
if (state.stateFilter) {
|
||||||
params.state = state.stateFilter;
|
params.state = state.stateFilter;
|
||||||
}
|
}
|
||||||
if (state.seekMonths) {
|
const totalMonths = (state.seekMonths || 0) + (state.seekYears || 0) * 12;
|
||||||
params.seekMonths = state.seekMonths;
|
if (totalMonths > 0) {
|
||||||
|
params.seekMonths = totalMonths;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await shipmentApi.list(params);
|
const res = await shipmentApi.list(params);
|
||||||
@@ -164,7 +166,22 @@ const actions = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setSeekMonths(months) {
|
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(() => {});
|
void automat.actions.load().catch(() => {});
|
||||||
},
|
},
|
||||||
// #endregion
|
// #endregion
|
||||||
@@ -205,16 +222,31 @@ const actions = {
|
|||||||
void orderAutomat.actions.reload().catch(() => {});
|
void orderAutomat.actions.reload().catch(() => {});
|
||||||
},
|
},
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
if (debounceTimer) clearTimeout(debounceTimer);
|
if (debounceTimer) clearTimeout(debounceTimer);
|
||||||
inflightLoad = null;
|
inflightLoad = null;
|
||||||
automat.setState({ ...initialState });
|
automat.setState({ ...initialState });
|
||||||
},
|
},
|
||||||
// #endregion
|
// #endregion
|
||||||
};
|
};
|
||||||
|
|
||||||
automat = new Automat(initialState, actions, { name: 'shipment' });
|
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
|
// #region authAutomat synchronization
|
||||||
let lastCompanyId = null;
|
let lastCompanyId = null;
|
||||||
authAutomat.subscribe((auth) => {
|
authAutomat.subscribe((auth) => {
|
||||||
|
|||||||
@@ -171,10 +171,12 @@ class AppSidebar extends PureComponent {
|
|||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={label}
|
primary={label}
|
||||||
primaryTypographyProps={{
|
slotProps={{
|
||||||
fontSize: { xs: '0.8rem', sm: '0.875rem' },
|
primary: {
|
||||||
fontWeight: active ? 600 : 500,
|
fontSize: { xs: '0.8rem', sm: '0.875rem' },
|
||||||
noWrap: true,
|
fontWeight: active ? 600 : 500,
|
||||||
|
noWrap: true,
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
m: { xs: 0, lg: 'initial' },
|
m: { xs: 0, lg: 'initial' },
|
||||||
|
|||||||
@@ -167,7 +167,9 @@ class UserMenu extends PureComponent {
|
|||||||
<ListItemText
|
<ListItemText
|
||||||
primary="Update verfügbar"
|
primary="Update verfügbar"
|
||||||
secondary="Jetzt aktualisieren"
|
secondary="Jetzt aktualisieren"
|
||||||
primaryTypographyProps={{ fontWeight: 600, color: 'primary.main' }}
|
slotProps={{
|
||||||
|
primary: { fontWeight: 600, color: 'primary.main' },
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user