feat: disable payment method select when no payment methods configured
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { LocationEditForm } from '@/app/ui/LocationEditForm';
|
import { LocationEditForm } from '@/app/ui/LocationEditForm';
|
||||||
import { YearMonth } from '@/app/lib/db-types';
|
import { YearMonth } from '@/app/lib/db-types';
|
||||||
|
import { getUserSettings } from '@/app/lib/actions/userSettingsActions';
|
||||||
|
|
||||||
export default async function LocationAddPage({ yearMonth }: { yearMonth:YearMonth }) {
|
export default async function LocationAddPage({ yearMonth }: { yearMonth:YearMonth }) {
|
||||||
return (<LocationEditForm yearMonth={yearMonth} />);
|
const userSettings = await getUserSettings();
|
||||||
|
return (<LocationEditForm yearMonth={yearMonth} userSettings={userSettings} />);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
import { LocationEditForm } from '@/app/ui/LocationEditForm';
|
import { LocationEditForm } from '@/app/ui/LocationEditForm';
|
||||||
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
import { fetchLocationById } from '@/app/lib/actions/locationActions';
|
||||||
|
import { getUserSettings } from '@/app/lib/actions/userSettingsActions';
|
||||||
|
|
||||||
export default async function LocationEditPage({ locationId }: { locationId:string }) {
|
export default async function LocationEditPage({ locationId }: { locationId:string }) {
|
||||||
|
|
||||||
@@ -10,7 +11,9 @@ export default async function LocationEditPage({ locationId }: { locationId:stri
|
|||||||
return(notFound());
|
return(notFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = <LocationEditForm location={location} />;
|
const userSettings = await getUserSettings();
|
||||||
|
|
||||||
|
const result = <LocationEditForm location={location} userSettings={userSettings} />;
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
@@ -2,26 +2,31 @@
|
|||||||
|
|
||||||
import { TrashIcon } from "@heroicons/react/24/outline";
|
import { TrashIcon } from "@heroicons/react/24/outline";
|
||||||
import { FC, useState } from "react";
|
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 { updateOrAddLocation } from "../lib/actions/locationActions";
|
||||||
import { useFormState } from "react-dom";
|
import { useFormState } from "react-dom";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useLocale, useTranslations } from "next-intl";
|
import { useLocale, useTranslations } from "next-intl";
|
||||||
import { InfoBox } from "./InfoBox";
|
import { InfoBox } from "./InfoBox";
|
||||||
|
import { NoteBox } from "./NoteBox";
|
||||||
|
|
||||||
export type LocationEditFormProps = {
|
export type LocationEditFormProps = {
|
||||||
/** location which should be edited */
|
/** location which should be edited */
|
||||||
location: BillingLocation,
|
location: BillingLocation,
|
||||||
/** year adn month at a new billing location should be assigned */
|
/** 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 which should be edited */
|
||||||
location?: undefined,
|
location?: undefined,
|
||||||
/** year adn month at a new billing location should be assigned */
|
/** 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<LocationEditFormProps> = ({ location, yearMonth }) => {
|
export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMonth, userSettings }) => {
|
||||||
const initialState = { message: null, errors: {} };
|
const initialState = { message: null, errors: {} };
|
||||||
|
|
||||||
const handleAction = updateOrAddLocation.bind(null, location?._id, location?.yearMonth ?? yearMonth);
|
const handleAction = updateOrAddLocation.bind(null, location?._id, location?.yearMonth ?? yearMonth);
|
||||||
@@ -88,12 +93,23 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
|
|||||||
|
|
||||||
<fieldset className="fieldset mt-2 p-2">
|
<fieldset className="fieldset mt-2 p-2">
|
||||||
<legend className="fieldset-legend">{t("tenant-payment-instructions-method--legend")}</legend>
|
<legend className="fieldset-legend">{t("tenant-payment-instructions-method--legend")}</legend>
|
||||||
<select defaultValue={formValues.tenantPaymentMethod} className="select input-bordered w-full" name="tenantPaymentMethod" onChange={(e) => handleInputChange("tenantPaymentMethod", e.target.value)}>
|
<select
|
||||||
|
value={(!userSettings?.enableIbanPayment && !userSettings?.enableRevolutPayment) ? "none" : formValues.tenantPaymentMethod}
|
||||||
|
className="select input-bordered w-full"
|
||||||
|
name="tenantPaymentMethod"
|
||||||
|
onChange={(e) => handleInputChange("tenantPaymentMethod", e.target.value)}
|
||||||
|
disabled={!userSettings?.enableIbanPayment && !userSettings?.enableRevolutPayment}
|
||||||
|
>
|
||||||
<option value="none">{t("tenant-payment-instructions-method--none")}</option>
|
<option value="none">{t("tenant-payment-instructions-method--none")}</option>
|
||||||
<option value="iban">{t("tenant-payment-instructions-method--iban")}</option>
|
<option value="iban" disabled={!userSettings?.enableIbanPayment}>{t("tenant-payment-instructions-method--iban")}</option>
|
||||||
<option value="revolut">{t("tenant-payment-instructions-method--revolut")}</option>
|
<option value="revolut" disabled={!userSettings?.enableRevolutPayment}>{t("tenant-payment-instructions-method--revolut")}</option>
|
||||||
</select>
|
</select>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
{
|
||||||
|
!userSettings?.enableIbanPayment && !userSettings?.enableRevolutPayment && (
|
||||||
|
<NoteBox className="p-1 mt-2">{t("tenant-payment-instructions-method--disabled-message")}</NoteBox>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{ formValues.tenantPaymentMethod === "iban" ? (
|
{ formValues.tenantPaymentMethod === "iban" ? (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -146,10 +146,11 @@
|
|||||||
"tenant-payment-instructions-legend": "PAYMENT INSTRUCTIONS",
|
"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-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--legend": "Show payment instructions to tenant:",
|
||||||
"tenant-payment-instructions-method--none": "ne prikazuj upute za uplatu",
|
"tenant-payment-instructions-method--none": "do not show payment instructions",
|
||||||
"tenant-payment-instructions-method--iban": "uplata na IBAN",
|
"tenant-payment-instructions-method--iban": "payment via IBAN",
|
||||||
"tenant-payment-instructions-method--revolut": "uplata na Revolut",
|
"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.",
|
"tenant--payment-instructions-note": "IMPORTANT: for this to work you will also need to go into app settings and enter your name and IBAN.",
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@
|
|||||||
"tenant-payment-instructions-method--none": "ne prikazuj 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--iban": "uplata na IBAN",
|
||||||
"tenant-payment-instructions-method--revolut": "uplata na Revolut",
|
"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.",
|
"tenant--payment-instructions-note": "VAŽNO: za ovu funkcionalnost potrebno je otvoriti postavke aplikacije, te unijeti vaše ime i IBAN.",
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user