mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
feat(FE-363): Add pagination to purchases per supplier report
This commit is contained in:
@@ -37,6 +37,10 @@ const PurchasesPerSupplierTab = () => {
|
|||||||
'received_date'
|
'received_date'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ===== PAGINATION STATE =====
|
||||||
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
const [pageSize, setPageSize] = useState(10);
|
||||||
|
|
||||||
// ===== TABLE FILTER STATE =====
|
// ===== TABLE FILTER STATE =====
|
||||||
const { state: tableFilterState, updateFilter } = useTableFilter({
|
const { state: tableFilterState, updateFilter } = useTableFilter({
|
||||||
initial: {
|
initial: {
|
||||||
@@ -169,6 +173,8 @@ const PurchasesPerSupplierTab = () => {
|
|||||||
po_date: tableFilterState.po_date || undefined,
|
po_date: tableFilterState.po_date || undefined,
|
||||||
start_date: tableFilterState.start_date || undefined,
|
start_date: tableFilterState.start_date || undefined,
|
||||||
end_date: tableFilterState.end_date || undefined,
|
end_date: tableFilterState.end_date || undefined,
|
||||||
|
page: currentPage,
|
||||||
|
limit: pageSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
return ['logistic-purchase-report', params];
|
return ['logistic-purchase-report', params];
|
||||||
@@ -181,7 +187,9 @@ const PurchasesPerSupplierTab = () => {
|
|||||||
params.received_date,
|
params.received_date,
|
||||||
params.po_date,
|
params.po_date,
|
||||||
params.start_date,
|
params.start_date,
|
||||||
params.end_date
|
params.end_date,
|
||||||
|
params.page,
|
||||||
|
params.limit
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -191,6 +199,32 @@ const PurchasesPerSupplierTab = () => {
|
|||||||
? (purchasePerSupplier?.data as unknown as LogisticPurchasePerSupplier[])
|
? (purchasePerSupplier?.data as unknown as LogisticPurchasePerSupplier[])
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const meta =
|
||||||
|
isResponseSuccess(purchasePerSupplier) && 'meta' in purchasePerSupplier
|
||||||
|
? purchasePerSupplier.meta
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
// ===== PAGINATION HANDLERS =====
|
||||||
|
const handlePageChange = (page: number) => {
|
||||||
|
setCurrentPage(page);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRowChange = (pageSize: number) => {
|
||||||
|
setPageSize(pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNextPage = () => {
|
||||||
|
if (meta && currentPage < meta.total_pages) {
|
||||||
|
setCurrentPage(currentPage + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePrevPage = () => {
|
||||||
|
if (currentPage > 1) {
|
||||||
|
setCurrentPage(currentPage - 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getTableColumns = (
|
const getTableColumns = (
|
||||||
totals: Totals
|
totals: Totals
|
||||||
): ColumnDef<LogisticPurchasePerSupplierItems>[] => {
|
): ColumnDef<LogisticPurchasePerSupplierItems>[] => {
|
||||||
@@ -505,7 +539,6 @@ const PurchasesPerSupplierTab = () => {
|
|||||||
const tableColumns = getTableColumns(totals);
|
const tableColumns = getTableColumns(totals);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<Card
|
<Card
|
||||||
key={supplier.id}
|
key={supplier.id}
|
||||||
title={supplier.supplier.name}
|
title={supplier.supplier.name}
|
||||||
@@ -522,8 +555,7 @@ const PurchasesPerSupplierTab = () => {
|
|||||||
containerClassName: 'w-full',
|
containerClassName: 'w-full',
|
||||||
tableWrapperClassName: 'overflow-x-auto mt-4',
|
tableWrapperClassName: 'overflow-x-auto mt-4',
|
||||||
tableClassName: 'w-full table-auto text-sm',
|
tableClassName: 'w-full table-auto text-sm',
|
||||||
headerRowClassName:
|
headerRowClassName: 'border-b border-b-gray-200 bg-gray-50',
|
||||||
'border-b border-b-gray-200 bg-gray-50',
|
|
||||||
headerColumnClassName:
|
headerColumnClassName:
|
||||||
'px-4 py-3 text-xs font-semibold text-gray-700 text-left border border-gray-200',
|
'px-4 py-3 text-xs font-semibold text-gray-700 text-left border border-gray-200',
|
||||||
bodyRowClassName:
|
bodyRowClassName:
|
||||||
@@ -535,25 +567,28 @@ const PurchasesPerSupplierTab = () => {
|
|||||||
footerRowClassName: 'border-t-2 border-gray-300',
|
footerRowClassName: 'border-t-2 border-gray-300',
|
||||||
footerColumnClassName:
|
footerColumnClassName:
|
||||||
'px-4 py-3 text-xs text-gray-900 whitespace-nowrap',
|
'px-4 py-3 text-xs text-gray-900 whitespace-nowrap',
|
||||||
|
paginationClassName: 'hidden',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Pagination
|
|
||||||
key={supplier.id}
|
|
||||||
currentPage={1}
|
|
||||||
totalItems={supplier.items.length}
|
|
||||||
onPageChange={() => {}}
|
|
||||||
onRowChange={() => {}}
|
|
||||||
onNextPage={() => {}}
|
|
||||||
onPrevPage={() => {}}
|
|
||||||
rowOptions={[10, 25, 50, 100]}
|
|
||||||
itemsPerPage={10}
|
|
||||||
/>
|
|
||||||
</Card>
|
</Card>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
{meta && data.length > 0 && (
|
||||||
|
<div className='mt-6'>
|
||||||
|
<Pagination
|
||||||
|
currentPage={meta.page}
|
||||||
|
totalItems={meta.total_results}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
onRowChange={handleRowChange}
|
||||||
|
onNextPage={handleNextPage}
|
||||||
|
onPrevPage={handlePrevPage}
|
||||||
|
rowOptions={[10, 25, 50, 100]}
|
||||||
|
itemsPerPage={meta.limit}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,11 +18,13 @@ export class LogisticApiService extends BaseApiService<
|
|||||||
received_date?: string,
|
received_date?: string,
|
||||||
po_date?: string,
|
po_date?: string,
|
||||||
start_date?: string,
|
start_date?: string,
|
||||||
end_date?: string
|
end_date?: string,
|
||||||
|
page?: number,
|
||||||
|
limit?: number
|
||||||
): Promise<BaseApiResponse<LogisticPurchasePerSupplierReport> | undefined> {
|
): Promise<BaseApiResponse<LogisticPurchasePerSupplierReport> | undefined> {
|
||||||
return await this.customRequest<
|
return await this.customRequest<
|
||||||
BaseApiResponse<LogisticPurchasePerSupplierReport>
|
BaseApiResponse<LogisticPurchasePerSupplierReport>
|
||||||
>(`purchase-supplier`, {
|
>(`logistic-stock`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params: {
|
params: {
|
||||||
area_id: area_id,
|
area_id: area_id,
|
||||||
@@ -32,9 +34,14 @@ export class LogisticApiService extends BaseApiService<
|
|||||||
po_date: po_date,
|
po_date: po_date,
|
||||||
start_date: start_date,
|
start_date: start_date,
|
||||||
end_date: end_date,
|
end_date: end_date,
|
||||||
|
page: page,
|
||||||
|
limit: limit,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LogisticApi = new LogisticApiService('/reports');
|
// TODO: REPLACE WITH PRODUCTION URL
|
||||||
|
export const LogisticApi = new LogisticApiService(
|
||||||
|
'http://localhost:4010/api/report'
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user