From 97ff90996a0f5fd79a2332bee2bfe9ce4bf5e4ac Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Thu, 4 Jun 2026 14:58:51 +0700 Subject: [PATCH] feat: add Refresh button with force_recompute to ReportDepreciationTab Adds a Refresh button to the tab actions bar (left of ButtonFilter) that re-fetches depreciation data with force_recompute=true in the query param, triggering a server-side recomputation. The arrow-path icon spins while the request is in flight. Button is styled to match ButtonFilter. The force_recompute flag resets to false when filters are changed. Co-Authored-By: Claude Sonnet 4.6 --- .../expense/tab/ReportDepreciationTab.tsx | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/src/components/pages/report/expense/tab/ReportDepreciationTab.tsx b/src/components/pages/report/expense/tab/ReportDepreciationTab.tsx index abab3df7..ada6b805 100644 --- a/src/components/pages/report/expense/tab/ReportDepreciationTab.tsx +++ b/src/components/pages/report/expense/tab/ReportDepreciationTab.tsx @@ -1,10 +1,11 @@ 'use client'; -import React, { useEffect, useMemo } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import useSWR from 'swr'; import { ColumnDef } from '@tanstack/react-table'; import { Icon } from '@iconify/react'; +import Button from '@/components/Button'; import Card from '@/components/Card'; import Pagination from '@/components/Pagination'; import Table from '@/components/Table'; @@ -56,11 +57,21 @@ const ReportDepreciationTab = ({ tabId }: ReportDepreciationTabProps) => { storeName: 'report-depreciation-table', }); - const { data: depreciationsResponse, isLoading: isLoadingDepreciations } = - useSWR( - `${DepreciationReportApi.basePath}${getTableFilterQueryString()}`, - DepreciationReportApi.getAllFetcher - ); + const [forceRecompute, setForceRecompute] = useState(false); + + const { + data: depreciationsResponse, + isLoading: isLoadingDepreciations, + isValidating, + mutate, + } = useSWR( + `${DepreciationReportApi.basePath}${getTableFilterQueryString()}&force_recompute=${forceRecompute}`, + DepreciationReportApi.getAllFetcher + ); + + const handleRefresh = useCallback(() => { + setForceRecompute(true); + }, [mutate]); const depreciations = isResponseSuccess(depreciationsResponse) ? depreciationsResponse.data @@ -114,6 +125,21 @@ const ReportDepreciationTab = ({ tabId }: ReportDepreciationTabProps) => { const tabActionsElement = useMemo( () => (
+ { />
), - [tableFilterState] + [tableFilterState, handleRefresh, isValidating] ); useEffect(() => { @@ -255,6 +281,8 @@ const ReportDepreciationTab = ({ tabId }: ReportDepreciationTabProps) => { values.period ? formatDate(values.period, 'YYYY-MM-DD') : '', true ); + + setForceRecompute(false); }} />