(refactor) dbTypes: added utilBillsProofOfPaymentUploadedAt to BillingLocation
This commit is contained in:
@@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -23,7 +23,7 @@ export const LocationCard: FC<LocationCardProps> = ({ 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<LocationCardProps> = ({ location, currency }) => {
|
||||
</div>
|
||||
|
||||
|
||||
{monthlyExpense > 0 || seenByTenant || utilBillsProofOfPaymentAttachment ?
|
||||
{monthlyExpense > 0 || seenByTenant || utilBillsProofOfPaymentUploadedAt ?
|
||||
|
||||
<fieldset className="card card-compact card-bordered border-1 border-neutral p-3 mt-2 mr-[3.5rem]">
|
||||
<legend className="fieldset-legend px-2 text-sm font-semibold uppercase">{t("monthly-statement-legend")}</legend>
|
||||
@@ -78,7 +78,7 @@ export const LocationCard: FC<LocationCardProps> = ({ location, currency }) => {
|
||||
<CheckCircleIcon className="h-5 w-5 text-success" />
|
||||
</div>
|
||||
)}
|
||||
{utilBillsProofOfPaymentAttachment && (
|
||||
{utilBillsProofOfPaymentUploadedAt && (
|
||||
<Link
|
||||
href={`/share/proof-of-payment/${_id}/`}
|
||||
target="_blank"
|
||||
|
||||
@@ -29,13 +29,15 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({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<string | null>(null);
|
||||
const [attachmentUploadedAt, setAttachmentUploadedAt ] = useState<Date | null>(utilBillsProofOfPaymentUploadedAt ?? null);
|
||||
const [attachmentFilename, setAttachmentFilename] = useState(utilBillsProofOfPaymentAttachment?.fileName);
|
||||
|
||||
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -60,6 +62,7 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
|
||||
|
||||
if (result.success) {
|
||||
setAttachmentFilename(file.name);
|
||||
setAttachmentUploadedAt(new Date());
|
||||
} else {
|
||||
setUploadError(result.error || 'Upload failed');
|
||||
}
|
||||
@@ -144,8 +147,13 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
|
||||
}
|
||||
<fieldset className="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4 pb-2 pt-0 mt-2">
|
||||
<legend className="fieldset-legend font-semibold uppercase">{t("upload-proof-of-payment-legend")}</legend>
|
||||
|
||||
{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 ? (
|
||||
<div className="mt-3 ml-[-.5rem]">
|
||||
<Link
|
||||
href={`/share/proof-of-payment/${_id}/`}
|
||||
@@ -156,7 +164,8 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
|
||||
{decodeURIComponent(attachmentFilename)}
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
) : null
|
||||
) : /* ELSE show upload input */ (
|
||||
<div className="form-control w-full">
|
||||
<label className="label">
|
||||
<span className="label-text">{t("upload-proof-of-payment-label")}</span>
|
||||
|
||||
Reference in New Issue
Block a user