Changes:
- Updated UserSettings interface: street -> ownerStreet
- Updated userSettingsActions.ts:
- Changed State type to use ownerStreet
- Added max length validation (25 characters) to FormSchema
- Updated validation refinement to check ownerStreet
- Updated form data parsing to read ownerStreet
- Updated database write operations to use ownerStreet
- Updated UserSettingsForm.tsx:
- Changed state tracking to use ownerStreet
- Updated validation check to reference ownerStreet
- Updated input field: id, name, maxLength={25}
- Updated ViewLocationCard.tsx to use ownerStreet instead of street
- Updated English translations:
- street-label -> owner-street-label: "Your Street and House Number"
- street-placeholder -> owner-street-placeholder
- street-required -> owner-street-required
- Updated Croatian translations with corresponding ownerStreet keys
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
4.0 KiB
TypeScript
72 lines
4.0 KiB
TypeScript
'use client';
|
|
|
|
import { FC } from "react";
|
|
import { BilledTo, BillingLocation, UserSettings } from "../lib/db-types";
|
|
import { formatYearMonth } from "../lib/format";
|
|
import { formatCurrency } from "../lib/formatStrings";
|
|
import { useTranslations } from "next-intl";
|
|
import { ViewBillBadge } from "./ViewBillBadge";
|
|
import { Pdf417Barcode } from "./Pdf417Barcode";
|
|
import { PaymentParams } from "hub-3a-payment-encoder";
|
|
|
|
export interface ViewLocationCardProps {
|
|
location: BillingLocation;
|
|
userSettings: UserSettings | null;
|
|
}
|
|
|
|
export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettings}) => {
|
|
|
|
const { _id, name, yearMonth, bills, tenantName, tenantStreet, tenantTown } = location;
|
|
|
|
const t = useTranslations("home-page.location-card");
|
|
|
|
// 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 paymentParams:PaymentParams = {
|
|
Iznos: (monthlyExpense/100).toFixed(2).replace(".",","),
|
|
ImePlatitelja: tenantName ?? "",
|
|
AdresaPlatitelja: tenantStreet ?? "",
|
|
SjedistePlatitelja: tenantTown ?? "",
|
|
Primatelj: userSettings?.ownerName ?? "",
|
|
AdresaPrimatelja: userSettings?.ownerStreet ?? "",
|
|
SjedistePrimatelja: userSettings?.town ?? "",
|
|
IBAN: userSettings?.iban ?? "",
|
|
ModelPlacanja: "HR00",
|
|
PozivNaBroj: `${yearMonth.year}-${yearMonth.month.toString().padStart(2,"0")}`,
|
|
SifraNamjene: "",
|
|
OpisPlacanja: `Režije-${name}-${yearMonth.month.toString().padStart(2,"0")}`,
|
|
};
|
|
|
|
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">
|
|
<div className="card-body">
|
|
<h2 className="card-title mr-[2em] text-[1.3rem]">{formatYearMonth(yearMonth)} {name}</h2>
|
|
<div className="card-actions mt-[1em] mb-[1em]">
|
|
{
|
|
bills.filter(bill => (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant).map(bill => <ViewBillBadge key={`${_id}-${bill._id}`} locationId={_id} bill={bill} />)
|
|
}
|
|
</div>
|
|
{
|
|
monthlyExpense > 0 ?
|
|
<p className="text-[1.2rem]">
|
|
{ t("payed-total-label") } <strong>${formatCurrency(monthlyExpense)}</strong>
|
|
</p>
|
|
: null
|
|
}
|
|
<p className="max-w-[25em] ml-1 mt-1 mb-1">{t("payment-info-header")}</p>
|
|
<ul className="ml-4 mb-3">
|
|
<li><strong>{t("payment-amount-label")}</strong> <pre className="inline pl-1">{paymentParams.Iznos}</pre></li>
|
|
<li><strong>{t("payment-recipient-label")}</strong> <pre className="inline pl-1">{paymentParams.Primatelj}</pre></li>
|
|
<li><strong>{t("payment-recipient-address-label")}</strong><pre className="inline pl-1">{paymentParams.AdresaPrimatelja}</pre></li>
|
|
<li><strong>{t("payment-recipient-city-label")}</strong><pre className="inline pl-1">{paymentParams.SjedistePrimatelja}</pre></li>
|
|
<li><strong>{t("payment-iban-label")}</strong><pre className="inline pl-1">{paymentParams.IBAN}</pre></li>
|
|
<li><strong>{t("payment-model-label")}</strong><pre className="inline pl-1">{paymentParams.ModelPlacanja}</pre></li>
|
|
<li><strong>{t("payment-reference-label")}</strong><pre className="inline pl-1">{paymentParams.PozivNaBroj}</pre></li>
|
|
<li><strong>{t("payment-purpose-code-label")}</strong><pre className="inline pl-1">{paymentParams.SifraNamjene}</pre></li>
|
|
<li><strong>{t("payment-description-label")}</strong><pre className="inline pl-1">{paymentParams.OpisPlacanja}</pre></li>
|
|
</ul>
|
|
<Pdf417Barcode paymentParams={paymentParams} />
|
|
</div>
|
|
</div>);
|
|
}; |