diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index 1bb4f84..369f178 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -435,6 +435,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu // "bills.hub3aText": 1, // project only file name - leave out file content so that // less data is transferred to the client + "utilBillsProofOfPaymentUploadedAt": 1, "utilBillsProofOfPaymentAttachment.fileName": 1, }, }, diff --git a/app/lib/actions/monthActions.ts b/app/lib/actions/monthActions.ts index 2fcde2d..d33d929 100644 --- a/app/lib/actions/monthActions.ts +++ b/app/lib/actions/monthActions.ts @@ -41,6 +41,7 @@ export const addMonth = withUser(async (user:AuthenticatedUser, { year, month }: ...prevLocation, // clear properties specific to the month seenByTenant: undefined, + utilBillsProofOfPaymentUploadedAt: undefined, utilBillsProofOfPaymentAttachment: undefined, // assign a new ID _id: (new ObjectId()).toHexString(), diff --git a/app/ui/LocationCard.tsx b/app/ui/LocationCard.tsx index 52c542b..a2eaf07 100644 --- a/app/ui/LocationCard.tsx +++ b/app/ui/LocationCard.tsx @@ -23,7 +23,7 @@ export const LocationCard: FC = ({ location, currency }) => { bills, seenByTenant, // NOTE: only the fileName is projected from the DB to reduce data transfer - utilBillsProofOfPaymentAttachment + utilBillsProofOfPaymentUploadedAt } = location; const t = useTranslations("home-page.location-card"); @@ -58,7 +58,7 @@ export const LocationCard: FC = ({ location, currency }) => { - {monthlyExpense > 0 || seenByTenant || utilBillsProofOfPaymentAttachment ? + {monthlyExpense > 0 || seenByTenant || utilBillsProofOfPaymentUploadedAt ?
{t("monthly-statement-legend")} @@ -78,7 +78,7 @@ export const LocationCard: FC = ({ location, currency }) => { )} - {utilBillsProofOfPaymentAttachment && ( + {utilBillsProofOfPaymentUploadedAt && ( = ({location, userSettin tenantTown, generateTenantCode, // NOTE: only the fileName is projected from the DB to reduce data transfer - utilBillsProofOfPaymentAttachment + utilBillsProofOfPaymentAttachment, + utilBillsProofOfPaymentUploadedAt, } = location; const t = useTranslations("home-page.location-card"); const [isUploading, setIsUploading] = useState(false); const [uploadError, setUploadError] = useState(null); + const [attachmentUploadedAt, setAttachmentUploadedAt ] = useState(utilBillsProofOfPaymentUploadedAt ?? null); const [attachmentFilename, setAttachmentFilename] = useState(utilBillsProofOfPaymentAttachment?.fileName); const handleFileChange = async (e: React.ChangeEvent) => { @@ -60,6 +62,7 @@ export const ViewLocationCard:FC = ({location, userSettin if (result.success) { setAttachmentFilename(file.name); + setAttachmentUploadedAt(new Date()); } else { setUploadError(result.error || 'Upload failed'); } @@ -144,19 +147,25 @@ export const ViewLocationCard:FC = ({location, userSettin }
{t("upload-proof-of-payment-legend")} - - {attachmentFilename ? ( -
- - - {decodeURIComponent(attachmentFilename)} - -
- ) : ( + { + // IF proof of payment was uploaded + attachmentUploadedAt ? ( + // IF file name is available, show link to download + // ELSE it's not available that means that the uploaded file was purged by housekeeping + // -> don't show anything + attachmentFilename ? ( +
+ + + {decodeURIComponent(attachmentFilename)} + +
+ ) : null + ) : /* ELSE show upload input */ (