Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/pages/ReportList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useMemo } from 'react';
import { useState, useMemo, useEffect } from 'react';
import { useRoadReports } from '@/hooks/useRoadReports';
import { useDeleteReport, useEditReport } from '@/hooks/useReportMutations';
import { ReportCard } from '@/components/ReportCard';
Expand Down Expand Up @@ -39,10 +39,20 @@ export function ReportListPage() {

const [editingReport, setEditingReport] = useState<RoadReport | null>(null);
const [deletingReport, setDeletingReport] = useState<RoadReport | null>(null);
const [pendingDelete, setPendingDelete] = useState<RoadReport | null>(null);

const deleteReport = useDeleteReport();
const editReport = useEditReport();

// Fire-and-forget delete after dialog closes
useEffect(() => {
if (pendingDelete) {
const report = pendingDelete;
setPendingDelete(null);
deleteReport(report).catch(console.error);
}
}, [pendingDelete, deleteReport]);

const filteredReports = useMemo(() => {
if (!reports) return [];

Expand Down Expand Up @@ -221,7 +231,14 @@ export function ReportListPage() {
/>

{/* Delete Confirmation */}
<AlertDialog open={!!deletingReport} onOpenChange={(open) => { if (!open) setDeletingReport(null); }}>
<AlertDialog
open={!!deletingReport}
onOpenChange={(open) => {
if (!open) {
setDeletingReport(null);
}
}}
>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete Report</AlertDialogTitle>
Expand All @@ -234,9 +251,8 @@ export function ReportListPage() {
<AlertDialogAction
onClick={() => {
if (deletingReport) {
const report = deletingReport;
setPendingDelete(deletingReport);
setDeletingReport(null);
deleteReport(report).catch(console.error);
}
}}
className="bg-red-500 hover:bg-red-600 text-white"
Expand Down
Loading