feat(income): offer retry after exhausted income reads (WealthLedger/frontend#55)

This commit is contained in:
2026-11-03 08:38:23 +03:00
parent d3335a7a8d
commit a2e9d63bfe
4 changed files with 116 additions and 20 deletions
@@ -3,10 +3,9 @@ import { useEffect, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
import { useParams, useSearchParams } from "react-router";
import type { InvestmentResourceMeta } from "@/shared/api";
import { type IncomeAnalytics, useIncomeAnalytics } from "@/entities/income";
import { useScreenSync } from "@/features/tbank-connection";
import { type InvestmentResourceMeta, readRetry } from "@/shared/api";
import { isValidPeriod, moscowDate, useInitialAvailability } from "@/shared/lib";
import {
@@ -32,12 +31,14 @@ type AccountIncomePageViewModel
onReset: () => void;
onSubmit: (values: IncomeForm) => void;
partial?: boolean;
readRetry: ReturnType<typeof readRetry>;
source?: InvestmentResourceMeta;
state: "loaded";
totalVisible: boolean;
}
| {
period: IncomePeriod;
readRetry: ReturnType<typeof readRetry>;
state: "error";
}
| { state: "loading" };
@@ -87,12 +88,14 @@ const useAccountIncomePageViewModel = (): AccountIncomePageViewModel => {
isFetching: analytics.isFetching,
});
const retry = readRetry([analytics]);
if (availability === "loading" && analytics.isLoading)
return { state: "loading" };
if (!analytics.data)
return availability === "unavailable"
? { period, state: "error" }
? { period, readRetry: retry, state: "error" }
: { state: "loading" };
const display = toIncomeDisplayModel(analytics.data);
@@ -119,6 +122,7 @@ const useAccountIncomePageViewModel = (): AccountIncomePageViewModel => {
onReset,
onSubmit,
partial: analytics.meta?.completeness === "incomplete",
readRetry: retry,
source: analytics.meta,
state: "loaded",
totalVisible: analytics.meta?.completeness === "complete",