refactor: simplify frontend state and mutation boundaries
Frontend verify / commits (pull_request) Successful in 31s
Frontend verify / security (pull_request) Successful in 11s
Frontend verify / verify (pull_request) Successful in 9m1s
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 10s
Frontend verify / verify (push) Successful in 9m59s

This commit was merged in pull request #44.
This commit is contained in:
2026-09-28 20:01:37 +03:00
parent a4046dbe87
commit a7537da344
25 changed files with 414 additions and 547 deletions
+33 -10
View File
@@ -7,9 +7,9 @@ import {
bankPeriod,
useBankCard,
useBankCards,
useBankMutations,
useBankOperations,
useBankSummary,
useUpdateBankCard,
} from "@/entities/bank-card";
import { ApiErrorCode, apiErrorCode, isApiErrorCode } from "@/shared/api";
import { formatDate, formatMoney } from "@/shared/lib";
@@ -33,7 +33,7 @@ function useCardPageVm() {
: 1;
const card = useBankCard(cardId);
const { updateCard } = useBankMutations();
const updateCard = useUpdateBankCard();
const [archiveError, setArchiveError] = useState<unknown>();
const cards = useBankCards(true);
@@ -69,7 +69,9 @@ function useCardPageVm() {
return {
color: isOutgoing ? "red" : "green",
editable:
Boolean(cards.data)
!history.isPlaceholderData
&& !card.data?.archivedAt
&& Boolean(cards.data)
&& !cards.data?.some(
c =>
(c.id === item.cardId || c.id === item.targetCardId)
@@ -94,27 +96,42 @@ function useCardPageVm() {
return {
archiveError,
archivePending: updateCard.isPending,
card,
cards,
canAddOperation: !card.data?.archivedAt && Boolean(cards.data),
card: card.data,
cardLoading: card.isLoading,
cardRefreshError: card.isError,
cardRefreshing: card.isFetching,
cards: cards.data,
cardsFeedback: cards.isError
? { cached: Boolean(cards.data), error: cards.error }
: undefined,
closeDeletion: () => setDeleting(null),
closeEditing: () => setEditingCard(false),
closeOperation: () => setOperation(null),
deleting,
editableOperation: operation === "new" ? undefined : (operation ?? undefined),
editingCard,
history,
history: {
changingPage: history.isPlaceholderData,
error: history.isError,
loading: history.isLoading,
page: history.data?.page,
refreshing: history.isFetching,
retry: () => void history.refetch(),
},
notFound: isApiErrorCode(
apiErrorCode(card.error),
ApiErrorCode.BankNotFound,
),
openCardEditor: () => setEditingCard(true),
openNewOperation: () => setOperation("new"),
operation,
page,
pageSize,
period,
retryCard: () => void card.refetch(),
retryCards: () => void cards.refetch(),
rows,
setDeleting,
setEditingCard,
setOperation,
setPage: (value: number) =>
setParameters({ ...period, limit: pageSize, page: String(value) }),
setPageSize: (value: null | string) => {
@@ -125,7 +142,13 @@ function useCardPageVm() {
if (value[0] && value[1])
setParameters({ from: value[0], limit: pageSize, to: value[1] });
},
summary,
summary: {
data: summary.data,
error: summary.isError,
fetching: summary.isFetching,
loading: summary.isLoading,
retry: () => void summary.refetch(),
},
toggleArchive: async () => {
if (!card.data) return;
setArchiveError(undefined);