feat: support custom maintenance mode duration

This commit was merged in pull request #22.
This commit is contained in:
2026-10-18 15:07:34 +03:00
parent 71834904a1
commit fd582cbab8
4 changed files with 206 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
import { authInstance, languageInstance, mobxFetch } from "@shared";
import { makeAutoObservable, runInAction } from "mobx";
import { getVehicleSessionsApi } from "./api";
import { Vehicle, VehicleMaintenanceSession } from "./types";
import { Vehicle, VehicleMaintenanceSession, SetMaintenanceModeResponse } from "./types";
export type { Vehicle, VehicleMaintenanceSession } from "./types";
@@ -218,23 +218,32 @@ class VehicleStore {
});
};
setMaintenanceMode = async (uuid: string, enabled: boolean) => {
const response = await authInstance.post(
setMaintenanceMode = async (
uuid: string,
enabled: boolean,
durationSeconds?: number,
): Promise<SetMaintenanceModeResponse> => {
const response = await authInstance.post<SetMaintenanceModeResponse>(
`/devices/${uuid}/maintenance-mode`,
{
enabled,
...(enabled && durationSeconds !== undefined
? { duration_seconds: durationSeconds }
: {}),
},
);
const normalizedVehicle = this.normalizeVehicleItem(response.data);
if (!response.data.saved) {
throw new Error("Maintenance mode was not saved");
}
runInAction(() => {
this.mergeVehicleInCaches({
...normalizedVehicle.vehicle,
uuid,
maintenance_mode_on:
normalizedVehicle.vehicle.maintenance_mode_on ?? enabled,
maintenance_mode_on: response.data.enabled,
maintenance_mode_duration_seconds: response.data.duration_seconds,
});
});
return response.data;
};
setDemoMode = async (uuid: string, enabled: boolean) => {

View File

@@ -11,6 +11,7 @@ export type Vehicle = {
snapshot_update_blocked?: boolean;
demo_mode_enabled?: boolean;
maintenance_mode_on?: boolean;
maintenance_mode_duration_seconds?: number;
city_id?: number;
};
device_status?: {
@@ -21,13 +22,24 @@ export type Vehicle = {
last_update: string;
is_connected: boolean;
current_route_id?: number;
maintenance_mode_on?: boolean;
maintenance_mode_duration_seconds?: number;
};
};
export type VehicleMaintenanceSession = {
duration_seconds: number;
ended_at: string;
duration_seconds?: number | null;
ended_at?: string | null;
id: number;
started_at: string;
vehicle_id: number;
};
export type SetMaintenanceModeResponse = {
message: string;
enabled: boolean;
duration_seconds: number;
saved: boolean;
sent: boolean;
warning?: string;
};