From 600e31e7b1478dc92e72efdc3826c42288576b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Mon, 24 Nov 2025 16:48:23 +0100 Subject: [PATCH] feat: disable payment method select when no payment methods configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add userSettings prop to LocationEditForm to check payment configuration - Disable payment method dropdown when neither IBAN nor Revolut is enabled - Force select value to "none" when both methods are disabled - Disable individual IBAN/Revolut options when not configured - Display NoteBox warning explaining why payment options are unavailable - Update LocationEditPage and LocationAddPage to fetch and pass userSettings - Add English and Croatian translations for disabled state message This prevents users from configuring location payment methods before setting up their own payment info. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../location/[id]/add/LocationAddPage.tsx | 4 ++- .../location/[id]/edit/LocationEditPage.tsx | 7 ++-- app/ui/LocationEditForm.tsx | 32 ++++++++++++++----- messages/en.json | 11 ++++--- messages/hr.json | 1 + 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/app/[locale]/location/[id]/add/LocationAddPage.tsx b/app/[locale]/location/[id]/add/LocationAddPage.tsx index 9556980..93c65ec 100644 --- a/app/[locale]/location/[id]/add/LocationAddPage.tsx +++ b/app/[locale]/location/[id]/add/LocationAddPage.tsx @@ -1,6 +1,8 @@ import { LocationEditForm } from '@/app/ui/LocationEditForm'; import { YearMonth } from '@/app/lib/db-types'; +import { getUserSettings } from '@/app/lib/actions/userSettingsActions'; export default async function LocationAddPage({ yearMonth }: { yearMonth:YearMonth }) { - return (); + const userSettings = await getUserSettings(); + return (); } \ No newline at end of file diff --git a/app/[locale]/location/[id]/edit/LocationEditPage.tsx b/app/[locale]/location/[id]/edit/LocationEditPage.tsx index 505f634..b99203e 100644 --- a/app/[locale]/location/[id]/edit/LocationEditPage.tsx +++ b/app/[locale]/location/[id]/edit/LocationEditPage.tsx @@ -1,6 +1,7 @@ import { notFound } from 'next/navigation'; import { LocationEditForm } from '@/app/ui/LocationEditForm'; import { fetchLocationById } from '@/app/lib/actions/locationActions'; +import { getUserSettings } from '@/app/lib/actions/userSettingsActions'; export default async function LocationEditPage({ locationId }: { locationId:string }) { @@ -10,7 +11,9 @@ export default async function LocationEditPage({ locationId }: { locationId:stri return(notFound()); } - const result = ; - + const userSettings = await getUserSettings(); + + const result = ; + return (result); } \ No newline at end of file diff --git a/app/ui/LocationEditForm.tsx b/app/ui/LocationEditForm.tsx index 8525413..00c5e1c 100644 --- a/app/ui/LocationEditForm.tsx +++ b/app/ui/LocationEditForm.tsx @@ -2,26 +2,31 @@ import { TrashIcon } from "@heroicons/react/24/outline"; import { FC, useState } from "react"; -import { BillingLocation, YearMonth } from "../lib/db-types"; +import { BillingLocation, UserSettings, YearMonth } from "../lib/db-types"; import { updateOrAddLocation } from "../lib/actions/locationActions"; import { useFormState } from "react-dom"; import Link from "next/link"; import { useLocale, useTranslations } from "next-intl"; import { InfoBox } from "./InfoBox"; +import { NoteBox } from "./NoteBox"; export type LocationEditFormProps = { /** location which should be edited */ location: BillingLocation, /** year adn month at a new billing location should be assigned */ - yearMonth?: undefined + yearMonth?: undefined, + /** user settings for payment configuration */ + userSettings: UserSettings | null } | { /** location which should be edited */ location?: undefined, /** year adn month at a new billing location should be assigned */ - yearMonth: YearMonth + yearMonth: YearMonth, + /** user settings for payment configuration */ + userSettings: UserSettings | null } -export const LocationEditForm: FC = ({ location, yearMonth }) => { +export const LocationEditForm: FC = ({ location, yearMonth, userSettings }) => { const initialState = { message: null, errors: {} }; const handleAction = updateOrAddLocation.bind(null, location?._id, location?.yearMonth ?? yearMonth); @@ -83,17 +88,28 @@ export const LocationEditForm: FC = ({ location, yearMont
{t("tenant-payment-instructions-legend")} - + {t("tenant-payment-instructions-code-info")}
{t("tenant-payment-instructions-method--legend")} - handleInputChange("tenantPaymentMethod", e.target.value)} + disabled={!userSettings?.enableIbanPayment && !userSettings?.enableRevolutPayment} + > - - + +
+ { + !userSettings?.enableIbanPayment && !userSettings?.enableRevolutPayment && ( + {t("tenant-payment-instructions-method--disabled-message")} + ) + } { formValues.tenantPaymentMethod === "iban" ? ( <> diff --git a/messages/en.json b/messages/en.json index 947fac3..c3644c2 100644 --- a/messages/en.json +++ b/messages/en.json @@ -146,11 +146,12 @@ "tenant-payment-instructions-legend": "PAYMENT INSTRUCTIONS", "tenant-payment-instructions-code-info": "When the tenant opens the link to the statement for the given month, the application can show payment instructions for utility costs to your IBAN, as well as a 2D code they can scan.", - "tenant-payment-instructions-method--legend": "Podstanaru prikaži upute za uplatu:", - "tenant-payment-instructions-method--none": "ne prikazuj upute za uplatu", - "tenant-payment-instructions-method--iban": "uplata na IBAN", - "tenant-payment-instructions-method--revolut": "uplata na Revolut", - + "tenant-payment-instructions-method--legend": "Show payment instructions to tenant:", + "tenant-payment-instructions-method--none": "do not show payment instructions", + "tenant-payment-instructions-method--iban": "payment via IBAN", + "tenant-payment-instructions-method--revolut": "payment via Revolut", + "tenant-payment-instructions-method--disabled-message": "IMPORTANT: Payment instructions are not available because neither IBAN nor Revolut payment methods are configured in your user settings. Please go to Settings and enable at least one payment method.", + "tenant--payment-instructions-note": "IMPORTANT: for this to work you will also need to go into app settings and enter your name and IBAN.", "iban-payment--tenant-name-label": "Tenant First and Last Name", diff --git a/messages/hr.json b/messages/hr.json index 299cab1..419d324 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -149,6 +149,7 @@ "tenant-payment-instructions-method--none": "ne prikazuj upute za uplatu", "tenant-payment-instructions-method--iban": "uplata na IBAN", "tenant-payment-instructions-method--revolut": "uplata na Revolut", + "tenant-payment-instructions-method--disabled-message": "VAŽNO: Upute za uplatu nisu dostupne jer niti IBAN niti Revolut metode plaćanja nisu konfigurirane u vašim korisničkim postavkama. Molimo idite u Postavke i omogućite barem jednu metodu plaćanja.", "tenant--payment-instructions-note": "VAŽNO: za ovu funkcionalnost potrebno je otvoriti postavke aplikacije, te unijeti vaše ime i IBAN.",