fix: add vehicle button opens add vehicle form (refs #2)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m35s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 36s
Deploy to Staging / Verify Staging (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 5s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m35s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 36s
Deploy to Staging / Verify Staging (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 5s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
- Add onAddVehicle prop to DashboardScreen - Mobile: triggers setShowAddVehicle(true) in App.tsx - Desktop: navigates to /garage/vehicles with showAddForm state - VehiclesPage auto-opens form when receiving showAddForm state 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -633,6 +633,7 @@ function App() {
|
||||
<DashboardFeature
|
||||
onNavigate={navigateToScreen}
|
||||
onVehicleClick={handleVehicleSelect}
|
||||
onAddVehicle={() => setShowAddVehicle(true)}
|
||||
/>
|
||||
</MobileErrorBoundary>
|
||||
</motion.div>
|
||||
|
||||
@@ -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')}
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user