Merge branch 'main' of https://github.com/Hestia-Homes/assessment-model into new-reporting

This commit is contained in:
Khalim Conn-Kowlessar 2025-11-10 22:30:26 +00:00
commit dfce54016d
6 changed files with 1413 additions and 183 deletions

1468
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -15,6 +15,7 @@
},
"dependencies": {
"@aws-sdk/client-sqs": "^3.864.0",
"@aws-sdk/s3-request-presigner": "^3.927.0",
"@headlessui/react": "^2.2.7",
"@heroicons/react": "^2.0.18",
"@hookform/resolvers": "^3.9.1",
@ -45,6 +46,7 @@
"autoprefixer": "10.4.14",
"aws-sdk": "^2.1415.0",
"class-variance-authority": "^0.6.1",
"client-s3": "github:aws-sdk/client-s3",
"clsx": "^1.2.1",
"drizzle-orm": "^0.44.5",
"esbuild": "^0.25.8",

View file

@ -0,0 +1,32 @@
// /app/api/sign-s3-url/route.ts
import { NextResponse } from "next/server";
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
const s3 = new S3Client({
region: process.env.RETROFIT_DATA_DEV_REGION,
credentials: {
accessKeyId: process.env.RETROFIT_DATA_DEV_ACCESS_KEY!,
secretAccessKey: process.env.RETROFIT_DATA_DEV_SECRET_KEY!,
},
});
export async function POST(req: Request) {
try {
const { key } = await req.json(); // key = "path/to/photo.jpg"
if (!key) return NextResponse.json({ error: "Missing key" }, { status: 400 });
const command = new GetObjectCommand({
Bucket: process.env.RETROFIT_DATA_DEV_S3_BUCKET_NAME!,
Key: key,
});
// URL expires in 30 minutes
const signedUrl = await getSignedUrl(s3, command, { expiresIn: 1800 });
return NextResponse.json({ url: signedUrl });
} catch (error) {
console.error("Error generating signed URL:", error);
return NextResponse.json({ error: "Failed to sign URL" }, { status: 500 });
}
}

View file

@ -17,6 +17,7 @@ export const hubspotDealData = pgTable("hubspot_deal_data", {
majorConditionIssueDescription: text("major_condition_issue_description"),
majorConditionIssuePhotos: text("major_condition_issue_photos"),
majorConditionIssuePhotosS3: text("major_condition_issue_evidence_s3_url"),
createdAt: timestamp("created_at", { precision: 6, withTimezone: true })
.defaultNow()

View file

@ -112,11 +112,13 @@ export default function LiveTracker({ deals }: ReportsProps) {
"dealname",
"landlordPropertyId",
"majorConditionIssueDescription",
"majorConditionIssuePhotosS3"
],
{
dealname: "Address Ref.",
landlordPropertyId: "Property Ref.",
majorConditionIssueDescription: "Surveyor's Notes"
majorConditionIssueDescription: "Surveyor's Notes",
majorConditionIssuePhotosS3: "Photo Evidence"
}
)
}

View file

@ -1,6 +1,7 @@
"use client";
import { useState, useMemo } from "react";
import { Download } from "lucide-react";
interface TableViewerProps {
data: Record<string, any>[];
@ -8,9 +9,15 @@ interface TableViewerProps {
columnLabels?: Record<string, string>;
}
export default function TableViewer({ data, columns, columnLabels }: TableViewerProps) {
export default function TableViewer({
data,
columns,
columnLabels,
}: TableViewerProps) {
const [searchTerms, setSearchTerms] = useState<Record<string, string>>({});
const visibleColumns = columns?.length ? columns : Object.keys(data?.[0] || {});
const visibleColumns = columns?.length
? columns
: Object.keys(data?.[0] || {});
const filteredData = useMemo(() => {
return data.filter((row) =>
@ -23,13 +30,77 @@ export default function TableViewer({ data, columns, columnLabels }: TableViewer
);
}, [data, searchTerms, visibleColumns]);
const renderCellContent = (col: string, value: any) => {
if (col === "majorConditionIssuePhotosS3" && value) {
let urls: string[] = [];
if (typeof value === "string") {
try {
const parsed = JSON.parse(value);
urls = Array.isArray(parsed) ? parsed : [value];
} catch {
urls = value.split(/[\s,]+/).filter((u) => u.startsWith("http"));
}
} else if (Array.isArray(value)) {
urls = value;
}
if (urls.length === 0)
return <span className="text-gray-400">No photos</span>;
const handleDownload = async (rawUrl: string) => {
try {
// Extract the object key (after the bucket domain)
const key = rawUrl.split(".amazonaws.com/")[1];
if (!key) return alert("Invalid S3 key");
const res = await fetch("/api/sign-s3-url", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ key }),
});
const data = await res.json();
if (data.url) {
window.open(data.url, "_blank");
} else {
alert("Failed to get signed URL");
}
} catch (err) {
console.error(err);
alert("Error downloading file");
}
};
return (
<div className="flex flex-wrap gap-2">
{urls.map((url, idx) => (
<button
key={idx}
onClick={() => handleDownload(url)}
className="flex items-center gap-1 px-2 py-1 bg-blue-50 text-blue-600 text-xs rounded hover:bg-blue-100 transition"
>
<Download className="w-3 h-3" />
<span>Download Photos</span>
</button>
))}
</div>
);
}
return String(value ?? "");
};
return (
<div className="overflow-x-auto border rounded-xl shadow-lg bg-white">
<table className="min-w-full text-sm border-collapse">
<thead className="bg-gray-100 sticky top-0">
<tr>
{visibleColumns.map((col) => (
<th key={col} className="border-b p-3 text-left text-gray-700 font-semibold">
<th
key={col}
className="border-b p-3 text-left text-gray-700 font-semibold"
>
<div className="flex flex-col gap-1">
<span>{columnLabels?.[col] || col}</span>
<input
@ -37,7 +108,10 @@ export default function TableViewer({ data, columns, columnLabels }: TableViewer
placeholder="Search..."
className="p-1 border border-gray-300 rounded text-xs focus:ring-1 focus:ring-blue-400 outline-none"
onChange={(e) =>
setSearchTerms((prev) => ({ ...prev, [col]: e.target.value }))
setSearchTerms((prev) => ({
...prev,
[col]: e.target.value,
}))
}
/>
</div>
@ -48,7 +122,10 @@ export default function TableViewer({ data, columns, columnLabels }: TableViewer
<tbody>
{filteredData.length === 0 ? (
<tr>
<td colSpan={visibleColumns.length} className="text-center py-6 text-gray-400">
<td
colSpan={visibleColumns.length}
className="text-center py-6 text-gray-400"
>
No results found
</td>
</tr>
@ -60,7 +137,7 @@ export default function TableViewer({ data, columns, columnLabels }: TableViewer
>
{visibleColumns.map((col) => (
<td key={col} className="border-b p-3 text-gray-700">
{String(row[col] ?? "")}
{renderCellContent(col, row[col])}
</td>
))}
</tr>