Refactor: Extract common logic and reduce file size

Refactors `Index.tsx` and `JobCardHeader.tsx` to reduce bloat and extract common logic, such as job status coloring, into reusable components or utility functions. This improves code maintainability and readability.
This commit is contained in:
gpt-engineer-app[bot]
2025-07-07 17:49:07 +00:00
committed by PhatPhuckDave
parent cb32ccaba9
commit ec8430189a
12 changed files with 480 additions and 532 deletions

View File

@@ -1,6 +1,8 @@
import { useNavigate } from 'react-router-dom';
import { Card, CardContent, CardHeader } from '@/components/ui/card';
import { IndJob } from '@/lib/types';
import { getStatusBackgroundColor } from '@/utils/jobStatusUtils';
import JobCardHeader from './JobCardHeader';
import JobCardDetails from './JobCardDetails';
import JobCardMetrics from './JobCardMetrics';
@@ -24,30 +26,14 @@ const JobCard: React.FC<JobCardProps> = ({
}) => {
const navigate = useNavigate();
const getStatusBackgroundColor = (status: string) => {
switch (status) {
case 'Planned': return 'bg-gray-600/20';
case 'Acquisition': return 'bg-yellow-600/20';
case 'Running': return 'bg-blue-600/20';
case 'Done': return 'bg-purple-600/20';
case 'Selling': return 'bg-orange-600/20';
case 'Closed': return 'bg-green-600/20';
case 'Tracked': return 'bg-cyan-600/20';
default: return 'bg-gray-600/20';
}
};
const handleCardClick = (e: React.MouseEvent) => {
// Check if the click target or any of its parents has the data-no-navigate attribute
const target = e.target as HTMLElement;
const hasNoNavigate = target.closest('[data-no-navigate]');
if (hasNoNavigate) {
// Don't navigate if clicking on elements marked as non-navigating
return;
}
// Only navigate if clicking on areas that aren't marked as non-navigating
navigate(`/${job.id}`);
};