Files
frontend/src/entities/bank-card/ui/BankCardForm/BankCardFields.vm.ts
T
codex-bot e67c47b102
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 12s
Frontend verify / verify (push) Successful in 7m56s
refactor: derive payment-system options from schema tuple (#58) (#75)
2026-10-13 21:05:07 +03:00

38 lines
1.0 KiB
TypeScript

import { useController, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { type BankCardValues, paymentSystemValues } from "../../model/form.schema";
import { bankDateField } from "../bankDateField";
function useBankCardFieldsVm() {
const {
control,
formState: { errors },
register,
} = useFormContext<BankCardValues>();
const { t } = useTranslation();
const { field: openingDateField } = useController({ control, name: "openingDate" });
const { field: paymentSystemField } = useController({ control, name: "paymentSystem" });
const paymentSystems = paymentSystemValues.map(value => ({
label: t(`bank.paymentSystems.${value}`),
value,
}));
const onPaymentSystemChange = (value: null | string) =>
paymentSystemField.onChange(value ?? "");
return {
errors,
onPaymentSystemChange,
openingDate: { ...openingDateField, ...bankDateField(openingDateField) },
paymentSystemField,
paymentSystems,
register,
t,
};
}
export { useBankCardFieldsVm };