import { Alert, Button, Group, MultiSelect, Progress, Stack, Title, } from "@mantine/core"; import { DateInput } from "@mantine/dates"; import type { FC } from "react"; import { useTranslation } from "react-i18next"; import { LedgerEntryRow, type OperationCategory, operationCategories, } from "@/entities/broker-operation"; import { StateView } from "@/shared/ui"; import type { AccountOperationsPageViewModel } from "../AccountOperationsPage.vm"; type AccountOperationsPageLoadedProps = Extract< AccountOperationsPageViewModel, { state: "loaded" } >; const operationCategorySet = new Set(operationCategories); function toDateValue(value: string | null): Date | null { if (!value) return null; const [year, month, day] = value.split("-").map(Number); return new Date(year, month - 1, day); } function fromDateValue(value: Date | string | null): string | null { if (!value) return null; if (typeof value === "string") return value; const year = value.getFullYear(); const month = String(value.getMonth() + 1).padStart(2, "0"); const day = String(value.getDate()).padStart(2, "0"); return `${year}-${month}-${day}`; } function fromMultiSelectValue(value: string[]) { return value.filter((item): item is OperationCategory => operationCategorySet.has(item), ); } const AccountOperationsPageLoaded: FC = ( props, ) => { const { canApply, draftCategories, draftFrom, draftTo, hasNext, hasPrevious, items, onApply, onDraftCategoriesChange, onDraftFromChange, onDraftToChange, onNext, onPrevious, onReset, } = props; const { t } = useTranslation(); const categoryData = operationCategories.map((category) => ({ value: category, label: t(`ledger.category.${category}`), })); return ( {t("ledger.title")} {props.refreshing ? ( ) : null} {props.refreshError ? ( {t("accounts.refreshError")} ) : null} onDraftFromChange(fromDateValue(value))} maxDate={toDateValue(draftTo) ?? undefined} valueFormat="DD.MM.YYYY" /> onDraftToChange(fromDateValue(value))} minDate={toDateValue(draftFrom) ?? undefined} valueFormat="DD.MM.YYYY" /> onDraftCategoriesChange(fromMultiSelectValue(value)) } clearable /> {items.length ? ( items.map((operation) => ( )) ) : ( )} {hasNext || hasPrevious ? ( ) : null} ); }; export { AccountOperationsPageLoaded };