Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24d332e063 | ||
|
|
aba4cf1ce8 | ||
|
|
cf21a5bd17 |
@@ -126,7 +126,9 @@ describe("AppRoutes", () => {
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Вход" }));
|
||||
await screen.findByRole("heading", { name: "Добавьте первую карту" });
|
||||
expect(screen.getByLabelText("Месяц")).toHaveTextContent("August 2026");
|
||||
expect(screen.getByLabelText("Период")).toHaveTextContent(
|
||||
"01.08.2026 – 31.08.2026",
|
||||
);
|
||||
expect(document.title).toBe("Карты — WealthLedger");
|
||||
});
|
||||
|
||||
|
||||
@@ -14,15 +14,16 @@ export {
|
||||
bankDateInputValue,
|
||||
bankDateSchema,
|
||||
bankMoneyValue,
|
||||
bankMonth,
|
||||
bankToday,
|
||||
moneyCents,
|
||||
positiveMoneySchema,
|
||||
} from "./model/form-validation";
|
||||
export { bankPeriod } from "./model/period";
|
||||
export { BankCardFace } from "./ui/BankCardFace";
|
||||
export { BankCardForm } from "./ui/BankCardForm";
|
||||
export { BankFeedback } from "./ui/BankFeedback";
|
||||
export { BankOperationIcon } from "./ui/BankOperationIcon";
|
||||
export { BankPeriodPicker } from "./ui/BankPeriodPicker";
|
||||
export { BankSummaryView } from "./ui/BankSummary.view";
|
||||
export { CategoryManager } from "./ui/CategoryManager";
|
||||
export { useBankFormFocus } from "./ui/useBankFormFocus";
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import dayjs from "dayjs";
|
||||
import { z } from "zod";
|
||||
import { bankMonth } from "./form-validation";
|
||||
|
||||
const calendarDate = z.string().date();
|
||||
function bankPeriod(params: URLSearchParams) {
|
||||
const month = bankMonth(params.get("month"));
|
||||
const from = params.get("from");
|
||||
const to = params.get("to");
|
||||
return from &&
|
||||
to &&
|
||||
calendarDate.safeParse(from).success &&
|
||||
calendarDate.safeParse(to).success &&
|
||||
from >= "0001-01-01" &&
|
||||
from <= to
|
||||
? { from, to }
|
||||
: {
|
||||
from: `${month}-01`,
|
||||
to: dayjs(`${month}-01`).endOf("month").format("YYYY-MM-DD"),
|
||||
};
|
||||
}
|
||||
|
||||
export { bankPeriod };
|
||||
@@ -39,6 +39,12 @@ function setup(value: BankCard) {
|
||||
return close;
|
||||
}
|
||||
describe("BankCardForm", () => {
|
||||
it("waits for the exit transition before notifying the parent", async () => {
|
||||
const close = setup(card);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Отмена" }));
|
||||
expect(close).not.toHaveBeenCalled();
|
||||
await waitFor(() => expect(close).toHaveBeenCalledTimes(1));
|
||||
});
|
||||
it("clears optional metadata on archive while omitting protected financial fields", async () => {
|
||||
const close = setup({ ...card, archivedAt: "2026-09-01" });
|
||||
expect(screen.getByLabelText(/Начальный остаток/)).toHaveAttribute(
|
||||
|
||||
@@ -20,6 +20,7 @@ import { useBankFormFocus } from "./useBankFormFocus";
|
||||
type BankCardFormProps = { card?: BankCard; onClose: () => void };
|
||||
const BankCardForm: FC<BankCardFormProps> = (props) => {
|
||||
useBankFormFocus();
|
||||
const [opened, setOpened] = useState(true);
|
||||
const { t } = useTranslation();
|
||||
const [intent] = useState(() => crypto.randomUUID());
|
||||
const [version, setVersion] = useState(props.card?.version ?? 1);
|
||||
@@ -39,11 +40,14 @@ const BankCardForm: FC<BankCardFormProps> = (props) => {
|
||||
},
|
||||
});
|
||||
const pending =
|
||||
methods.formState.isSubmitting || (fresh.isFetching && Boolean(error));
|
||||
!opened ||
|
||||
methods.formState.isSubmitting ||
|
||||
(fresh.isFetching && Boolean(error));
|
||||
return (
|
||||
<Modal
|
||||
opened
|
||||
onClose={() => !pending && props.onClose()}
|
||||
opened={opened}
|
||||
onExitTransitionEnd={props.onClose}
|
||||
onClose={() => !pending && setOpened(false)}
|
||||
title={t(props.card ? "bank.editCard" : "bank.addCard")}
|
||||
closeButtonProps={{ "aria-label": t("bank.close"), disabled: pending }}
|
||||
closeOnClickOutside={!pending}
|
||||
@@ -82,7 +86,7 @@ const BankCardForm: FC<BankCardFormProps> = (props) => {
|
||||
...metadata,
|
||||
...financial,
|
||||
});
|
||||
props.onClose();
|
||||
setOpened(false);
|
||||
} catch (failure) {
|
||||
setError(failure);
|
||||
}
|
||||
@@ -132,7 +136,7 @@ const BankCardForm: FC<BankCardFormProps> = (props) => {
|
||||
<Button type="submit" loading={pending}>
|
||||
{t("bank.save")}
|
||||
</Button>
|
||||
<Button variant="default" onClick={props.onClose}>
|
||||
<Button variant="default" onClick={() => setOpened(false)}>
|
||||
{t("bank.cancel")}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import { type FC, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type BankPeriodPickerProps = {
|
||||
period: { from: string; to: string };
|
||||
onChange: (value: [string | null, string | null]) => void;
|
||||
};
|
||||
const BankPeriodPicker: FC<BankPeriodPickerProps> = (props) => {
|
||||
const { period, onChange } = props;
|
||||
const { t } = useTranslation();
|
||||
const scope = `${period.from}-${period.to}`;
|
||||
const [draft, setDraft] = useState<{
|
||||
scope: string;
|
||||
value: [string | null, string | null];
|
||||
}>();
|
||||
const value: [string | null, string | null] =
|
||||
draft?.scope === scope ? draft.value : [period.from, period.to];
|
||||
return (
|
||||
<DatePickerInput
|
||||
type="range"
|
||||
allowSingleDateInRange
|
||||
label={t("bank.period")}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
value={value}
|
||||
onChange={(next) => {
|
||||
setDraft({ scope, value: next });
|
||||
onChange(next);
|
||||
}}
|
||||
popoverProps={{
|
||||
returnFocus: true,
|
||||
middlewares: { shift: { crossAxis: true } },
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export { BankPeriodPicker };
|
||||
@@ -53,6 +53,7 @@ const CategoryFields: FC = () => {
|
||||
};
|
||||
const CategoryManager: FC<CategoryManagerProps> = (props) => {
|
||||
useBankFormFocus();
|
||||
const [opened, setOpened] = useState(true);
|
||||
const { t } = useTranslation();
|
||||
const categories = useBankCategories();
|
||||
const mutation = useBankMutations();
|
||||
@@ -83,11 +84,12 @@ const CategoryManager: FC<CategoryManagerProps> = (props) => {
|
||||
),
|
||||
defaultValues: { name: "" },
|
||||
});
|
||||
const pending = methods.formState.isSubmitting;
|
||||
const pending = !opened || methods.formState.isSubmitting;
|
||||
return (
|
||||
<Modal
|
||||
opened
|
||||
onClose={() => !pending && props.onClose()}
|
||||
opened={opened}
|
||||
onExitTransitionEnd={props.onClose}
|
||||
onClose={() => !pending && setOpened(false)}
|
||||
title={t("bank.categories")}
|
||||
closeOnClickOutside={!pending}
|
||||
closeOnEscape={!pending}
|
||||
@@ -205,7 +207,7 @@ const CategoryManager: FC<CategoryManagerProps> = (props) => {
|
||||
{t("bank.cancel")}
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="default" onClick={props.onClose}>
|
||||
<Button variant="default" onClick={() => setOpened(false)}>
|
||||
{t("bank.close")}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
@@ -55,7 +55,7 @@ describe("Upcoming event date filters", () => {
|
||||
);
|
||||
render(
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
<MantineProvider>
|
||||
<MantineProvider env="test">
|
||||
<MemoryRouter
|
||||
initialEntries={[
|
||||
`/accounts/${accountId}/events?from=2099-02-01&to=2099-02-28`,
|
||||
@@ -72,31 +72,37 @@ describe("Upcoming event date filters", () => {
|
||||
</MantineProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
const from = await screen.findByLabelText("С");
|
||||
const to = screen.getByLabelText("По");
|
||||
expect(from).toHaveValue("01.02.2099");
|
||||
expect(to).toHaveValue("28.02.2099");
|
||||
const from = await screen.findByLabelText("Период");
|
||||
expect(from).toHaveTextContent("01.02.2099 – 28.02.2099");
|
||||
expect(screen.getByRole("button", { name: "Применить" })).toBeDisabled();
|
||||
expect(searches).toEqual(["?from=2099-02-01&to=2099-02-28"]);
|
||||
fireEvent.change(from, { target: { value: "10.02.2099" } });
|
||||
fireEvent.blur(from);
|
||||
fireEvent.click(from);
|
||||
fireEvent.click(
|
||||
await screen.findByRole("button", { name: /10 February 2099/i }),
|
||||
);
|
||||
fireEvent.click(
|
||||
await screen.findByRole("button", { name: /28 February 2099/i }),
|
||||
);
|
||||
expect(searches).toHaveLength(1);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Применить" }));
|
||||
await waitFor(() =>
|
||||
expect(searches.at(-1)).toBe("?from=2099-02-10&to=2099-02-28"),
|
||||
);
|
||||
expect(await screen.findByLabelText("С")).toHaveValue("10.02.2099");
|
||||
expect(await screen.findByLabelText("Период")).toHaveTextContent(
|
||||
"10.02.2099 – 28.02.2099",
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "History back" }));
|
||||
await waitFor(() =>
|
||||
expect(screen.getByLabelText("С")).toHaveValue("01.02.2099"),
|
||||
expect(screen.getByLabelText("Период")).toHaveTextContent(
|
||||
"01.02.2099 – 28.02.2099",
|
||||
),
|
||||
);
|
||||
expect(screen.getByLabelText("URL")).toHaveTextContent(
|
||||
"?from=2099-02-01&to=2099-02-28",
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Сбросить" }));
|
||||
await waitFor(() => expect(searches.at(-1)).toBe(""));
|
||||
expect(await screen.findByLabelText("С")).toHaveValue("");
|
||||
expect(screen.getByLabelText("По")).toHaveValue("");
|
||||
expect(await screen.findByLabelText("Период")).toHaveTextContent("");
|
||||
expect(screen.getByRole("button", { name: "Применить" })).toBeDisabled();
|
||||
expect(
|
||||
screen.getByText("За выбранный период событий не найдено"),
|
||||
|
||||
@@ -7,22 +7,13 @@ import {
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { DateInput } from "@mantine/dates";
|
||||
import dayjs from "dayjs";
|
||||
import customParseFormat from "dayjs/plugin/customParseFormat";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import type { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { BrokerageEventCard } from "@/entities/brokerage-event";
|
||||
import type { AccountEventsPageViewModel } from "../AccountEventsPage.vm";
|
||||
import { AccountEventsPageEmpty } from "./AccountEventsPageEmpty.view";
|
||||
|
||||
dayjs.extend(customParseFormat);
|
||||
|
||||
const parseDate = (value: string) => {
|
||||
const date = dayjs(value, "DD.MM.YYYY", true);
|
||||
return date.isValid() ? date.format("YYYY-MM-DD") : null;
|
||||
};
|
||||
|
||||
type AccountEventsPageLoadedProps = Extract<
|
||||
AccountEventsPageViewModel,
|
||||
{ state: "loaded" }
|
||||
@@ -46,25 +37,22 @@ const AccountEventsPageLoaded: FC<AccountEventsPageLoadedProps> = (props) => {
|
||||
) : null}
|
||||
<Text c="dimmed">{t("events.hint")}</Text>
|
||||
<Group align="end">
|
||||
<DateInput
|
||||
label={t("ledger.from")}
|
||||
value={props.draftFrom}
|
||||
onChange={props.onDraftFromChange}
|
||||
maxDate={props.draftTo ?? undefined}
|
||||
<DatePickerInput
|
||||
type="range"
|
||||
allowSingleDateInRange
|
||||
clearable
|
||||
clearButtonProps={{ "aria-label": t("ledger.clearPeriod") }}
|
||||
label={t("ledger.period")}
|
||||
value={[props.draftFrom, props.draftTo]}
|
||||
onChange={([from, to]) => {
|
||||
props.onDraftFromChange(from);
|
||||
props.onDraftToChange(to);
|
||||
}}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
dateParser={parseDate}
|
||||
allowDeselect
|
||||
popoverProps={{ middlewares: { shift: { crossAxis: true } } }}
|
||||
/>
|
||||
<DateInput
|
||||
label={t("ledger.to")}
|
||||
value={props.draftTo}
|
||||
onChange={props.onDraftToChange}
|
||||
minDate={props.draftFrom ?? undefined}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
dateParser={parseDate}
|
||||
allowDeselect
|
||||
popoverProps={{ middlewares: { shift: { crossAxis: true } } }}
|
||||
popoverProps={{
|
||||
returnFocus: true,
|
||||
middlewares: { shift: { crossAxis: true } },
|
||||
}}
|
||||
/>
|
||||
</Group>
|
||||
<Group>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
.fields {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: var(--mantine-spacing-sm);
|
||||
}
|
||||
|
||||
|
||||
@@ -523,12 +523,10 @@ const LocationProbe: FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
function inputDate(label: string, value: string) {
|
||||
const field = screen.getByLabelText(label);
|
||||
fireEvent.focus(field);
|
||||
fireEvent.input(field, { target: { value } });
|
||||
fireEvent.blur(field);
|
||||
return field;
|
||||
function selectPeriod() {
|
||||
fireEvent.click(screen.getByLabelText("Период"));
|
||||
fireEvent.click(screen.getByRole("button", { name: /^2 августа 2026$/i }));
|
||||
fireEvent.click(screen.getByRole("button", { name: /^27 августа 2026$/i }));
|
||||
}
|
||||
|
||||
function respondWithRequestedPeriod(requests: string[]) {
|
||||
@@ -557,9 +555,10 @@ describe("income period and snapshot boundary", () => {
|
||||
const requests: string[] = [];
|
||||
respondWithRequestedPeriod(requests);
|
||||
renderPage();
|
||||
expect(await screen.findByLabelText("С")).toHaveValue("01.08.2026");
|
||||
expect(screen.getByLabelText("По")).toHaveValue("27.08.2026");
|
||||
inputDate("С", "02.08.2026");
|
||||
expect(await screen.findByLabelText("Период")).toHaveTextContent(
|
||||
"01.08.2026 – 27.08.2026",
|
||||
);
|
||||
selectPeriod();
|
||||
expect(requests).toHaveLength(1);
|
||||
expect(
|
||||
screen.queryByText("2026-08-01 — 2026-08-27"),
|
||||
@@ -573,66 +572,37 @@ describe("income period and snapshot boundary", () => {
|
||||
.closest("form") as HTMLFormElement,
|
||||
);
|
||||
await waitFor(() => expect(requests).toHaveLength(2));
|
||||
expect(await screen.findByLabelText("С")).toHaveValue("02.08.2026");
|
||||
expect(await screen.findByLabelText("Период")).toHaveTextContent(
|
||||
"02.08.2026 – 27.08.2026",
|
||||
);
|
||||
expect(screen.getByTestId("location")).toHaveTextContent(
|
||||
"from=2026-08-02&to=2026-08-27",
|
||||
);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Back" }));
|
||||
await waitFor(() =>
|
||||
expect(screen.getByLabelText("С")).toHaveValue("01.08.2026"),
|
||||
expect(screen.getByLabelText("Период")).toHaveTextContent(
|
||||
"01.08.2026 – 27.08.2026",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["С", "", "Введите существующую дату"],
|
||||
["С", "31.02.2026", "Введите существующую дату"],
|
||||
["По", "29.02.2026", "Введите существующую дату"],
|
||||
["По", "2026-08-02", "Введите существующую дату"],
|
||||
["С", "01.01.2099", "Дата не может быть позже"],
|
||||
["По", "01.01.2099", "Дата не может быть позже"],
|
||||
["По", "31.07.2026", "Укажите корректный период"],
|
||||
])(
|
||||
"rejects visible %s=%s without replacing data or URL",
|
||||
async (label, value, error) => {
|
||||
const requests: string[] = [];
|
||||
respondWithRequestedPeriod(requests);
|
||||
renderPage();
|
||||
await screen.findByLabelText("С");
|
||||
const field = inputDate(label, value);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Применить" }));
|
||||
expect(await screen.findByText(new RegExp(error))).toBeInTheDocument();
|
||||
expect(field).toHaveValue(value);
|
||||
expect(field).toHaveAttribute("aria-invalid", "true");
|
||||
await waitFor(() => expect(field).toHaveFocus());
|
||||
expect(requests).toHaveLength(1);
|
||||
expect(screen.getByTestId("location")).toHaveTextContent(
|
||||
"from=2026-08-01&to=2026-08-27",
|
||||
);
|
||||
expect(
|
||||
screen.queryByText("2026-08-01 — 2026-08-27"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("region", { name: "Выплаты" })).toBeVisible();
|
||||
},
|
||||
);
|
||||
|
||||
it("replaces invalid raw text with a calendar choice and closes the calendar with Escape", async () => {
|
||||
respondWithRequestedPeriod([]);
|
||||
it("rejects an incomplete range without replacing the URL and allows a single day", async () => {
|
||||
const requests: string[] = [];
|
||||
respondWithRequestedPeriod(requests);
|
||||
renderPage();
|
||||
const from = await screen.findByLabelText("С");
|
||||
act(() => from.focus());
|
||||
fireEvent.input(from, { target: { value: "invalid" } });
|
||||
// The selected month stays available even when the visible draft is invalid.
|
||||
const day = await screen.findByRole("button", {
|
||||
name: /^2 августа 2026$/i,
|
||||
});
|
||||
fireEvent.click(day);
|
||||
expect(from).toHaveValue("02.08.2026");
|
||||
act(() => from.focus());
|
||||
fireEvent.keyDown(from, { key: "Escape" });
|
||||
const period = await screen.findByLabelText("Период");
|
||||
fireEvent.click(period);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^2 августа 2026$/i }));
|
||||
fireEvent.keyDown(period, { key: "Escape" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Применить" }));
|
||||
expect(await screen.findByText(/Введите существующую дату/)).toBeVisible();
|
||||
expect(requests).toHaveLength(1);
|
||||
if (period.getAttribute("aria-expanded") !== "true")
|
||||
fireEvent.click(period);
|
||||
fireEvent.click(screen.getByRole("button", { name: /^2 августа 2026$/i }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Применить" }));
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.queryByRole("button", { name: /^2 августа 2026$/i }),
|
||||
).not.toBeInTheDocument(),
|
||||
expect(requests.at(-1)).toBe("?from=2026-08-02&to=2026-08-02"),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -642,19 +612,23 @@ describe("income period and snapshot boundary", () => {
|
||||
const requests: string[] = [];
|
||||
respondWithRequestedPeriod(requests);
|
||||
renderPage("");
|
||||
expect(await screen.findByLabelText("С")).toHaveValue("01.09.2026");
|
||||
expect(screen.getByLabelText("По")).toHaveValue("01.09.2026");
|
||||
inputDate("С", "wrong");
|
||||
expect(await screen.findByLabelText("Период")).toHaveTextContent(
|
||||
"01.09.2026 – 01.09.2026",
|
||||
);
|
||||
fireEvent.click(screen.getByLabelText("Период"));
|
||||
fireEvent.click(screen.getByRole("button", { name: /^1 сентября 2026$/i }));
|
||||
fireEvent.keyDown(screen.getByLabelText("Период"), { key: "Escape" });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Применить" }));
|
||||
await screen.findByText(/Введите существующую дату/);
|
||||
fireEvent.click(screen.getByRole("button", { name: "Сбросить" }));
|
||||
await waitFor(() =>
|
||||
expect(screen.getByLabelText("С")).toHaveValue("01.09.2026"),
|
||||
expect(screen.getByLabelText("Период")).toHaveTextContent(
|
||||
"01.09.2026 – 01.09.2026",
|
||||
),
|
||||
);
|
||||
expect(
|
||||
screen.queryByText(/Введите существующую дату/),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByLabelText("По")).toHaveValue("01.09.2026");
|
||||
expect(screen.getByTestId("location")).toHaveTextContent(
|
||||
"from=2026-09-01&to=2026-09-01",
|
||||
);
|
||||
@@ -664,8 +638,8 @@ describe("income period and snapshot boundary", () => {
|
||||
it("keeps valid data and draft during refetch, warns on failure and retries", async () => {
|
||||
respondWithRequestedPeriod([]);
|
||||
const { queryClient } = renderPage();
|
||||
await screen.findByLabelText("С");
|
||||
inputDate("С", "02.08.2026");
|
||||
await screen.findByLabelText("Период");
|
||||
selectPeriod();
|
||||
let release!: () => void;
|
||||
const pending = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
@@ -686,7 +660,9 @@ describe("income period and snapshot boundary", () => {
|
||||
await screen.findByRole("status", { name: "Обновляем пассивный доход" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByRole("region", { name: "Выплаты" })).toBeVisible();
|
||||
expect(screen.getByLabelText("С")).toHaveValue("02.08.2026");
|
||||
expect(screen.getByLabelText("Период")).toHaveTextContent(
|
||||
"02.08.2026 – 27.08.2026",
|
||||
);
|
||||
release();
|
||||
expect(
|
||||
await screen.findByText(/Показан последний загруженный результат/),
|
||||
@@ -699,13 +675,15 @@ describe("income period and snapshot boundary", () => {
|
||||
screen.queryByText(/Показан последний загруженный результат/),
|
||||
).not.toBeInTheDocument(),
|
||||
);
|
||||
expect(screen.getByLabelText("С")).toHaveValue("02.08.2026");
|
||||
expect(screen.getByLabelText("Период")).toHaveTextContent(
|
||||
"02.08.2026 – 27.08.2026",
|
||||
);
|
||||
});
|
||||
|
||||
it("shows busy skeleton for a new uncached period without relabeling the previous result", async () => {
|
||||
respondWithRequestedPeriod([]);
|
||||
renderPage();
|
||||
await screen.findByLabelText("С");
|
||||
await screen.findByLabelText("Период");
|
||||
let release!: () => void;
|
||||
const pending = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
@@ -722,7 +700,7 @@ describe("income period and snapshot boundary", () => {
|
||||
},
|
||||
),
|
||||
);
|
||||
inputDate("С", "02.08.2026");
|
||||
selectPeriod();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Применить" }));
|
||||
expect(
|
||||
await screen.findByRole("status", { name: "Загрузка" }),
|
||||
@@ -734,7 +712,9 @@ describe("income period and snapshot boundary", () => {
|
||||
screen.queryByText("2026-08-02 — 2026-08-27"),
|
||||
).not.toBeInTheDocument();
|
||||
release();
|
||||
expect(await screen.findByLabelText("С")).toHaveValue("02.08.2026");
|
||||
expect(await screen.findByLabelText("Период")).toHaveTextContent(
|
||||
"02.08.2026 – 27.08.2026",
|
||||
);
|
||||
});
|
||||
|
||||
it("shows one flat payment card per entry in server order without currency or instrument groups", () => {
|
||||
|
||||
@@ -99,7 +99,7 @@ const useAccountIncomePageViewModel = (
|
||||
const onReset = () => {
|
||||
const next = defaultPeriod();
|
||||
form.reset(draftPeriod(next));
|
||||
// DateInput retains raw text while its calendar is open; reset that UI state too.
|
||||
// Reset the open calendar along with the form.
|
||||
setFormRevision((revision) => revision + 1);
|
||||
setSearchParams(next, { replace: true });
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Button, Paper, Stack, Text } from "@mantine/core";
|
||||
import { DateInput } from "@mantine/dates";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import type { FC, FormEventHandler } from "react";
|
||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||
import { useController, useFormContext, useWatch } from "react-hook-form";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import classes from "../AccountIncomePage.module.css";
|
||||
import {
|
||||
@@ -22,6 +22,8 @@ const IncomePeriodForm: FC<IncomePeriodFormProps> = (props) => {
|
||||
control,
|
||||
formState: { isSubmitting },
|
||||
} = useFormContext<IncomeForm>();
|
||||
const fromField = useController({ control, name: "from" });
|
||||
const toField = useController({ control, name: "to" });
|
||||
const [from, to] = useWatch({ control, name: ["from", "to"] });
|
||||
const today = moscowDate(new Date());
|
||||
const start = parseDraftDate(from);
|
||||
@@ -37,39 +39,34 @@ const IncomePeriodForm: FC<IncomePeriodFormProps> = (props) => {
|
||||
<Stack gap="sm">
|
||||
<Text fw={700}>{t("income.period")}</Text>
|
||||
<div className={classes.fields}>
|
||||
{(["from", "to"] as const).map((name) => (
|
||||
<Controller
|
||||
key={name}
|
||||
name={name}
|
||||
control={control}
|
||||
render={({ field, fieldState }) => (
|
||||
<DateInput
|
||||
ref={field.ref}
|
||||
label={t(`income.${name}`)}
|
||||
placeholder={t("income.datePlaceholder")}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
value={parseDraftDate(field.value)}
|
||||
dateParser={parseDraftDate}
|
||||
fixOnBlur={false}
|
||||
popoverProps={{ middlewares: { shift: { crossAxis: true } } }}
|
||||
onInput={(event) => field.onChange(event.currentTarget.value)}
|
||||
onChange={(value) =>
|
||||
field.onChange(value ? formatDraftDate(value) : "")
|
||||
}
|
||||
onBlur={(event) => {
|
||||
field.onChange(event.currentTarget.value);
|
||||
field.onBlur();
|
||||
}}
|
||||
minDate={
|
||||
name === "to" && start && start <= today ? start : undefined
|
||||
}
|
||||
maxDate={name === "from" && end && end <= today ? end : today}
|
||||
error={fieldState.error?.message}
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
<DatePickerInput
|
||||
type="range"
|
||||
allowSingleDateInRange
|
||||
clearable
|
||||
clearButtonProps={{ "aria-label": t("ledger.clearPeriod") }}
|
||||
ref={fromField.field.ref}
|
||||
label={t("income.period")}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
value={[start, end]}
|
||||
onChange={([from, to]) => {
|
||||
fromField.field.onChange(from ? formatDraftDate(from) : "");
|
||||
toField.field.onChange(to ? formatDraftDate(to) : "");
|
||||
}}
|
||||
onBlur={() => {
|
||||
fromField.field.onBlur();
|
||||
toField.field.onBlur();
|
||||
}}
|
||||
maxDate={today}
|
||||
error={
|
||||
fromField.fieldState.error?.message ??
|
||||
toField.fieldState.error?.message
|
||||
}
|
||||
disabled={isSubmitting}
|
||||
popoverProps={{
|
||||
returnFocus: true,
|
||||
middlewares: { shift: { crossAxis: true } },
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className={classes.actions}>
|
||||
<Button type="submit" loading={isSubmitting}>
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
Stack,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { DateInput } from "@mantine/dates";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import type { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
@@ -25,21 +25,6 @@ type AccountOperationsPageLoadedProps = Extract<
|
||||
|
||||
const operationCategorySet = new Set<string>(operationCategories);
|
||||
|
||||
function toDateValue(value: string | null): Date | null {
|
||||
if (!value) return null;
|
||||
const [year, month, day] = value.split("-").map(Number);
|
||||
return new Date(year, month - 1, day);
|
||||
}
|
||||
|
||||
function fromDateValue(value: Date | string | null): string | null {
|
||||
if (!value) return null;
|
||||
if (typeof value === "string") return value;
|
||||
const year = value.getFullYear();
|
||||
const month = String(value.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(value.getDate()).padStart(2, "0");
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
function fromMultiSelectValue(value: string[]) {
|
||||
return value.filter((item): item is OperationCategory =>
|
||||
operationCategorySet.has(item),
|
||||
@@ -87,19 +72,22 @@ const AccountOperationsPageLoaded: FC<AccountOperationsPageLoadedProps> = (
|
||||
</Alert>
|
||||
) : null}
|
||||
<Group align="end">
|
||||
<DateInput
|
||||
label={t("ledger.from")}
|
||||
value={toDateValue(draftFrom)}
|
||||
onChange={(value) => onDraftFromChange(fromDateValue(value))}
|
||||
maxDate={toDateValue(draftTo) ?? undefined}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
/>
|
||||
<DateInput
|
||||
label={t("ledger.to")}
|
||||
value={toDateValue(draftTo)}
|
||||
onChange={(value) => onDraftToChange(fromDateValue(value))}
|
||||
minDate={toDateValue(draftFrom) ?? undefined}
|
||||
<DatePickerInput
|
||||
type="range"
|
||||
allowSingleDateInRange
|
||||
clearable
|
||||
clearButtonProps={{ "aria-label": t("ledger.clearPeriod") }}
|
||||
label={t("ledger.period")}
|
||||
value={[draftFrom, draftTo]}
|
||||
onChange={([from, to]) => {
|
||||
onDraftFromChange(from);
|
||||
onDraftToChange(to);
|
||||
}}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
popoverProps={{
|
||||
returnFocus: true,
|
||||
middlewares: { shift: { crossAxis: true } },
|
||||
}}
|
||||
/>
|
||||
</Group>
|
||||
<MultiSelect
|
||||
@@ -111,6 +99,7 @@ const AccountOperationsPageLoaded: FC<AccountOperationsPageLoadedProps> = (
|
||||
onDraftCategoriesChange(fromMultiSelectValue(value))
|
||||
}
|
||||
clearable
|
||||
clearButtonProps={{ "aria-label": t("ledger.clearPeriod") }}
|
||||
/>
|
||||
<Group>
|
||||
<Button onClick={onApply} disabled={!canApply}>
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
.card {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 28rem;
|
||||
}
|
||||
.cardActions {
|
||||
position: absolute;
|
||||
top: 4.5rem;
|
||||
right: clamp(1.1rem, 3vw, 1.6rem);
|
||||
padding: 4px;
|
||||
border: 1px solid var(--mantine-color-gray-3);
|
||||
border-radius: var(--mantine-radius-lg);
|
||||
background: var(--mantine-color-white);
|
||||
box-shadow: 0 3px 12px #0000001a;
|
||||
}
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.cardActions {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.card:hover .cardActions,
|
||||
.card:focus-within .cardActions {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.wrap {
|
||||
overflow-wrap: anywhere;
|
||||
min-width: 0;
|
||||
@@ -21,7 +48,21 @@
|
||||
.operations[data-pending] {
|
||||
opacity: 0.55;
|
||||
}
|
||||
@media (pointer: coarse) {
|
||||
.cardActions button {
|
||||
min-width: 36px;
|
||||
min-height: 36px;
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.cardActions {
|
||||
transition: opacity 180ms ease;
|
||||
}
|
||||
.page button {
|
||||
transition:
|
||||
background-color 180ms ease,
|
||||
color 180ms ease;
|
||||
}
|
||||
.operations {
|
||||
animation: operations-appear 200ms ease-out;
|
||||
transition: opacity 150ms ease;
|
||||
|
||||
@@ -4,60 +4,26 @@ import {
|
||||
Button,
|
||||
Group,
|
||||
Pagination,
|
||||
Paper,
|
||||
Select,
|
||||
Skeleton,
|
||||
Stack,
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import { type FC, useLayoutEffect, useRef, useState } from "react";
|
||||
import { type FC, useLayoutEffect, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import {
|
||||
BankCardFace,
|
||||
BankFeedback,
|
||||
BankOperationIcon,
|
||||
BankPeriodPicker,
|
||||
BankSummaryView,
|
||||
} from "@/entities/bank-card";
|
||||
import { EntryCard, LoadingSkeleton, StateView } from "@/shared/ui";
|
||||
import classes from "./CardPage.module.css";
|
||||
import type { CardPageVm } from "./CardPage.vm";
|
||||
|
||||
type PeriodPickerProps = {
|
||||
period: CardPageVm["period"];
|
||||
onChange: CardPageVm["setPeriod"];
|
||||
};
|
||||
const PeriodPicker: FC<PeriodPickerProps> = (props) => {
|
||||
const { period, onChange } = props;
|
||||
const { t } = useTranslation();
|
||||
const scope = `${period.from}-${period.to}`;
|
||||
const [draft, setDraft] = useState<{
|
||||
scope: string;
|
||||
value: [string | null, string | null];
|
||||
}>();
|
||||
const value: [string | null, string | null] =
|
||||
draft?.scope === scope ? draft.value : [period.from, period.to];
|
||||
return (
|
||||
<DatePickerInput
|
||||
type="range"
|
||||
allowSingleDateInRange
|
||||
label={t("bank.period")}
|
||||
valueFormat="DD.MM.YYYY"
|
||||
value={value}
|
||||
onChange={(next) => {
|
||||
setDraft({ scope, value: next });
|
||||
onChange(next);
|
||||
}}
|
||||
popoverProps={{
|
||||
returnFocus: true,
|
||||
middlewares: { shift: { crossAxis: true } },
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
type CardPageViewProps = { vm: CardPageVm };
|
||||
const CardPageView: FC<CardPageViewProps> = (props) => {
|
||||
const { vm } = props;
|
||||
@@ -124,41 +90,76 @@ const CardPageView: FC<CardPageViewProps> = (props) => {
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Stack gap="lg">
|
||||
<Paper p="md" withBorder>
|
||||
<Stack>
|
||||
<Title order={1} className={classes.wrap}>
|
||||
{card.name}
|
||||
</Title>
|
||||
<Stack gap="lg" className={classes.page}>
|
||||
<Stack>
|
||||
<Title order={1} className={classes.wrap}>
|
||||
{card.name}
|
||||
</Title>
|
||||
<div className={classes.card}>
|
||||
<BankCardFace card={card} />
|
||||
<Text c="dimmed">{t("bank.manualBalance")}</Text>
|
||||
<Group>
|
||||
<Button
|
||||
disabled={Boolean(card.archivedAt) || !vm.cards.data}
|
||||
onClick={() => vm.setOperation("new")}
|
||||
<Group gap={4} wrap="nowrap" className={classes.cardActions}>
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
size="md"
|
||||
radius="md"
|
||||
aria-label={t("bank.editCard")}
|
||||
title={t("bank.editCard")}
|
||||
onClick={() => vm.setEditingCard(true)}
|
||||
>
|
||||
{t("bank.addOperation")}
|
||||
</Button>
|
||||
<Button variant="default" onClick={() => vm.setEditingCard(true)}>
|
||||
{t("bank.editCard")}
|
||||
</Button>
|
||||
<Button
|
||||
variant="default"
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="m16 3 5 5-12 12-6 1 1-6L16 3Z M13 6l5 5" />
|
||||
</svg>
|
||||
</ActionIcon>
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
size="md"
|
||||
radius="md"
|
||||
color="red"
|
||||
aria-label={t(card.archivedAt ? "bank.restore" : "bank.archive")}
|
||||
title={t(card.archivedAt ? "bank.restore" : "bank.archive")}
|
||||
loading={vm.archivePending}
|
||||
onClick={() => void vm.toggleArchive()}
|
||||
>
|
||||
{t(card.archivedAt ? "bank.restore" : "bank.archive")}
|
||||
</Button>
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
d={
|
||||
card.archivedAt
|
||||
? "M3 3h18v4H3z M5 7v14h14V7 M12 17V10m-3 3 3-3 3 3"
|
||||
: "M3 6h18 M9 6V3h6v3 M5 6l1 15h12l1-15 M10 10v7 M14 10v7"
|
||||
}
|
||||
/>
|
||||
</svg>
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
{vm.archiveError ? (
|
||||
<BankFeedback
|
||||
error={vm.archiveError}
|
||||
retry={() => void vm.card.refetch()}
|
||||
/>
|
||||
) : null}
|
||||
{card.archivedAt && <Text>{t("bank.archiveHint")}</Text>}
|
||||
</Stack>
|
||||
</Paper>
|
||||
</div>
|
||||
{vm.archiveError ? (
|
||||
<BankFeedback
|
||||
error={vm.archiveError}
|
||||
retry={() => void vm.card.refetch()}
|
||||
/>
|
||||
) : null}
|
||||
{card.archivedAt && <Text>{t("bank.archiveHint")}</Text>}
|
||||
</Stack>
|
||||
{vm.card.isError && (
|
||||
<Group role="alert">
|
||||
<Text>{t("bank.refreshError")}</Text>
|
||||
@@ -176,7 +177,7 @@ const CardPageView: FC<CardPageViewProps> = (props) => {
|
||||
retry={() => void vm.cards.refetch()}
|
||||
/>
|
||||
)}
|
||||
<PeriodPicker period={vm.period} onChange={vm.setPeriod} />
|
||||
<BankPeriodPicker period={vm.period} onChange={vm.setPeriod} />
|
||||
<BankSummaryView
|
||||
data={vm.summary.data}
|
||||
loading={vm.summary.isLoading}
|
||||
@@ -185,7 +186,30 @@ const CardPageView: FC<CardPageViewProps> = (props) => {
|
||||
retry={() => void vm.summary.refetch()}
|
||||
/>
|
||||
<Group justify="space-between" align="end">
|
||||
<Title order={2}>{t("bank.operations")}</Title>
|
||||
<Group gap="xs">
|
||||
<Title order={2}>{t("bank.operations")}</Title>
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
size="lg"
|
||||
aria-label={t("bank.addOperation")}
|
||||
title={t("bank.addOperation")}
|
||||
disabled={Boolean(card.archivedAt) || !vm.cards.data}
|
||||
onClick={() => vm.setOperation("new")}
|
||||
>
|
||||
<svg
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M12 5v14 M5 12h14" />
|
||||
</svg>
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
<Select
|
||||
label={t("bank.pageSize")}
|
||||
value={vm.pageSize}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import dayjs from "dayjs";
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useParams, useSearchParams } from "react-router";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
type BankOperation,
|
||||
bankMonth,
|
||||
bankPeriod,
|
||||
useBankCard,
|
||||
useBankCards,
|
||||
useBankMutations,
|
||||
@@ -15,29 +13,13 @@ import {
|
||||
import { apiErrorCode } from "@/shared/api";
|
||||
import { formatDate, formatMoney } from "@/shared/lib";
|
||||
|
||||
const calendarDate = z.string().date();
|
||||
|
||||
const PAGE_SIZES = ["5", "10", "20", "50", "100", "all"];
|
||||
|
||||
function useCardPageVm() {
|
||||
const { cardId } = useParams();
|
||||
const [params, setParams] = useSearchParams();
|
||||
const { t } = useTranslation();
|
||||
const month = bankMonth(params.get("month"));
|
||||
const from = params.get("from");
|
||||
const to = params.get("to");
|
||||
const period =
|
||||
from &&
|
||||
to &&
|
||||
calendarDate.safeParse(from).success &&
|
||||
calendarDate.safeParse(to).success &&
|
||||
from >= "0001-01-01" &&
|
||||
from <= to
|
||||
? { from, to }
|
||||
: {
|
||||
from: `${month}-01`,
|
||||
to: dayjs(`${month}-01`).endOf("month").format("YYYY-MM-DD"),
|
||||
};
|
||||
const period = bankPeriod(params);
|
||||
const requestedSize = params.get("limit") ?? "10";
|
||||
const pageSize = PAGE_SIZES.includes(requestedSize) ? requestedSize : "10";
|
||||
const rawPage = Number(params.get("page") ?? 1);
|
||||
|
||||
@@ -13,6 +13,7 @@ import { formatDate, formatMoney } from "@/shared/lib";
|
||||
type DeleteOperationProps = { operation: BankOperation; onClose: () => void };
|
||||
const DeleteOperation: FC<DeleteOperationProps> = (props) => {
|
||||
useBankFormFocus();
|
||||
const [opened, setOpened] = useState(true);
|
||||
const { t } = useTranslation();
|
||||
const [record, setRecord] = useState(props.operation);
|
||||
const [latest, setLatest] = useState<BankOperation>();
|
||||
@@ -20,11 +21,14 @@ const DeleteOperation: FC<DeleteOperationProps> = (props) => {
|
||||
const query = useBankOperation(record.id);
|
||||
const { deleteOperation } = useBankMutations();
|
||||
const pending =
|
||||
deleteOperation.isPending || (query.isFetching && Boolean(error));
|
||||
!opened ||
|
||||
deleteOperation.isPending ||
|
||||
(query.isFetching && Boolean(error));
|
||||
return (
|
||||
<Modal
|
||||
opened
|
||||
onClose={() => !pending && props.onClose()}
|
||||
opened={opened}
|
||||
onExitTransitionEnd={props.onClose}
|
||||
onClose={() => !pending && setOpened(false)}
|
||||
title={t("bank.deleteTitle")}
|
||||
closeOnEscape={!pending}
|
||||
closeOnClickOutside={!pending}
|
||||
@@ -91,7 +95,7 @@ const DeleteOperation: FC<DeleteOperationProps> = (props) => {
|
||||
id: record.id,
|
||||
version: record.version,
|
||||
});
|
||||
props.onClose();
|
||||
setOpened(false);
|
||||
} catch (failure) {
|
||||
setError(failure);
|
||||
}
|
||||
@@ -99,7 +103,11 @@ const DeleteOperation: FC<DeleteOperationProps> = (props) => {
|
||||
>
|
||||
{t("bank.delete")}
|
||||
</Button>
|
||||
<Button variant="default" disabled={pending} onClick={props.onClose}>
|
||||
<Button
|
||||
variant="default"
|
||||
disabled={pending}
|
||||
onClick={() => setOpened(false)}
|
||||
>
|
||||
{t("bank.cancel")}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
@@ -47,6 +47,7 @@ type OperationFormProps = {
|
||||
};
|
||||
const OperationForm: FC<OperationFormProps> = (props) => {
|
||||
useBankFormFocus();
|
||||
const [opened, setOpened] = useState(true);
|
||||
const { t } = useTranslation();
|
||||
const [categoriesOpen, setCategoriesOpen] = useState(false);
|
||||
const [version, setVersion] = useState(props.operation?.version ?? 1);
|
||||
@@ -164,15 +165,16 @@ const OperationForm: FC<OperationFormProps> = (props) => {
|
||||
{ page: sourcePage },
|
||||
);
|
||||
const source = methods.watch("cardId");
|
||||
const pending = methods.formState.isSubmitting;
|
||||
const pending = !opened || methods.formState.isSubmitting;
|
||||
const options = props.cards
|
||||
.filter((c) => !c.archivedAt)
|
||||
.map((c) => ({ value: c.id, label: c.name }));
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
opened
|
||||
onClose={() => !pending && !categoriesOpen && props.onClose()}
|
||||
opened={opened}
|
||||
onExitTransitionEnd={props.onClose}
|
||||
onClose={() => !pending && !categoriesOpen && setOpened(false)}
|
||||
title={t(props.operation ? "bank.editOperation" : "bank.addOperation")}
|
||||
closeOnEscape={!pending && !categoriesOpen}
|
||||
closeOnClickOutside={!pending && !categoriesOpen}
|
||||
@@ -217,7 +219,7 @@ const OperationForm: FC<OperationFormProps> = (props) => {
|
||||
id: intent,
|
||||
...body,
|
||||
});
|
||||
props.onClose();
|
||||
setOpened(false);
|
||||
} catch (failure) {
|
||||
setError(failure);
|
||||
}
|
||||
@@ -392,7 +394,7 @@ const OperationForm: FC<OperationFormProps> = (props) => {
|
||||
>
|
||||
{t("bank.save")}
|
||||
</Button>
|
||||
<Button variant="default" onClick={props.onClose}>
|
||||
<Button variant="default" onClick={() => setOpened(false)}>
|
||||
{t("bank.cancel")}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
@@ -42,7 +42,7 @@ function renderCards(fail = false, categoryFail = false) {
|
||||
);
|
||||
return render(
|
||||
<QueryClientProvider client={createTestQueryClient()}>
|
||||
<MantineProvider>
|
||||
<MantineProvider env="test">
|
||||
<MemoryRouter initialEntries={["/cards?month=2026-09"]}>
|
||||
<CardsPage />
|
||||
</MemoryRouter>
|
||||
@@ -138,10 +138,42 @@ describe("CardsPage", () => {
|
||||
fireEvent.click(screen.getByLabelText("Показать архив"));
|
||||
await screen.findByText("Запасная");
|
||||
expect(requests).toContain("?includeArchived=true");
|
||||
expect(screen.getByLabelText("Месяц")).toHaveTextContent("September 2026");
|
||||
expect(screen.getByLabelText("Период")).toHaveTextContent(
|
||||
"01.09.2026 – 30.09.2026",
|
||||
);
|
||||
expect(screen.getByRole("link", { name: /Запасная/ })).toHaveAttribute(
|
||||
"href",
|
||||
"/cards/demo?month=2026-09",
|
||||
"/cards/demo?from=2026-09-01&to=2026-09-30",
|
||||
);
|
||||
});
|
||||
it("applies a completed custom period to the summary", async () => {
|
||||
renderCards();
|
||||
await screen.findByText("За этот период операций по расходам нет.");
|
||||
await screen.findByRole("heading", { name: "Добавьте первую карту" });
|
||||
const requests: string[] = [];
|
||||
server.use(
|
||||
http.get("*/api/v1/bank-cards/summary", ({ request }) => {
|
||||
requests.push(new URL(request.url).search);
|
||||
return HttpResponse.json({
|
||||
cardId: null,
|
||||
expenses: money("0"),
|
||||
refunds: money("0"),
|
||||
net: money("0"),
|
||||
categories: [],
|
||||
});
|
||||
}),
|
||||
);
|
||||
fireEvent.click(screen.getByLabelText("Период"));
|
||||
fireEvent.click(
|
||||
await screen.findByRole("button", { name: "10 September 2026" }),
|
||||
);
|
||||
expect(requests).toHaveLength(0);
|
||||
|
||||
fireEvent.click(
|
||||
await screen.findByRole("button", { name: "20 September 2026" }),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(requests.at(-1)).toBe("?from=2026-09-10&to=2026-09-20"),
|
||||
);
|
||||
});
|
||||
it("shows retry after failure instead of presenting an empty list", async () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
ActionIcon,
|
||||
Button,
|
||||
Group,
|
||||
Paper,
|
||||
@@ -9,13 +10,13 @@ import {
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { MonthPickerInput } from "@mantine/dates";
|
||||
import type { FC } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import {
|
||||
BankCardFace,
|
||||
BankFeedback,
|
||||
BankPeriodPicker,
|
||||
BankSummaryView,
|
||||
} from "@/entities/bank-card";
|
||||
import { LoadingSkeleton, StateView } from "@/shared/ui";
|
||||
@@ -28,11 +29,29 @@ const CardsPageView: FC<CardsPageViewProps> = (props) => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Stack gap="lg">
|
||||
<Group justify="space-between">
|
||||
<Group gap="sm">
|
||||
<Title order={1}>{t("bank.title")}</Title>
|
||||
<Button onClick={() => vm.setAdding(true)}>{t("bank.addCard")}</Button>
|
||||
<ActionIcon
|
||||
size="lg"
|
||||
variant="light"
|
||||
aria-label={t("bank.addCard")}
|
||||
title={t("bank.addCard")}
|
||||
onClick={() => vm.setAdding(true)}
|
||||
>
|
||||
<svg
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M12 5v14M5 12h14" />
|
||||
</svg>
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
<Text c="dimmed">{t("bank.manualBalance")}</Text>
|
||||
<Switch
|
||||
label={t("bank.showArchive")}
|
||||
checked={vm.archive}
|
||||
@@ -83,14 +102,32 @@ const CardsPageView: FC<CardsPageViewProps> = (props) => {
|
||||
{vm.cards.data && vm.cards.isFetching && (
|
||||
<Text role="status">{t("bank.refreshing")}</Text>
|
||||
)}
|
||||
<MonthPickerInput
|
||||
label={t("bank.month")}
|
||||
value={`${vm.month}-01`}
|
||||
onChange={(value) => {
|
||||
if (value) vm.setMonth(value.slice(0, 7));
|
||||
}}
|
||||
popoverProps={{ middlewares: { shift: { crossAxis: true } } }}
|
||||
/>
|
||||
<Group align="flex-end" justify="space-between">
|
||||
<BankPeriodPicker period={vm.period} onChange={vm.setPeriod} />
|
||||
{Boolean(vm.categories.data?.length || vm.cards.data?.length) && (
|
||||
<Button
|
||||
variant="subtle"
|
||||
color="gray"
|
||||
onClick={() => vm.setManagingCategories(true)}
|
||||
leftSection={
|
||||
<svg
|
||||
width="18"
|
||||
height="18"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.7"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path d="M3 3h7v7H3zM14 3h7v7h-7zM3 14h7v7H3zM14 14h7v7h-7z" />
|
||||
</svg>
|
||||
}
|
||||
>
|
||||
{t("bank.categories")}
|
||||
</Button>
|
||||
)}
|
||||
</Group>
|
||||
<BankSummaryView
|
||||
all
|
||||
data={vm.summary.data}
|
||||
@@ -107,14 +144,6 @@ const CardsPageView: FC<CardsPageViewProps> = (props) => {
|
||||
retry={() => void vm.categories.refetch()}
|
||||
/>
|
||||
)}
|
||||
{Boolean(vm.categories.data?.length || vm.cards.data?.length) && (
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={() => vm.setManagingCategories(true)}
|
||||
>
|
||||
{t("bank.categories")}
|
||||
</Button>
|
||||
)}
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useSearchParams } from "react-router";
|
||||
import {
|
||||
bankMonth,
|
||||
bankPeriod,
|
||||
useBankCards,
|
||||
useBankCategories,
|
||||
useBankSummary,
|
||||
@@ -9,30 +9,30 @@ import {
|
||||
|
||||
function useCardsPageVm() {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const month = bankMonth(params.get("month"));
|
||||
const period = bankPeriod(params);
|
||||
const [archive, setArchive] = useState(false);
|
||||
const categories = useBankCategories();
|
||||
const [managingCategories, setManagingCategories] = useState(false);
|
||||
const [adding, setAdding] = useState(false);
|
||||
const cards = useBankCards(archive);
|
||||
const summary = useBankSummary(month);
|
||||
const summary = useBankSummary(period);
|
||||
return {
|
||||
categories,
|
||||
managingCategories,
|
||||
setManagingCategories,
|
||||
month,
|
||||
period,
|
||||
archive,
|
||||
setArchive,
|
||||
adding,
|
||||
setAdding,
|
||||
cards,
|
||||
summary,
|
||||
setMonth: (value: string) => {
|
||||
if (value) setParams({ month: bankMonth(value) });
|
||||
setPeriod: (value: [string | null, string | null]) => {
|
||||
if (value[0] && value[1]) setParams({ from: value[0], to: value[1] });
|
||||
},
|
||||
items: cards.data?.map((card) => ({
|
||||
...card,
|
||||
to: `/cards/${card.id}?month=${month}`,
|
||||
to: `/cards/${card.id}?${new URLSearchParams(period)}`,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -529,6 +529,7 @@ const ru = {
|
||||
share: "Доля: {{value}}",
|
||||
},
|
||||
ledger: {
|
||||
clearPeriod: "Очистить период",
|
||||
occurredAt: "{{date}} UTC",
|
||||
quantity: "{{value}} шт.",
|
||||
price: "Цена: {{value}}",
|
||||
@@ -550,6 +551,7 @@ const ru = {
|
||||
recentLoading: "Загрузка последних событий",
|
||||
recentError: "Не удалось загрузить последние события.",
|
||||
recentEmpty: "Последних событий пока нет.",
|
||||
period: "Период",
|
||||
from: "С",
|
||||
to: "По",
|
||||
categories: "Категории",
|
||||
|
||||
@@ -10,3 +10,30 @@ a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.mantine-Modal-content {
|
||||
animation: modal-appear 220ms ease-out;
|
||||
}
|
||||
|
||||
.mantine-Modal-overlay {
|
||||
animation: modal-backdrop-appear 220ms ease-out;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes modal-appear {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(8px) scale(0.98);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes modal-backdrop-appear {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
createTheme,
|
||||
getThemeColor,
|
||||
type MantinePrimaryShade,
|
||||
Modal,
|
||||
rem,
|
||||
rgba,
|
||||
} from "@mantine/core";
|
||||
@@ -21,6 +22,20 @@ const colorRoles = mapValues(color.roles, (role) =>
|
||||
);
|
||||
|
||||
const theme = createTheme({
|
||||
respectReducedMotion: true,
|
||||
components: {
|
||||
Modal: Modal.extend({
|
||||
defaultProps: {
|
||||
overlayProps: { blur: 3 },
|
||||
transitionProps: {
|
||||
transition: "fade-down",
|
||||
duration: 220,
|
||||
exitDuration: 180,
|
||||
timingFunction: "ease-out",
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
primaryColor: color.roles.primary.color,
|
||||
primaryShade: color.primaryShade as MantinePrimaryShade,
|
||||
defaultRadius: radius.default,
|
||||
|
||||
Reference in New Issue
Block a user