feat: Dashboard - Vehicle Fleet Overview (#2) #3

Merged
egullickson merged 11 commits from issue-2-dashboard-fleet-overview into main 2026-01-03 04:47:29 +00:00
4 changed files with 24 additions and 5 deletions
Showing only changes of commit 98a4a62ea5 - Show all commits

View File

@@ -633,6 +633,7 @@ function App() {
<DashboardFeature
onNavigate={navigateToScreen}
onVehicleClick={handleVehicleSelect}
onAddVehicle={() => setShowAddVehicle(true)}
/>
</MobileErrorBoundary>
</motion.div>

View File

@@ -20,12 +20,14 @@ interface DashboardScreenProps {
onNavigate?: (screen: MobileScreen, metadata?: Record<string, any>) => void;
onVehicleClick?: (vehicle: Vehicle) => void;
onViewMaintenance?: () => void;
onAddVehicle?: () => void;
}
export const DashboardScreen: React.FC<DashboardScreenProps> = ({
onNavigate,
onVehicleClick,
onViewMaintenance
onViewMaintenance,
onAddVehicle
}) => {
const { data: summary, isLoading: summaryLoading, error: summaryError } = useDashboardSummary();
const { data: vehiclesNeedingAttention, isLoading: attentionLoading, error: attentionError } = useVehiclesNeedingAttention();
@@ -87,7 +89,7 @@ export const DashboardScreen: React.FC<DashboardScreenProps> = ({
<Button
variant="primary"
size="lg"
onClick={() => onNavigate?.('Vehicles')}
onClick={onAddVehicle ?? (() => onNavigate?.('Vehicles'))}
>
Add Your First Vehicle
</Button>
@@ -118,7 +120,7 @@ export const DashboardScreen: React.FC<DashboardScreenProps> = ({
{/* Quick Actions */}
<QuickActions
onAddVehicle={() => onNavigate?.('Vehicles')}
onAddVehicle={onAddVehicle ?? (() => onNavigate?.('Vehicles'))}
onLogFuel={() => onNavigate?.('Log Fuel')}
onViewMaintenance={onViewMaintenance ?? (() => onNavigate?.('Vehicles'))}
onViewVehicles={() => onNavigate?.('Vehicles')}

View File

@@ -43,6 +43,10 @@ export const DashboardPage: React.FC = () => {
navigate('/garage/maintenance');
};
const handleAddVehicle = () => {
navigate('/garage/vehicles', { state: { showAddForm: true } });
};
return (
<Box sx={{ py: 2 }}>
<Typography variant="h4" sx={{ fontWeight: 700, color: 'text.primary', mb: 4 }}>
@@ -52,6 +56,7 @@ export const DashboardPage: React.FC = () => {
onNavigate={handleNavigate}
onVehicleClick={handleVehicleClick}
onViewMaintenance={handleViewMaintenance}
onAddVehicle={handleAddVehicle}
/>
</Box>
);

View File

@@ -3,7 +3,7 @@
* @ai-context Enhanced with Suspense, useOptimistic, and useTransition
*/
import React, { useState, useTransition, useMemo } from 'react';
import React, { useState, useTransition, useMemo, useEffect } from 'react';
import { Box, Typography, Grid, Button as MuiButton, TextField, IconButton } from '@mui/material';
import AddIcon from '@mui/icons-material/Add';
import SearchIcon from '@mui/icons-material/Search';
@@ -16,12 +16,13 @@ import { VehicleForm } from '../components/VehicleForm';
import { Card } from '../../../shared-minimal/components/Card';
import { VehicleListSuspense, FormSuspense } from '../../../components/SuspenseWrappers';
import { useAppStore } from '../../../core/store';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useLocation } from 'react-router-dom';
import { useQueryClient } from '@tanstack/react-query';
import { vehiclesApi } from '../api/vehicles.api';
export const VehiclesPage: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();
const queryClient = useQueryClient();
const { data: vehicles, isLoading } = useVehicles();
const setSelectedVehicle = useAppStore(state => state.setSelectedVehicle);
@@ -52,6 +53,16 @@ export const VehiclesPage: React.FC = () => {
const [showForm, setShowForm] = useState(false);
const [stagedImageFile, setStagedImageFile] = useState<File | null>(null);
// Auto-show form if navigated with showAddForm state (from dashboard)
useEffect(() => {
const state = location.state as { showAddForm?: boolean } | null;
if (state?.showAddForm) {
setShowForm(true);
// Clear the state to prevent re-triggering on refresh
navigate(location.pathname, { replace: true, state: {} });
}
}, [location.state, location.pathname, navigate]);
const handleSelectVehicle = (id: string) => {
// Use transition for navigation to avoid blocking UI
startTransition(() => {