diff --git a/app/ui/LocationCard.tsx b/app/ui/LocationCard.tsx index 7944935..52c542b 100644 --- a/app/ui/LocationCard.tsx +++ b/app/ui/LocationCard.tsx @@ -16,7 +16,15 @@ export interface LocationCardProps { } export const LocationCard: FC = ({ location, currency }) => { - const { _id, name, yearMonth, bills, seenByTenant, utilBillsProofOfPaymentAttachment } = location; + const { + _id, + name, + yearMonth, + bills, + seenByTenant, + // NOTE: only the fileName is projected from the DB to reduce data transfer + utilBillsProofOfPaymentAttachment + } = location; const t = useTranslations("home-page.location-card"); const currentLocale = useLocale(); diff --git a/app/ui/MonthLocationList.tsx b/app/ui/MonthLocationList.tsx index 7433fb7..dc29c08 100644 --- a/app/ui/MonthLocationList.tsx +++ b/app/ui/MonthLocationList.tsx @@ -124,17 +124,17 @@ export const MonthLocationList:React.FC = ({ { monthsArray.map(([monthKey, { yearMonth, locations, monthlyExpense }], monthIx) => - - { - yearMonth.month === expandedMonth ? - locations.map((location, ix) => ) - : null - } -
- - -
-
+ + { + yearMonth.month === expandedMonth ? + locations.map((location, ix) => ) + : null + } +
+ + +
+
) }
diff --git a/app/ui/ViewLocationCard.tsx b/app/ui/ViewLocationCard.tsx index ab8682e..3f1043f 100644 --- a/app/ui/ViewLocationCard.tsx +++ b/app/ui/ViewLocationCard.tsx @@ -1,7 +1,7 @@ 'use client'; import { FC, useState } from "react"; -import { BilledTo, BillingLocation, UserSettings } from "../lib/db-types"; +import { BillAttachment, BilledTo, BillingLocation, UserSettings } from "../lib/db-types"; import { formatYearMonth } from "../lib/format"; import { formatCurrency } from "../lib/formatStrings"; import { useTranslations } from "next-intl"; @@ -19,13 +19,24 @@ export interface ViewLocationCardProps { export const ViewLocationCard:FC = ({location, userSettings}) => { - const { _id, name: locationName, yearMonth, bills, tenantName, tenantStreet, tenantTown, generateTenantCode, utilBillsProofOfPaymentAttachment } = location; + const { + _id, + name: locationName, + yearMonth, + bills, + tenantName, + tenantStreet, + tenantTown, + generateTenantCode, + // NOTE: only the fileName is projected from the DB to reduce data transfer + utilBillsProofOfPaymentAttachment + } = location; const t = useTranslations("home-page.location-card"); const [isUploading, setIsUploading] = useState(false); const [uploadError, setUploadError] = useState(null); - const [attachment, setAttachment] = useState(utilBillsProofOfPaymentAttachment); + const [attachmentFilename, setAttachmentFilename] = useState(utilBillsProofOfPaymentAttachment?.fileName); const handleFileChange = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; @@ -48,14 +59,7 @@ export const ViewLocationCard:FC = ({location, userSettin const result = await uploadUtilBillsProofOfPayment(_id, formData); if (result.success) { - // Update local state with the uploaded attachment - setAttachment({ - fileName: file.name, - fileSize: file.size, - fileType: file.type, - fileLastModified: file.lastModified, - fileContentsBase64: '', // We don't need the contents in the UI - }); + setAttachmentFilename(file.name); } else { setUploadError(result.error || 'Upload failed'); } @@ -127,7 +131,7 @@ export const ViewLocationCard:FC = ({location, userSettin
{t("upload-proof-of-payment-legend")} - {attachment ? ( + {attachmentFilename ? (
= ({location, userSettin className='text-center w-full max-w-[20rem] text-nowrap truncate inline-block' > - {decodeURIComponent(attachment.fileName)} + {decodeURIComponent(attachmentFilename)}
) : (