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
|
<DashboardFeature
|
||||||
onNavigate={navigateToScreen}
|
onNavigate={navigateToScreen}
|
||||||
onVehicleClick={handleVehicleSelect}
|
onVehicleClick={handleVehicleSelect}
|
||||||
|
onAddVehicle={() => setShowAddVehicle(true)}
|
||||||
/>
|
/>
|
||||||
</MobileErrorBoundary>
|
</MobileErrorBoundary>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
@@ -20,12 +20,14 @@ interface DashboardScreenProps {
|
|||||||
onNavigate?: (screen: MobileScreen, metadata?: Record<string, any>) => void;
|
onNavigate?: (screen: MobileScreen, metadata?: Record<string, any>) => void;
|
||||||
onVehicleClick?: (vehicle: Vehicle) => void;
|
onVehicleClick?: (vehicle: Vehicle) => void;
|
||||||
onViewMaintenance?: () => void;
|
onViewMaintenance?: () => void;
|
||||||
|
onAddVehicle?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DashboardScreen: React.FC<DashboardScreenProps> = ({
|
export const DashboardScreen: React.FC<DashboardScreenProps> = ({
|
||||||
onNavigate,
|
onNavigate,
|
||||||
onVehicleClick,
|
onVehicleClick,
|
||||||
onViewMaintenance
|
onViewMaintenance,
|
||||||
|
onAddVehicle
|
||||||
}) => {
|
}) => {
|
||||||
const { data: summary, isLoading: summaryLoading, error: summaryError } = useDashboardSummary();
|
const { data: summary, isLoading: summaryLoading, error: summaryError } = useDashboardSummary();
|
||||||
const { data: vehiclesNeedingAttention, isLoading: attentionLoading, error: attentionError } = useVehiclesNeedingAttention();
|
const { data: vehiclesNeedingAttention, isLoading: attentionLoading, error: attentionError } = useVehiclesNeedingAttention();
|
||||||
@@ -87,7 +89,7 @@ export const DashboardScreen: React.FC<DashboardScreenProps> = ({
|
|||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
size="lg"
|
size="lg"
|
||||||
onClick={() => onNavigate?.('Vehicles')}
|
onClick={onAddVehicle ?? (() => onNavigate?.('Vehicles'))}
|
||||||
>
|
>
|
||||||
Add Your First Vehicle
|
Add Your First Vehicle
|
||||||
</Button>
|
</Button>
|
||||||
@@ -118,7 +120,7 @@ export const DashboardScreen: React.FC<DashboardScreenProps> = ({
|
|||||||
|
|
||||||
{/* Quick Actions */}
|
{/* Quick Actions */}
|
||||||
<QuickActions
|
<QuickActions
|
||||||
onAddVehicle={() => onNavigate?.('Vehicles')}
|
onAddVehicle={onAddVehicle ?? (() => onNavigate?.('Vehicles'))}
|
||||||
onLogFuel={() => onNavigate?.('Log Fuel')}
|
onLogFuel={() => onNavigate?.('Log Fuel')}
|
||||||
onViewMaintenance={onViewMaintenance ?? (() => onNavigate?.('Vehicles'))}
|
onViewMaintenance={onViewMaintenance ?? (() => onNavigate?.('Vehicles'))}
|
||||||
onViewVehicles={() => onNavigate?.('Vehicles')}
|
onViewVehicles={() => onNavigate?.('Vehicles')}
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ export const DashboardPage: React.FC = () => {
|
|||||||
navigate('/garage/maintenance');
|
navigate('/garage/maintenance');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAddVehicle = () => {
|
||||||
|
navigate('/garage/vehicles', { state: { showAddForm: true } });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ py: 2 }}>
|
<Box sx={{ py: 2 }}>
|
||||||
<Typography variant="h4" sx={{ fontWeight: 700, color: 'text.primary', mb: 4 }}>
|
<Typography variant="h4" sx={{ fontWeight: 700, color: 'text.primary', mb: 4 }}>
|
||||||
@@ -52,6 +56,7 @@ export const DashboardPage: React.FC = () => {
|
|||||||
onNavigate={handleNavigate}
|
onNavigate={handleNavigate}
|
||||||
onVehicleClick={handleVehicleClick}
|
onVehicleClick={handleVehicleClick}
|
||||||
onViewMaintenance={handleViewMaintenance}
|
onViewMaintenance={handleViewMaintenance}
|
||||||
|
onAddVehicle={handleAddVehicle}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @ai-context Enhanced with Suspense, useOptimistic, and useTransition
|
* @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 { Box, Typography, Grid, Button as MuiButton, TextField, IconButton } from '@mui/material';
|
||||||
import AddIcon from '@mui/icons-material/Add';
|
import AddIcon from '@mui/icons-material/Add';
|
||||||
import SearchIcon from '@mui/icons-material/Search';
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
@@ -16,12 +16,13 @@ import { VehicleForm } from '../components/VehicleForm';
|
|||||||
import { Card } from '../../../shared-minimal/components/Card';
|
import { Card } from '../../../shared-minimal/components/Card';
|
||||||
import { VehicleListSuspense, FormSuspense } from '../../../components/SuspenseWrappers';
|
import { VehicleListSuspense, FormSuspense } from '../../../components/SuspenseWrappers';
|
||||||
import { useAppStore } from '../../../core/store';
|
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 { useQueryClient } from '@tanstack/react-query';
|
||||||
import { vehiclesApi } from '../api/vehicles.api';
|
import { vehiclesApi } from '../api/vehicles.api';
|
||||||
|
|
||||||
export const VehiclesPage: React.FC = () => {
|
export const VehiclesPage: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { data: vehicles, isLoading } = useVehicles();
|
const { data: vehicles, isLoading } = useVehicles();
|
||||||
const setSelectedVehicle = useAppStore(state => state.setSelectedVehicle);
|
const setSelectedVehicle = useAppStore(state => state.setSelectedVehicle);
|
||||||
@@ -52,6 +53,16 @@ export const VehiclesPage: React.FC = () => {
|
|||||||
const [showForm, setShowForm] = useState(false);
|
const [showForm, setShowForm] = useState(false);
|
||||||
const [stagedImageFile, setStagedImageFile] = useState<File | null>(null);
|
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) => {
|
const handleSelectVehicle = (id: string) => {
|
||||||
// Use transition for navigation to avoid blocking UI
|
// Use transition for navigation to avoid blocking UI
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user