feat(platform): preserve customer time window in tasks
This commit is contained in:
@@ -14,6 +14,23 @@ const emptySummary: MileageSummary = {
|
||||
averageMileagePerVin: 0
|
||||
};
|
||||
|
||||
function numberOrZero(value: unknown) {
|
||||
const numeric = Number(value);
|
||||
return Number.isFinite(numeric) ? numeric : 0;
|
||||
}
|
||||
|
||||
function normalizeMileageSummary(summary?: Partial<MileageSummary> | null): MileageSummary {
|
||||
return {
|
||||
...emptySummary,
|
||||
...(summary ?? {}),
|
||||
vehicleCount: numberOrZero(summary?.vehicleCount),
|
||||
recordCount: numberOrZero(summary?.recordCount),
|
||||
sourceCount: numberOrZero(summary?.sourceCount),
|
||||
totalMileageKm: numberOrZero(summary?.totalMileageKm),
|
||||
averageMileagePerVin: numberOrZero(summary?.averageMileagePerVin)
|
||||
};
|
||||
}
|
||||
|
||||
const emptyOnlineSummary: OnlineStatisticsSummary = {
|
||||
vehicleCount: 0,
|
||||
onlineVehicleCount: 0,
|
||||
@@ -940,7 +957,7 @@ export function Mileage({
|
||||
const loadSummary = (values: Record<string, string> = filters) => {
|
||||
setSummaryLoading(true);
|
||||
api.mileageSummary(mileageParams(values))
|
||||
.then((nextSummary) => setSummary(nextSummary ?? emptySummary))
|
||||
.then((nextSummary) => setSummary(normalizeMileageSummary(nextSummary)))
|
||||
.catch((error: Error) => Toast.error(error.message))
|
||||
.finally(() => setSummaryLoading(false));
|
||||
api.onlineStatisticsSummary(mileageParams(values))
|
||||
|
||||
Reference in New Issue
Block a user