mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
fix: set filter default value
This commit is contained in:
@@ -61,7 +61,6 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
|
||||
// ===== SUBMISSION STATE =====
|
||||
const [filterParams, setFilterParams] = useState<FilterParams>({});
|
||||
const [isSubmitted, setIsSubmitted] = useState(false);
|
||||
const [dateErrorShown, setDateErrorShown] = useState(false);
|
||||
const [hasDateError, setHasDateError] = useState(false);
|
||||
|
||||
@@ -141,13 +140,11 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
sort_by: values.sort_by || undefined,
|
||||
});
|
||||
filterModal.closeModal();
|
||||
setIsSubmitted(true);
|
||||
setCurrentPage(1);
|
||||
setSubmitting(false);
|
||||
},
|
||||
onReset: () => {
|
||||
setFilterParams({});
|
||||
setIsSubmitted(false);
|
||||
setCurrentPage(1);
|
||||
setHasDateError(false);
|
||||
if (dateErrorShown) {
|
||||
@@ -271,24 +268,22 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
|
||||
// ===== DATA FETCHING =====
|
||||
const { data: purchasePerSupplier, isLoading } = useSWR(
|
||||
isSubmitted
|
||||
? () => {
|
||||
const params = {
|
||||
area_id: filterParams.area_id,
|
||||
supplier_id: filterParams.supplier_id,
|
||||
product_id: filterParams.product_id,
|
||||
product_category_id: filterParams.product_category_id,
|
||||
start_date: filterParams.start_date,
|
||||
end_date: filterParams.end_date,
|
||||
sort_by: filterParams.sort_by,
|
||||
filter_by: filterParams.filter_by,
|
||||
page: currentPage,
|
||||
limit: pageSize,
|
||||
};
|
||||
() => {
|
||||
const params = {
|
||||
area_id: filterParams.area_id,
|
||||
supplier_id: filterParams.supplier_id,
|
||||
product_id: filterParams.product_id,
|
||||
product_category_id: filterParams.product_category_id,
|
||||
start_date: filterParams.start_date,
|
||||
end_date: filterParams.end_date,
|
||||
sort_by: filterParams.sort_by,
|
||||
filter_by: filterParams.filter_by,
|
||||
page: currentPage,
|
||||
limit: pageSize,
|
||||
};
|
||||
|
||||
return ['logistic-purchase-report', params];
|
||||
}
|
||||
: null,
|
||||
return ['logistic-purchase-report', params];
|
||||
},
|
||||
([, params]) =>
|
||||
LogisticApi.getLogisticPurchasePerSupplierReport(
|
||||
params.area_id,
|
||||
@@ -736,21 +731,7 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
<>
|
||||
{TabActionsElement}
|
||||
<div className='w-full p-0 sm:p-3 flex flex-col gap-3'>
|
||||
{!isSubmitted ? (
|
||||
<PurchasePerSupplierSkeleton
|
||||
columns={getTableColumns({} as LogisticPurchasePerSupplierSummary)}
|
||||
icon={
|
||||
<Icon
|
||||
icon='heroicons:funnel'
|
||||
className='text-white'
|
||||
width={20}
|
||||
height={20}
|
||||
/>
|
||||
}
|
||||
title='No Filters Selected'
|
||||
subtitle='Please choose filters to narrow down your results and make your search easier.'
|
||||
/>
|
||||
) : isLoading ? (
|
||||
{isLoading && (
|
||||
<PurchasePerSupplierSkeleton
|
||||
columns={getTableColumns({} as LogisticPurchasePerSupplierSummary)}
|
||||
icon={
|
||||
@@ -764,7 +745,9 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
title='Memuat Data Pembelian Per Supplier'
|
||||
subtitle='Silakan tunggu sebentar...'
|
||||
/>
|
||||
) : data.length === 0 ? (
|
||||
)}
|
||||
|
||||
{!isLoading && data.length === 0 && (
|
||||
<PurchasePerSupplierSkeleton
|
||||
columns={getTableColumns({} as LogisticPurchasePerSupplierSummary)}
|
||||
icon={
|
||||
@@ -778,7 +761,10 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
title='Data Not Yet Available'
|
||||
subtitle='Please change your filters to get the data.'
|
||||
/>
|
||||
) : (
|
||||
)}
|
||||
|
||||
{!isLoading &&
|
||||
data.length > 0 &&
|
||||
data.map((supplierReport) => {
|
||||
const summary = supplierReport.summary || {
|
||||
total_qty: 0,
|
||||
@@ -808,7 +794,6 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
}}
|
||||
variant='bordered'
|
||||
collapsible={true}
|
||||
defaultCollapsed={true}
|
||||
>
|
||||
<Table
|
||||
data={supplierReport.rows}
|
||||
@@ -837,8 +822,7 @@ const PurchasesPerSupplierTab = ({ tabId }: PurchasesPerSupplierTabProps) => {
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
})
|
||||
)}
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Filter Modal */}
|
||||
|
||||
Reference in New Issue
Block a user