From 280e2ec029722f910b9f1399984cdb3190cd378b Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Sat, 22 Nov 2025 15:47:07 +0100 Subject: [PATCH] Populate paymentParams with actual data from database MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated ViewLocationCard to accept userSettings prop - Replaced all hardcoded payment values with dynamic data: * Amount calculated from monthly expenses * Payer info from tenant fields (name, street, town) * Recipient info from userSettings (name, street, town, IBAN) * Reference number and description generated from location data - Created getUserSettingsByUserId function for fetching owner settings on public pages - Updated LocationViewPage to fetch and pass userSettings to ViewLocationCard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../share/location/[id]/LocationViewPage.tsx | 8 +++-- app/lib/actions/userSettingsActions.ts | 15 +++++++++ app/ui/ViewLocationCard.tsx | 33 ++++++++++--------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/app/[locale]/share/location/[id]/LocationViewPage.tsx b/app/[locale]/share/location/[id]/LocationViewPage.tsx index 60fcf12..a962b5d 100644 --- a/app/[locale]/share/location/[id]/LocationViewPage.tsx +++ b/app/[locale]/share/location/[id]/LocationViewPage.tsx @@ -1,5 +1,6 @@ import { ViewLocationCard } from '@/app/ui/ViewLocationCard'; import { fetchLocationById, setSeenByTenant } from '@/app/lib/actions/locationActions'; +import { getUserSettingsByUserId } from '@/app/lib/actions/userSettingsActions'; import { notFound } from 'next/navigation'; import { myAuth } from '@/app/lib/auth'; @@ -10,14 +11,17 @@ export default async function LocationViewPage({ locationId }: { locationId:stri return(notFound()); } + // Fetch user settings for the location owner + const userSettings = await getUserSettingsByUserId(location.userId); + // Check if the page was accessed by an authenticated user who is the owner const session = await myAuth(); const isOwner = session?.user?.id === location.userId; - + // If the page is not visited by the owner, mark it as seen by tenant if (!isOwner) { await setSeenByTenant(locationId); } - return (); + return (); } \ No newline at end of file diff --git a/app/lib/actions/userSettingsActions.ts b/app/lib/actions/userSettingsActions.ts index 4e5ca44..8571712 100644 --- a/app/lib/actions/userSettingsActions.ts +++ b/app/lib/actions/userSettingsActions.ts @@ -123,6 +123,21 @@ export const getUserSettings = withUser(async (user: AuthenticatedUser) => { return userSettings; }); +/** + * Get user settings by userId (without authentication) + * Used for public/shared pages where we need to display owner's payment information + */ +export const getUserSettingsByUserId = async (userId: string): Promise => { + noStore(); + + const dbClient = await getDbClient(); + + const userSettings = await dbClient.collection("userSettings") + .findOne({ userId }); + + return userSettings; +}; + /** * Update user settings */ diff --git a/app/ui/ViewLocationCard.tsx b/app/ui/ViewLocationCard.tsx index d69763a..df83d3f 100644 --- a/app/ui/ViewLocationCard.tsx +++ b/app/ui/ViewLocationCard.tsx @@ -1,7 +1,7 @@ 'use client'; import { FC } from "react"; -import { BilledTo, BillingLocation } from "../lib/db-types"; +import { BilledTo, BillingLocation, UserSettings } from "../lib/db-types"; import { formatYearMonth } from "../lib/format"; import { formatCurrency } from "../lib/formatStrings"; import { useTranslations } from "next-intl"; @@ -10,10 +10,13 @@ import { Pdf417Barcode } from "./Pdf417Barcode"; import { PaymentParams } from "hub-3a-payment-encoder"; export interface ViewLocationCardProps { - location: BillingLocation + location: BillingLocation; + userSettings: UserSettings | null; } -export const ViewLocationCard:FC = ({location: { _id, name, yearMonth, bills }}) => { +export const ViewLocationCard:FC = ({location, userSettings}) => { + + const { _id, name, yearMonth, bills, tenantFirstName, tenantLastName, tenantStreet, tenantTown } = location; const t = useTranslations("home-page.location-card"); @@ -21,18 +24,18 @@ export const ViewLocationCard:FC = ({location: { _id, nam const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) ? acc + (bill.payedAmount ?? 0) : acc, 0); const paymentParams:PaymentParams = { - Iznos:"123,66", // NOTE: use comma, not period! - ImePlatitelja:"Ivan Horvat", - AdresaPlatitelja:"Ilica 23", - SjedistePlatitelja:"10000 Zagreb", - Primatelj:"Nikola Derežić", - AdresaPrimatelja:"Divka Budaka 17", - SjedistePrimatelja:"Zagreb", - IBAN:"HR8924020061100679445", - ModelPlacanja: "HR00", // MUST contain "HR" prefix! - PozivNaBroj:"2025-05", - SifraNamjene:"", - OpisPlacanja:"Režije-Budakova-05", + Iznos: (monthlyExpense/100).toFixed(2).replace(".",","), + ImePlatitelja: (tenantFirstName && tenantLastName) ? `${tenantFirstName} ${tenantLastName}` : "", + AdresaPlatitelja: tenantStreet ?? "", + SjedistePlatitelja: tenantTown ?? "", + Primatelj: (userSettings?.firstName && userSettings?.lastName) ? `${userSettings.firstName} ${userSettings.lastName}` : "", + AdresaPrimatelja: userSettings?.street ?? "", + 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(