diff --git a/app/lib/actions/userSettingsActions.ts b/app/lib/actions/userSettingsActions.ts index 62e175c..96560b8 100644 --- a/app/lib/actions/userSettingsActions.ts +++ b/app/lib/actions/userSettingsActions.ts @@ -19,6 +19,7 @@ export type State = { ownerTown?: string[]; ownerIBAN?: string[]; currency?: string[]; + ownerRevolutProfileName?: string[]; }; message?: string | null; success?: boolean; @@ -96,6 +97,26 @@ const FormSchema = (t: IntlTemplateFn) => z.object({ }, { message: t("currency-required"), path: ["currency"], +}) +.refine((data) => { + if (data.enableRevolutPayment) { + return !!data.ownerRevolutProfileName && data.ownerRevolutProfileName.trim().length > 0; + } + return true; +}, { + message: t("owner-revolut-profile-required"), + path: ["ownerRevolutProfileName"], +}) +.refine((data) => { + if (data.enableRevolutPayment && data.ownerRevolutProfileName) { + const profileName = data.ownerRevolutProfileName.trim(); + // Must start with @ and contain only English letters and numbers + return /^@[a-zA-Z0-9]+$/.test(profileName); + } + return true; +}, { + message: t("owner-revolut-profile-invalid"), + path: ["ownerRevolutProfileName"], }); /** diff --git a/messages/en.json b/messages/en.json index f67ccb3..0117b53 100644 --- a/messages/en.json +++ b/messages/en.json @@ -232,6 +232,8 @@ "owner-iban-required": "Valid IBAN is mandatory", "owner-iban-invalid": "Invalid IBAN format. Please enter a valid IBAN", "currency-required": "Currency is mandatory", + "owner-revolut-profile-required": "Revolut profile name is mandatory", + "owner-revolut-profile-invalid": "Invalid Revolut profile format. Must start with '@' and contain only English letters and numbers (e.g., '@john123')", "validation-failed": "Validation failed. Please check the form and try again." } } diff --git a/messages/hr.json b/messages/hr.json index edc862b..629a9f0 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -236,6 +236,8 @@ "owner-iban-required": "Ispravan IBAN je obavezan", "owner-iban-invalid": "Neispravan IBAN format. Molimo unesite ispravan IBAN.", "currency-required": "Valuta je obavezna", + "owner-revolut-profile-required": "Naziv Revolut profila je obavezan", + "owner-revolut-profile-invalid": "Neispravan format Revolut profila. Mora počinjati sa '@' i sadržavati samo slova i brojeve (npr. '@ivan123')", "validation-failed": "Validacija nije uspjela. Molimo provjerite formu i pokušajte ponovno." }, "payment-additional-notes": "VAŽNO: da bi upute za uplatu bile prikazane podstanaru, morate tu ovu opciju uključiti i u postavkama pripadajuće nekretnine."