refactor(FE-363): Use SWR key+fetcher with params for logistic report

This commit is contained in:
rstubryan
2025-12-13 12:03:56 +07:00
parent fd2e1f8b96
commit 63c2a240d2
@@ -154,23 +154,35 @@ const PurchasesPerSupplierTab = () => {
// ===== DATA FETCHING =====
const { data: purchasePerSupplier, isLoading } = useSWR(
() =>
LogisticApi.getLogisticStockReport(
tableFilterState.area_id ? Number(tableFilterState.area_id) : undefined,
tableFilterState.supplier_id
() => {
const params = {
area_id: tableFilterState.area_id
? Number(tableFilterState.area_id)
: undefined,
supplier_id: tableFilterState.supplier_id
? Number(tableFilterState.supplier_id)
: undefined,
tableFilterState.product_id
product_id: tableFilterState.product_id
? Number(tableFilterState.product_id)
: undefined,
tableFilterState.received_date || undefined,
tableFilterState.po_date || undefined,
tableFilterState.start_date || undefined,
tableFilterState.end_date || undefined
),
{
revalidateOnFocus: false,
}
received_date: tableFilterState.received_date || undefined,
po_date: tableFilterState.po_date || undefined,
start_date: tableFilterState.start_date || undefined,
end_date: tableFilterState.end_date || undefined,
};
return ['logistic-purchase-report', params];
},
([, params]) =>
LogisticApi.getLogisticStockReport(
params.area_id,
params.supplier_id,
params.product_id,
params.received_date,
params.po_date,
params.start_date,
params.end_date
)
);
const data: LogisticPurchasePerSupplier[] = isResponseSuccess(