feat(cards): refine controls and modal transitions
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -10,53 +10,20 @@ import {
|
|||||||
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;
|
||||||
@@ -210,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}
|
||||||
|
|||||||
@@ -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)}`,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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