save current work that allows uprn information

This commit is contained in:
Jun-te kim 2025-08-13 20:23:29 +00:00
parent 60ce2b4e82
commit d58e6f0300
4 changed files with 40 additions and 7 deletions

View file

@ -10,6 +10,7 @@ import { BrandButton } from "@/app/components/Buttons";
import { MenuButton } from "./MenuButton";
import { useState } from "react";
import { UploadModal } from "./UploadModal";
import { getPropertyMeta } from "../utils";
// Descriptions based on the document types
const descriptions: Record<ReportType, string> = {
@ -30,12 +31,14 @@ export const DocumentSection = ({
docs,
sectionKey,
documentType,
uprn,
fileTypes,
}: {
title: string;
docs: DocumentWithAuthor[];
sectionKey: string;
documentType: ReportType;
uprn: string;
fileTypes: ".xml,.pdf" | ".xml" | ".pdf";
}) => {
const [showUploadModal, setShowUploadModal] = useState(false);
@ -74,6 +77,7 @@ export const DocumentSection = ({
onClose={() => setShowUploadModal(false)}
documentType={documentType}
fileTypes={fileTypes}
uprn={uprn}
/>
</TableCell>
</TableRow>

View file

@ -16,6 +16,7 @@ import { MenuButton } from "./MenuButton";
type Props = {
documents: DocumentWithAuthor[];
uprn: string,
// allowedTypes: (typeof DocumentType)[number][]; // Use the union type for allowedTypes as well
};
@ -36,6 +37,7 @@ async function generatePresignedUrl(fileKey: string) {
export const DocumentsTable: React.FC<Props> = ({
documents,
uprn,
// allowedTypes,
}) => {
const [expanded, setExpanded] = React.useState(false);
@ -71,6 +73,10 @@ export const DocumentsTable: React.FC<Props> = ({
(doc) => doc.documentType === "QUIDOS_PRESITE_NOTE"
);
const osmosisConditionReport = documents.filter(
(doc) => doc.documentType === "OSMOSIS_CONDITION_PAS_2035_REPORT"
);
const domnaConditionReport = documents.filter(
(doc) => doc.documentType === "DOMNA_CONDITION_PAS_2035_REPORT"
);
@ -90,6 +96,7 @@ export const DocumentsTable: React.FC<Props> = ({
docs={quidosPreSite}
sectionKey="rdsap"
documentType="QUIDOS_PRESITE_NOTE"
uprn={uprn}
fileTypes=".pdf"
/>
<TableRow className="hover:bg-transparent">
@ -98,9 +105,10 @@ export const DocumentsTable: React.FC<Props> = ({
<DocumentSection
title="Condition Report"
docs={domnaConditionReport}
docs={osmosisConditionReport}
sectionKey="condition"
documentType="DOMNA_CONDITION_PAS_2035_REPORT"
documentType="OSMOSIS_CONDITION_PAS_2035_REPORT"
uprn={uprn}
fileTypes=".pdf"
/>
@ -113,6 +121,7 @@ export const DocumentsTable: React.FC<Props> = ({
docs={floors}
sectionKey="floorplan"
documentType="FLOOR_PLAN"
uprn={uprn}
fileTypes=".pdf"
/>
@ -125,6 +134,7 @@ export const DocumentsTable: React.FC<Props> = ({
docs={occupancy}
sectionKey="occupancy"
documentType="OCCUPANCY_ASSESSMENT"
uprn={uprn}
fileTypes=".pdf"
/>

View file

@ -11,13 +11,16 @@ import {
import { Button } from "@/app/shadcn_components/ui/button";
import { ReportType } from "@/app/db/documents_schema/documents";
import { Input } from "@/app/shadcn_components/ui/input";
import { useParams } from 'next/navigation';
import { useState } from "react";
import { uploadFileToS3 } from "@/app/utils/s3";
import { getPropertyMeta } from "../utils";
type UploadModalProps = {
open: boolean;
onClose: () => void;
documentType: string;
uprn:string;
fileTypes: ".xml,.pdf" | ".xml" | ".pdf";
};
@ -56,26 +59,39 @@ export const UploadModal = ({
open,
onClose,
documentType,
uprn,
fileTypes = ".xml,.pdf",
}: UploadModalProps) => {
const [uploadFiles, setUploadFiles] = useState<File[]>([]);
const [buttonDisabled, setButtonDisabled] = useState(true);
async function handleS3Upload() {
const timestamp = new Date()
.toISOString()
.replace(/[-:]/g, "")
.replace("T", "_")
.split(".")[0]; // remove milliseconds
const fileExtension = uploadFiles[0].name.split(".").pop() || "pdf";
const s3Key = `documents/${uprn}/${documentType}/${timestamp}.${fileExtension}`;
console.log("Get Presigned url in a specific bucket location")
console.log("files are", uploadFiles[0]);
const { url } = await generatePresignedUrls({
path: "foo/test/trololol", // path in bucket
path: s3Key, // path in bucket
contentType: "application/pdf",
expiresInSeconds: 5 * 60,
});
console.log("URl is ", url);
console.log("uploading file");
console.log("Retrievied url ", url);
console.log("uploading file...");
await uploadFileToS3({
presignedUrl: url,
file: uploadFiles[0],
contentType: "application/pdf"
})
console.log("uploading Completed!!! Check aws");
onClose(); //probably khalim call back to update the front end properl
}

View file

@ -60,7 +60,10 @@ export default async function DocumentsPage(
Core Survey Documents
</div>
<div className="py-4">
<DocumentsTable documents={documents?.documents ?? []} />
<DocumentsTable
documents={documents?.documents ?? []}
uprn={propertyMeta.uprn}
/>
</div>
<div className="flex items-center justify-between py-4 px-6 bg-brandblue text-white font-semibold text-lg rounded-md">