diff --git a/src/components/ProjectDetail.tsx b/src/components/ProjectDetail.tsx index e25b4c9..68d8680 100644 --- a/src/components/ProjectDetail.tsx +++ b/src/components/ProjectDetail.tsx @@ -19,23 +19,20 @@ const ProjectDetail: React.FC = ({ const navigate = useNavigate(); const { isVendor } = useAuth(); - // Calculate overall risk level based on issues - const calculateRiskLevel = () => { - if (!report.issues || report.issues.length === 0) return "Low"; - - const highRiskCount = report.issues.filter( - (issue) => issue.riskRating >= 5 - ).length; - if (highRiskCount > 0) return "High"; - - const mediumRiskCount = report.issues.filter( - (issue) => issue.riskRating >= 3 && issue.riskRating < 5 - ).length; - if (mediumRiskCount > 0) return "Medium"; - - return "Low"; + // Get criticality rating from assessment + const getCriticalityRating = () => { + return report.assessment?.sprintPlanning?.rating || "N/A"; }; + // Get schedule status based on variance days + const getScheduleStatus = () => { + if (report.varianceDays === undefined || report.varianceDays === null) { + return "N/A"; + } + if (report.varianceDays === 0) return "On Time"; + if (report.varianceDays > 0) return "Behind Schedule"; + return "Ahead of Schedule"; + }; // Handle delete report const handleDeleteReport = async () => { if ( @@ -56,7 +53,8 @@ const ProjectDetail: React.FC = ({ } }; - const riskLevel = calculateRiskLevel(); + const criticalityRating = getCriticalityRating(); + const scheduleStatus = getScheduleStatus(); return (
@@ -64,7 +62,8 @@ const ProjectDetail: React.FC = ({
-

MONTHLY REPORT {index}

+

REPORT: {report.month || "N/A"}

+
@@ -131,50 +130,42 @@ const ProjectDetail: React.FC = ({
-
- Month: {report.month || "N/A"} -
-
+
Report Date:{" "} {report.date ? new Date(report.date).toLocaleDateString() : "N/A"}
-
+
Criticality Rating:{" "} - {riskLevel} + {criticalityRating} + +
+
+ Schedule Status:{" "} + + {scheduleStatus}
-
- -
- {report.scheduleStatus && ( -
-
- Schedule Status:{" "} - - {riskLevel} - -
-
- )}
diff --git a/src/pages/ProjectDetailPage.tsx b/src/pages/ProjectDetailPage.tsx index f415f63..e8e64b1 100644 --- a/src/pages/ProjectDetailPage.tsx +++ b/src/pages/ProjectDetailPage.tsx @@ -16,6 +16,9 @@ const ProjectDetailPage: React.FC = () => { const { projectId } = useParams<{ projectId: string }>(); const [project, setProject] = useState(null); const [reports, setReports] = useState([]); + const [mostRecentReport, setMostRecentReport] = useState( + null + ); const [isLoading, setIsLoading] = useState(true); const [isFirestoreProject, setIsFirestoreProject] = useState(false); const { isETSEmployee, isVendor, currentUser } = useAuth(); @@ -64,7 +67,18 @@ const ProjectDetailPage: React.FC = () => { } as ReportData) ); console.log("Loaded reports from Firestore:", reportsList.length); + + const sortedReports = [...reportsList].sort((a, b) => { + const dateA = a.date || a.createdAt?.toDate?.() || new Date(0); + const dateB = b.date || b.createdAt?.toDate?.() || new Date(0); + return new Date(dateB).getTime() - new Date(dateA).getTime(); + }); + setReports(reportsList); + + if (sortedReports.length > 0) { + setMostRecentReport(sortedReports[0]); + } }); setIsLoading(false); @@ -108,7 +122,6 @@ const ProjectDetailPage: React.FC = () => { ); } - // Check if the current vendor is assigned to this project after project is loaded const isVendorAssignedToProject = isVendor && project.vendorId === currentUser?.uid; @@ -167,8 +180,17 @@ const ProjectDetailPage: React.FC = () => {
- {/* Project info card */} -
{/* Project details */}
+ {mostRecentReport && mostRecentReport.background && ( +
+
+

Project Overview:

+ +

{mostRecentReport.background}

+
+
+ )} + +

IV&V Monthly Reports