refactor: simplify calendar and form state
Frontend verify / commits (pull_request) Successful in 29s
Frontend verify / security (pull_request) Successful in 11s
Frontend verify / verify (pull_request) Successful in 8m43s

This commit is contained in:
2026-09-28 20:23:02 +03:00
parent a7537da344
commit 94adbafa34
20 changed files with 449 additions and 392 deletions
@@ -51,6 +51,9 @@ describe("bank form input", () => {
expect(bankDateSchema.safeParse("2026-09-01").success).toBe(true);
expect(bankDateSchema.safeParse("2026-09-02").success).toBe(false);
expect(bankDateSchema.safeParse("2026-02-30").success).toBe(false);
expect(bankDateSchema.safeParse("0000-01-01").success).toBe(false);
expect(bankDateSchema.safeParse("0001-01-01").success).toBe(true);
expect(bankDateSchema.safeParse("0099-12-31").success).toBe(true);
});
});
@@ -1,3 +1,5 @@
import { moscowDate } from "@/shared/lib";
const DECIMAL_PART_COUNT = 2;
const CENTS_PRECISION = 2;
@@ -21,12 +23,7 @@ function bankMonth(value: null | string) {
}
function bankToday() {
return new Intl.DateTimeFormat("en-CA", {
day: "2-digit",
month: "2-digit",
timeZone: "Europe/Moscow",
year: "numeric",
}).format(new Date());
return moscowDate(new Date());
}
function moneyCents(value: string): bigint | null {
+2 -5
View File
@@ -1,9 +1,9 @@
import { z } from "zod";
import { validationMessage } from "@/shared/i18n";
import { calendarDate } from "@/shared/lib";
import { bankToday, moneyCents } from "./form-validation";
const ISO_DATE_LENGTH = 10;
const MAX_CARD_NAME_LENGTH = 100;
const MIN_BALANCE_KOPECKS = -9_223_372_036_854_775_808n;
const MAX_BALANCE_KOPECKS = 9_223_372_036_854_775_807n;
@@ -34,11 +34,8 @@ const bankDateSchema = z
.string()
.refine(
value =>
/^\d{4}-\d{2}-\d{2}$/.test(value)
calendarDate.safeParse(value).success
&& value >= "0001-01-01"
&& !Number.isNaN(Date.parse(`${value}T00:00:00Z`))
&& new Date(`${value}T00:00:00Z`).toISOString().slice(0, ISO_DATE_LENGTH)
=== value
&& value <= bankToday(),
{ error: validationMessage("bank.validation.date") },
);