diff --git a/src/app/api/properties/[id]/delete/confirm/route.ts b/src/app/api/plan/[id]/delete/confirm/route.ts similarity index 100% rename from src/app/api/properties/[id]/delete/confirm/route.ts rename to src/app/api/plan/[id]/delete/confirm/route.ts diff --git a/src/app/api/properties/[id]/delete/preview/route.ts b/src/app/api/plan/[id]/delete/preview/route.ts similarity index 100% rename from src/app/api/properties/[id]/delete/preview/route.ts rename to src/app/api/plan/[id]/delete/preview/route.ts diff --git a/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/PlanCard.tsx b/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/PlanCard.tsx new file mode 100644 index 00000000..3ed8da6a --- /dev/null +++ b/src/app/portfolio/[slug]/building-passport/[propertyId]/plans/PlanCard.tsx @@ -0,0 +1,98 @@ +"use client"; + +import { TrashIcon } from "@heroicons/react/24/outline"; +import EpcCard from "@/app/components/building-passport/EpcCard"; +import { + Card, + CardContent, + CardHeader, +} from "@/app/shadcn_components/ui/card"; +import GoToPlanButton from "@/app/components/building-passport/GoToPlanButton"; +import { formatDateTime, formatNumber } from "@/app/utils"; + +export default function PlanCard({ + expectedEpcRating, + createdAt, + totalEstimatedCost, + totalSapPoints, + planName, + planId, + isDefault, +}: { + expectedEpcRating: string; + createdAt: Date; + totalEstimatedCost: number; + totalSapPoints: number; + planName: string | null; + planId: string; + isDefault: boolean; +}) { + return ( + + {/* Delete button (top-right, subtle) */} + + + {/* EPC card — unchanged */} +
+ +
+ + {/* Main content */} +
+ + {planName && ( +
+ {planName} +
+ )} +
+ + +
+ Total cost: + £{formatNumber(totalEstimatedCost)} +
+
+ Total SAP points: + + {Math.round((totalSapPoints + Number.EPSILON) * 100) / 100} + +
+
+
+ + {/* Right column */} +
+
+ {/*
+ Created {formatDateTime(createdAt)} +
*/} + + +
+
+ +
+ ); +} diff --git a/src/app/portfolio/[slug]/components/PropertyTable.tsx b/src/app/portfolio/[slug]/components/PropertyTable.tsx index d8ee22e1..455096e3 100644 --- a/src/app/portfolio/[slug]/components/PropertyTable.tsx +++ b/src/app/portfolio/[slug]/components/PropertyTable.tsx @@ -121,55 +121,6 @@ export default function PropertyTable({ const [previewError, setPreviewError] = useState(null); const [deleteLoading, setDeleteLoading] = useState(false); - /* ---------------------------------------- - Fetch delete preview - ----------------------------------------- */ - useEffect(() => { - if (!deletePropertyId) return; - - setPreviewLoading(true); - setPreviewError(null); - setDeletePreview(null); - - fetch(`/api/properties/${deletePropertyId}/delete/preview`, { - method: "POST", - }) - .then(async (res) => { - if (!res.ok) throw new Error("Failed to fetch delete preview"); - return res.json(); - }) - .then((data) => setDeletePreview(data.preview)) - .catch((err) => setPreviewError(err.message)) - .finally(() => setPreviewLoading(false)); - }, [deletePropertyId]); - - /* ---------------------------------------- - Confirm delete - ----------------------------------------- */ - const handleConfirmDelete = async () => { - if (!deletePropertyId) return; - - setDeleteLoading(true); - - try { - await fetch(`/api/properties/${deletePropertyId}/delete/confirm`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ confirm: true }), - }); - - // Close modal - setDeletePropertyId(null); - setDeletePreview(null); - - // ✅ THIS FIXES THE GHOST ROW - await refetch(); - } catch (err) { - console.error("[DELETE] failed", err); - } finally { - setDeleteLoading(false); - } - }; return (