Skip to content

Commit 1b4d4eb

Browse files
committed
refactor: update BillingStore to clear state and fetch history based on selected project and total balance changes
1 parent 235b2a1 commit 1b4d4eb

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/features/billing/model/billing.store.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,21 @@ export class BillingStore {
4848
makeAutoObservable(this);
4949

5050
createImmediateReaction(
51-
() => balanceStore.currentBalance$,
52-
() => {
53-
this.fetchHistory();
51+
() => projectsStore.selectedProject,
52+
project => {
53+
this.clearState();
54+
if (project) {
55+
this.fetchHistory();
56+
}
57+
}
58+
);
59+
60+
createImmediateReaction(
61+
() => balanceStore.balance?.total,
62+
total => {
63+
if (total !== undefined && projectsStore.selectedProject) {
64+
this.fetchHistory();
65+
}
5466
}
5567
);
5668
}

src/pages/balance/BillingBlock.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ const BillingBlock: FC<BillingBlockProps> = ({ billingStore }) => {
1414
const hasBillingHistory = billingStore.billingHistory.length > 0;
1515
const isLoading = billingStore.billingHistoryLoading;
1616

17-
// Reset state when store instance changes
18-
useEffect(() => {
19-
setHasEverLoaded(false);
20-
setPreviousRowCount(0);
21-
}, [billingStore]);
22-
2317
// Track whether data has ever been loaded and remember the row count
2418
useEffect(() => {
2519
if (!isLoading && hasBillingHistory) {

0 commit comments

Comments
 (0)