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(