(bugfix) ViewLocationCard: hub3a string was calculated even if this option was disabled

This commit is contained in:
Knee Cola
2025-11-23 21:39:05 +01:00
parent 9cc5241c05
commit 6c43c69934

View File

@@ -1,6 +1,6 @@
'use client';
import { FC, useState } from "react";
import { FC, useEffect, useMemo, useState } from "react";
import { BillAttachment, BilledTo, BillingLocation, UserSettings } from "../lib/db-types";
import { formatYearMonth } from "../lib/format";
import { formatCurrency } from "../lib/formatStrings";
@@ -74,6 +74,11 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
// sum all the billAmounts (only for bills billed to tenant)
const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) ? acc + (bill.payedAmount ?? 0) : acc, 0);
const hub3a_text = useMemo(() => {
if(!userSettings?.show2dCodeInMonthlyStatement || !generateTenantCode) {
return "";
}
const locationNameTrimmed_max20 = locationName.trimEnd().trimEnd().substring(0,19);
const paymentParams:PaymentParams = {
@@ -91,7 +96,8 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
OpisPlacanja: `Režije-${locationNameTrimmed_max20}-${formatYearMonth(yearMonth)}`, // max length 35 = "Režije-" (7) + locationName (20) + "-" (1) + "YYYY-MM" (7)
};
const hub3a_text = EncodePayment(paymentParams);
return(EncodePayment(paymentParams));
}, [userSettings?.show2dCodeInMonthlyStatement, generateTenantCode, locationName, tenantName, tenantStreet, tenantTown, userSettings, monthlyExpense, yearMonth]);
return(
<div data-key={_id } className="card card-compact card-bordered max-w-[30em] min-w-[350px] bg-base-100 border-1 border-neutral my-1">