Populate paymentParams with actual data from database
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 (<ViewLocationCard location={location} />);
|
||||
return (<ViewLocationCard location={location} userSettings={userSettings} />);
|
||||
}
|
||||
@@ -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<UserSettings | null> => {
|
||||
noStore();
|
||||
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
const userSettings = await dbClient.collection<UserSettings>("userSettings")
|
||||
.findOne({ userId });
|
||||
|
||||
return userSettings;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update user settings
|
||||
*/
|
||||
|
||||
@@ -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<ViewLocationCardProps> = ({location: { _id, name, yearMonth, bills }}) => {
|
||||
export const ViewLocationCard:FC<ViewLocationCardProps> = ({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<ViewLocationCardProps> = ({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(
|
||||
|
||||
Reference in New Issue
Block a user