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