refactor: derive payment-system options from schema tuple (#58) #75

Merged
codex-bot merged 1 commits from refactor/58-payment-system-tuple into develop 2026-10-13 21:05:08 +03:00
2 changed files with 5 additions and 4 deletions
Showing only changes of commit 001ad2e723 - Show all commits
+3 -1
View File
@@ -6,6 +6,7 @@ import { calendarDate } from "@/shared/lib";
import { bankToday } from "./form-validation";
import { moneyCents } from "./money";
const MAX_CARD_NAME_LENGTH = 100;
const paymentSystemValues = ["mir", "visa", "mastercard"] as const;
const MIN_BALANCE_KOPECKS = -9_223_372_036_854_775_808n;
const MAX_BALANCE_KOPECKS = 9_223_372_036_854_775_807n;
@@ -63,7 +64,7 @@ const bankCardSchema = z.object({
openingBalance: moneySchema,
openingDate: bankDateSchema,
paymentSystem: z
.enum(["", "mir", "visa", "mastercard"], {
.enum(["", ...paymentSystemValues], {
error: validationMessage("bank.validation.paymentSystem"),
})
.optional(),
@@ -75,5 +76,6 @@ export {
bankCardSchema,
type BankCardValues,
bankDateSchema,
paymentSystemValues,
positiveMoneySchema,
};
@@ -1,8 +1,7 @@
import { useController, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
import type { BankCardValues } from "../../model/form.schema";
import { type BankCardValues, paymentSystemValues } from "../../model/form.schema";
import { bankDateField } from "../bankDateField";
function useBankCardFieldsVm() {
@@ -16,7 +15,7 @@ function useBankCardFieldsVm() {
const { field: openingDateField } = useController({ control, name: "openingDate" });
const { field: paymentSystemField } = useController({ control, name: "paymentSystem" });
const paymentSystems = ["mir", "visa", "mastercard"].map(value => ({
const paymentSystems = paymentSystemValues.map(value => ({
label: t(`bank.paymentSystems.${value}`),
value,
}));