130 lines
2.8 KiB
TypeScript
130 lines
2.8 KiB
TypeScript
import type { FC } from "react";
|
|
|
|
import {
|
|
Alert,
|
|
Button,
|
|
Group,
|
|
Progress,
|
|
Stack,
|
|
Text,
|
|
Title,
|
|
} from "@mantine/core";
|
|
import { DatePickerInput } from "@mantine/dates";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { BrokerageEventCard } from "@/entities/brokerage-event";
|
|
import { formatSnapshotTime } from "@/shared/lib";
|
|
|
|
import type { AccountEventsPageViewModel } from "../AccountEventsPage.vm";
|
|
|
|
import { AccountEventsPageEmpty } from "./AccountEventsPageEmpty.view";
|
|
|
|
type AccountEventsPageLoadedProps = Extract<
|
|
AccountEventsPageViewModel,
|
|
{ state: "loaded" }
|
|
>;
|
|
|
|
const AccountEventsPageLoadedEvents: FC<AccountEventsPageLoadedProps> = (
|
|
props,
|
|
) => {
|
|
if (props.events.length > 0) {
|
|
return (
|
|
<Stack gap="sm">
|
|
{props.events.map(event => (
|
|
<BrokerageEventCard
|
|
event={event}
|
|
key={JSON.stringify([
|
|
event.account?.id,
|
|
event.type,
|
|
event.date,
|
|
event.instrumentUid,
|
|
event.figi,
|
|
event.ticker,
|
|
event.logoName,
|
|
])}
|
|
/>
|
|
))}
|
|
</Stack>
|
|
);
|
|
}
|
|
|
|
if (props.partial) {
|
|
return;
|
|
}
|
|
|
|
return <AccountEventsPageEmpty />;
|
|
};
|
|
|
|
const AccountEventsPageLoaded: FC<AccountEventsPageLoadedProps> = (props) => {
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
|
<Stack gap="lg">
|
|
{!!props.lastSuccessfulAt && (
|
|
<Text c="dimmed" size="xs">
|
|
{t("investment.sourceTime", {
|
|
date: formatSnapshotTime(props.lastSuccessfulAt),
|
|
})}
|
|
</Text>
|
|
)}
|
|
|
|
<Title order={1}>{t("events.title")}</Title>
|
|
|
|
<Button disabled={props.refreshing} onClick={props.retry} w="fit-content">
|
|
{t("investment.refresh")}
|
|
</Button>
|
|
|
|
{!!props.partial && <Alert role="status">{t("investment.partial")}</Alert>}
|
|
|
|
{!!props.refreshing && <Progress animated aria-label={t("accounts.refreshing")} value={100} />}
|
|
|
|
{!!props.refreshError && (
|
|
<Alert aria-live="polite" color="yellow" role="status">
|
|
{t(
|
|
props.sourceError
|
|
? "investment.syncFailed"
|
|
: "accounts.refreshError",
|
|
)}
|
|
|
|
<Button onClick={props.retry} variant="subtle">
|
|
{t("accounts.retry")}
|
|
</Button>
|
|
</Alert>
|
|
)}
|
|
|
|
<Text c="dimmed">{t("events.hint")}</Text>
|
|
|
|
<Group align="end">
|
|
<DatePickerInput
|
|
allowSingleDateInRange
|
|
clearable
|
|
clearButtonProps={{ "aria-label": t("ledger.clearPeriod") }}
|
|
label={t("ledger.period")}
|
|
onChange={props.onPeriodChange}
|
|
popoverProps={{
|
|
middlewares: { shift: { crossAxis: true } },
|
|
returnFocus: true,
|
|
}}
|
|
type="range"
|
|
value={props.draftPeriod}
|
|
valueFormat="DD.MM.YYYY"
|
|
/>
|
|
</Group>
|
|
|
|
<Group>
|
|
<Button disabled={!props.canApply} onClick={props.onApply}>
|
|
{t("ledger.apply")}
|
|
</Button>
|
|
|
|
<Button onClick={props.onReset} variant="default">
|
|
{t("ledger.reset")}
|
|
</Button>
|
|
</Group>
|
|
|
|
<AccountEventsPageLoadedEvents {...props} />
|
|
</Stack>
|
|
);
|
|
};
|
|
|
|
export { AccountEventsPageLoaded };
|