feat: default journal period to last 7 days
This commit is contained in:
+7
-4
@@ -18,6 +18,7 @@ import {
|
||||
LedgerEntryRow,
|
||||
} from "@/entities/broker-operation";
|
||||
import { configureAuthClient } from "@/shared/api";
|
||||
import { defaultPeriod } from "@/shared/lib";
|
||||
import { createTestQueryClient } from "@/test/query";
|
||||
import { resource } from "@/test/resource";
|
||||
import { server } from "@/test/server";
|
||||
@@ -312,18 +313,20 @@ describe("AccountOperationsPage", () => {
|
||||
"allows resetting filters after a request failure for %s",
|
||||
async (accountId) => {
|
||||
configureTestAuth();
|
||||
const [defaultFrom] = defaultPeriod();
|
||||
server.use(
|
||||
http.get(
|
||||
"*/api/v1/brokerage-accounts/:accountId/operations",
|
||||
({ request }) =>
|
||||
new URL(request.url).searchParams.has("from")
|
||||
? HttpResponse.json({ code: "VALIDATION_ERROR" }, { status: 400 })
|
||||
: HttpResponse.json(
|
||||
new URL(request.url).searchParams.get("from")
|
||||
=== `${defaultFrom}T00:00:00.000Z`
|
||||
? HttpResponse.json(
|
||||
|
||||
resource(
|
||||
{ hasNext: false, items: [], nextCursor: null },
|
||||
),
|
||||
),
|
||||
)
|
||||
: HttpResponse.json({ code: "VALIDATION_ERROR" }, { status: 400 }),
|
||||
),
|
||||
);
|
||||
render(
|
||||
|
||||
@@ -11,7 +11,13 @@ import {
|
||||
} from "@/entities/broker-operation";
|
||||
import { useScreenSync } from "@/features/tbank-connection";
|
||||
import { ApiErrorCode, apiErrorCode, isApiErrorCode } from "@/shared/api";
|
||||
import { isValidPeriod, useInitialAvailability, useUrlPeriod } from "@/shared/lib";
|
||||
import {
|
||||
defaultPeriod,
|
||||
isValidPeriod,
|
||||
moscowDate,
|
||||
useInitialAvailability,
|
||||
useUrlPeriod,
|
||||
} from "@/shared/lib";
|
||||
|
||||
const operationCategorySet = new Set<string>(operationCategories);
|
||||
|
||||
@@ -24,10 +30,12 @@ type AccountOperationsPageViewModel
|
||||
hasPrevious: boolean;
|
||||
historyLoading?: boolean;
|
||||
items: BrokerageOperation[];
|
||||
maxDate: string;
|
||||
onApply: () => void;
|
||||
onCategoriesChange: (value: string[]) => void;
|
||||
onNext: () => void;
|
||||
onPeriodChange: (value: [null | string, null | string]) => void;
|
||||
onPeriodPopoverOpen: () => void;
|
||||
onPrevious: () => void;
|
||||
onReset: () => void;
|
||||
partial?: boolean;
|
||||
@@ -61,6 +69,8 @@ const useAccountOperationsPageVm = (): AccountOperationsPageViewModel => {
|
||||
const [draftCategories, setDraftCategories]
|
||||
= useState<OperationCategory[]>(appliedCategories);
|
||||
|
||||
const [maxDate, setMaxDate] = useState(() => moscowDate(new Date()));
|
||||
|
||||
const firstPageQuery = {
|
||||
from: dateStart(appliedFrom),
|
||||
to: dateEnd(appliedTo),
|
||||
@@ -103,7 +113,7 @@ const useAccountOperationsPageVm = (): AccountOperationsPageViewModel => {
|
||||
}).queryKey;
|
||||
|
||||
const onReset = () => {
|
||||
setDraftPeriod([null, null]);
|
||||
setDraftPeriod([appliedFrom, appliedTo]);
|
||||
setDraftCategories([]);
|
||||
setSearchParameters({});
|
||||
history.reset();
|
||||
@@ -143,6 +153,7 @@ const useAccountOperationsPageVm = (): AccountOperationsPageViewModel => {
|
||||
operations.meta?.coverage?.historyState === "loading"
|
||||
|| operations.meta?.coverage?.historyState === "partial",
|
||||
items: operations.data.items,
|
||||
maxDate,
|
||||
onApply: () => {
|
||||
if (!isValidPeriod(draftFrom, draftTo)) return;
|
||||
setSearchParameters({
|
||||
@@ -160,7 +171,10 @@ const useAccountOperationsPageVm = (): AccountOperationsPageViewModel => {
|
||||
),
|
||||
),
|
||||
onNext: history.onNext,
|
||||
onPeriodChange: setDraftPeriod,
|
||||
onPeriodChange: value => setDraftPeriod(
|
||||
value[0] === null && value[1] === null ? defaultPeriod() : value,
|
||||
),
|
||||
onPeriodPopoverOpen: () => setMaxDate(moscowDate(new Date())),
|
||||
onPrevious: history.onPrevious,
|
||||
onReset,
|
||||
partial: operations.meta?.availability !== "complete",
|
||||
|
||||
+2
@@ -72,9 +72,11 @@ const AccountOperationsPageLoaded: FC<AccountOperationsPageLoadedProps> = (
|
||||
clearable
|
||||
clearButtonProps={{ "aria-label": t("ledger.clearPeriod") }}
|
||||
label={t("ledger.period")}
|
||||
maxDate={props.maxDate}
|
||||
onChange={props.onPeriodChange}
|
||||
popoverProps={{
|
||||
middlewares: { shift: { crossAxis: true } },
|
||||
onOpen: props.onPeriodPopoverOpen,
|
||||
returnFocus: true,
|
||||
}}
|
||||
type="range"
|
||||
|
||||
Reference in New Issue
Block a user