From fd2e1f8b96fa0f89b6b0fa056cf51cd69f10c963 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Sat, 13 Dec 2025 11:51:41 +0700 Subject: [PATCH] refactor(FE-363): Replace LogisticService with LogisticApi instance --- .../PurchasesPerSupplierTab.tsx | 27 ++++++++---- src/services/api/logistic.ts | 41 ++----------------- 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx b/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx index d74ec53f..f0f9f64e 100644 --- a/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx +++ b/src/components/pages/report/logistic-stock/PurchasesPerSupplierTab.tsx @@ -10,7 +10,7 @@ import DateInput from '@/components/input/DateInput'; import { AreaApi } from '@/services/api/master-data'; import { SupplierApi } from '@/services/api/master-data'; import { ProductApi } from '@/services/api/master-data'; -import { LogisticService } from '@/services/api/logistic'; +import { LogisticApi } from '@/services/api/logistic'; import Table from '@/components/Table'; import { ColumnDef } from '@tanstack/react-table'; import { formatCurrency, formatDate } from '@/lib/helper'; @@ -38,11 +38,7 @@ const PurchasesPerSupplierTab = () => { ); // ===== TABLE FILTER STATE ===== - const { - state: tableFilterState, - updateFilter, - toQueryString: getTableFilterQueryString, - } = useTableFilter({ + const { state: tableFilterState, updateFilter } = useTableFilter({ initial: { area_id: '', supplier_id: '', @@ -158,8 +154,23 @@ const PurchasesPerSupplierTab = () => { // ===== DATA FETCHING ===== const { data: purchasePerSupplier, isLoading } = useSWR( - `${LogisticService.basePath}/purchase-supplier${getTableFilterQueryString()}`, - LogisticService.getAllFetcher + () => + LogisticApi.getLogisticStockReport( + tableFilterState.area_id ? Number(tableFilterState.area_id) : undefined, + tableFilterState.supplier_id + ? Number(tableFilterState.supplier_id) + : undefined, + 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, + } ); const data: LogisticPurchasePerSupplier[] = isResponseSuccess( diff --git a/src/services/api/logistic.ts b/src/services/api/logistic.ts index 27fbb6ea..cee1c825 100644 --- a/src/services/api/logistic.ts +++ b/src/services/api/logistic.ts @@ -2,18 +2,12 @@ import { BaseApiService } from '@/services/api/base'; import { BaseApiResponse } from '@/types/api/api-general'; import { LogisticPurchasePerSupplierReport } from '@/types/api/report/logistic-stock'; -const baseLogisticApi = new BaseApiService< - LogisticPurchasePerSupplierReport, - unknown, - unknown ->('/reports'); - -export class LogisticApi extends BaseApiService< +export class LogisticApiService extends BaseApiService< LogisticPurchasePerSupplierReport, unknown, unknown > { - constructor(basePath: string = '') { + constructor(basePath: string) { super(basePath); } @@ -43,33 +37,4 @@ export class LogisticApi extends BaseApiService< } } -export const LogisticService = { - basePath: baseLogisticApi.basePath, - header: baseLogisticApi.header, - getAllFetcher: baseLogisticApi.getAllFetcher.bind(baseLogisticApi), - getSingle: baseLogisticApi.getSingle.bind(baseLogisticApi), - create: baseLogisticApi.create.bind(baseLogisticApi), - update: baseLogisticApi.update.bind(baseLogisticApi), - delete: baseLogisticApi.delete.bind(baseLogisticApi), - customRequest: baseLogisticApi.customRequest.bind(baseLogisticApi), - - // Custom method for specific endpoint - getLogisticStockReport: ( - area_id?: number, - supplier_id?: number, - product_id?: number, - received_date?: string, - po_date?: string, - start_date?: string, - end_date?: string - ) => - new LogisticApi().getLogisticStockReport( - area_id, - supplier_id, - product_id, - received_date, - po_date, - start_date, - end_date - ), -}; +export const LogisticApi = new LogisticApiService('/reports');