@@ -127,36 +90,90 @@ export default function VehicleStatusWidget(props: CommonWidgetProps) {
- {statusCounts.status === "pending" ? (
-
- ) : totalVehicles <= 0 ? (
-
- ) : (
-
-
- {sortedData.map((item, idx) => (
-
- ))}
-
-
- )}
+ }>
+
+
);
}
+function VehicleStatusChart(
+ props: CommonWidgetProps & { vehicleTypeId: string }
+) {
+ const statusCountQuery = useSuspenseQuery(
+ fetchDashboardVehicleStatusCountsOptions({
+ auth: props.auth,
+ filters: {
+ vehicleTypeId: props.vehicleTypeId,
+ locationIds: props.selectedLocationIds,
+ clientDate: new Date(),
+ },
+ })
+ );
+
+ const data = React.useMemo(
+ () =>
+ statusCountQuery.data.status === 200 ? statusCountQuery.data.body : [],
+ [statusCountQuery.data.body, statusCountQuery.data.status]
+ );
+
+ const vehicleStatusesQuery = useSuspenseQuery(
+ fetchVehiclesStatusesOptions({ auth: props.auth })
+ );
+
+ const vehicleStatuses = React.useMemo(
+ () => vehicleStatusesQuery.data ?? [],
+ [vehicleStatusesQuery.data]
+ );
+
+ const getStatusIdByName = React.useCallback(
+ (name: string) => {
+ const status = vehicleStatuses.find((s) => s.name === name);
+ return status?.id || 0;
+ },
+ [vehicleStatuses]
+ );
+
+ const sortedData = data.sort((a, b) => {
+ if (a.total < b.total) return 1;
+ if (a.total > b.total) return -1;
+ return 0;
+ });
+
+ const totalVehicles = sortedData.reduce((acc, item) => acc + item.total, 0);
+
+ const [rowCountStr] = useLocalStorage(
+ STORAGE_KEYS.tableRowCount,
+ STORAGE_DEFAULTS.tableRowCount
+ );
+ const defaultRowCount = parseInt(rowCountStr, 10);
+
+ return totalVehicles <= 0 ? (
+