refactor: derive payment-system options from schema tuple (#58)
This commit is contained in:
@@ -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,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user