refactor: enforce frontend view model boundaries
This commit is contained in:
@@ -24,29 +24,36 @@ type AccountDocumentTitleProps = {
|
||||
const AccountDocumentTitle: FC<AccountDocumentTitleProps> = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const { data } = useBrokerageAccounts();
|
||||
|
||||
const accountName
|
||||
= props.accountId === "all"
|
||||
? t("accounts.all")
|
||||
: (data?.find(account => account.id === props.accountId)?.name
|
||||
?? t("account.title"));
|
||||
|
||||
let section = t("portfolio.title");
|
||||
|
||||
switch (props.section ?? "") {
|
||||
case "income": {
|
||||
section = t("income.title");
|
||||
break;
|
||||
}
|
||||
|
||||
case "operations": {
|
||||
section = t("ledger.title");
|
||||
break;
|
||||
}
|
||||
|
||||
case "events": {
|
||||
section = t("events.title");
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return <DocumentTitle title={`${section} — ${accountName}`} />;
|
||||
};
|
||||
|
||||
@@ -55,18 +62,21 @@ type InstrumentDocumentTitleProps = { identifier: string };
|
||||
const BondDocumentTitle: FC<InstrumentDocumentTitleProps> = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const { data } = useBond(props.identifier);
|
||||
|
||||
return <DocumentTitle title={data?.name ?? t("bond.instrument")} />;
|
||||
};
|
||||
|
||||
const StockDocumentTitle: FC<InstrumentDocumentTitleProps> = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const { data } = useStock(props.identifier);
|
||||
|
||||
return <DocumentTitle title={data?.name ?? t("stock.share")} />;
|
||||
};
|
||||
|
||||
const CardDocumentTitle: FC<InstrumentDocumentTitleProps> = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const { data } = useBankCard(props.identifier);
|
||||
|
||||
return <DocumentTitle title={data?.name ?? t("bank.card")} />;
|
||||
};
|
||||
|
||||
@@ -94,7 +104,14 @@ const ProtectedDocumentTitle: FC = () => {
|
||||
if (cards) return <DocumentTitle title={t("navigation.cards")} />;
|
||||
if (bonds) return <DocumentTitle title={t("navigation.bonds")} />;
|
||||
if (stocks) return <DocumentTitle title={t("navigation.stocks")} />;
|
||||
return settings ? <DocumentTitle title={t("navigation.settings")} /> : <DocumentTitle title={t("navigation.accounts")} />;
|
||||
|
||||
return settings
|
||||
? (
|
||||
<DocumentTitle title={t("navigation.settings")} />
|
||||
)
|
||||
: (
|
||||
<DocumentTitle title={t("navigation.accounts")} />
|
||||
);
|
||||
};
|
||||
|
||||
export { ProtectedDocumentTitle };
|
||||
|
||||
Reference in New Issue
Block a user