feat(FE=361,363): Add Submit button to PurchasesPerSupplierTab

This commit is contained in:
rstubryan
2025-12-15 11:41:12 +07:00
parent 5c9332537c
commit 69eaae6d43
@@ -41,6 +41,9 @@ const PurchasesPerSupplierTab = () => {
const [currentPage, setCurrentPage] = useState(1); const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(10); const [pageSize, setPageSize] = useState(10);
// ===== SUBMISSION STATE =====
const [isSubmitted, setIsSubmitted] = useState(false);
// ===== TABLE FILTER STATE ===== // ===== TABLE FILTER STATE =====
const { state: tableFilterState, updateFilter } = useTableFilter({ const { state: tableFilterState, updateFilter } = useTableFilter({
initial: { initial: {
@@ -63,6 +66,7 @@ const PurchasesPerSupplierTab = () => {
setDataType(newDataType); setDataType(newDataType);
updateFilter('received_date', ''); updateFilter('received_date', '');
updateFilter('po_date', ''); updateFilter('po_date', '');
setIsSubmitted(false);
}, },
[updateFilter] [updateFilter]
); );
@@ -92,6 +96,7 @@ const PurchasesPerSupplierTab = () => {
(val: OptionType | OptionType[] | null) => { (val: OptionType | OptionType[] | null) => {
const newVal = val as OptionType; const newVal = val as OptionType;
updateFilter('area_id', newVal?.value ? String(newVal.value) : ''); updateFilter('area_id', newVal?.value ? String(newVal.value) : '');
setIsSubmitted(false);
}, },
[updateFilter] [updateFilter]
); );
@@ -100,6 +105,7 @@ const PurchasesPerSupplierTab = () => {
(val: OptionType | OptionType[] | null) => { (val: OptionType | OptionType[] | null) => {
const newVal = val as OptionType; const newVal = val as OptionType;
updateFilter('supplier_id', newVal?.value ? String(newVal.value) : ''); updateFilter('supplier_id', newVal?.value ? String(newVal.value) : '');
setIsSubmitted(false);
}, },
[updateFilter] [updateFilter]
); );
@@ -108,6 +114,7 @@ const PurchasesPerSupplierTab = () => {
(val: OptionType | OptionType[] | null) => { (val: OptionType | OptionType[] | null) => {
const newVal = val as OptionType; const newVal = val as OptionType;
updateFilter('product_id', newVal?.value ? String(newVal.value) : ''); updateFilter('product_id', newVal?.value ? String(newVal.value) : '');
setIsSubmitted(false);
}, },
[updateFilter] [updateFilter]
); );
@@ -118,6 +125,7 @@ const PurchasesPerSupplierTab = () => {
updateDataType( updateDataType(
(newVal?.value as 'received_date' | 'po_date') || 'received_date' (newVal?.value as 'received_date' | 'po_date') || 'received_date'
); );
setIsSubmitted(false);
}, },
[updateDataType] [updateDataType]
); );
@@ -128,11 +136,9 @@ const PurchasesPerSupplierTab = () => {
(e) => { (e) => {
const val = e.target.value; const val = e.target.value;
updateFilter('start_date', val || ''); updateFilter('start_date', val || '');
if (val && dataType) { setIsSubmitted(false);
updateFilter(dataType, val);
}
}, },
[updateFilter, dataType] [updateFilter]
); );
const endDateChangeHandler = useCallback< const endDateChangeHandler = useCallback<
@@ -141,6 +147,7 @@ const PurchasesPerSupplierTab = () => {
(e) => { (e) => {
const val = e.target.value; const val = e.target.value;
updateFilter('end_date', val || ''); updateFilter('end_date', val || '');
setIsSubmitted(false);
}, },
[updateFilter] [updateFilter]
); );
@@ -154,31 +161,39 @@ const PurchasesPerSupplierTab = () => {
updateFilter('start_date', ''); updateFilter('start_date', '');
updateFilter('end_date', ''); updateFilter('end_date', '');
setDataType('received_date'); setDataType('received_date');
setIsSubmitted(false);
}, [updateFilter]); }, [updateFilter]);
const handleSubmit = useCallback(() => {
setIsSubmitted(true);
setCurrentPage(1);
}, []);
// ===== DATA FETCHING ===== // ===== DATA FETCHING =====
const { data: purchasePerSupplier, isLoading } = useSWR( const { data: purchasePerSupplier, isLoading } = useSWR(
() => { isSubmitted
const params = { ? () => {
area_id: tableFilterState.area_id const params = {
? Number(tableFilterState.area_id) area_id: tableFilterState.area_id
: undefined, ? Number(tableFilterState.area_id)
supplier_id: tableFilterState.supplier_id : undefined,
? Number(tableFilterState.supplier_id) supplier_id: tableFilterState.supplier_id
: undefined, ? Number(tableFilterState.supplier_id)
product_id: tableFilterState.product_id : undefined,
? Number(tableFilterState.product_id) product_id: tableFilterState.product_id
: undefined, ? Number(tableFilterState.product_id)
received_date: tableFilterState.received_date || undefined, : undefined,
po_date: tableFilterState.po_date || undefined, received_date: tableFilterState.received_date || undefined,
start_date: tableFilterState.start_date || undefined, po_date: tableFilterState.po_date || undefined,
end_date: tableFilterState.end_date || undefined, start_date: tableFilterState.start_date || undefined,
page: currentPage, end_date: tableFilterState.end_date || undefined,
limit: pageSize, page: currentPage,
}; limit: pageSize,
};
return ['logistic-purchase-report', params]; return ['logistic-purchase-report', params];
}, }
: null,
([, params]) => ([, params]) =>
LogisticApi.getLogisticStockReport( LogisticApi.getLogisticStockReport(
params.area_id, params.area_id,
@@ -393,10 +408,13 @@ const PurchasesPerSupplierTab = () => {
subtitle='Laporan > Rekapitulasi Pembelian Per Supplier' subtitle='Laporan > Rekapitulasi Pembelian Per Supplier'
className={{ wrapper: 'w-full', body: 'p-1!' }} className={{ wrapper: 'w-full', body: 'p-1!' }}
> >
<div className='mb-4 flex justify-end'> <div className='mb-4 flex justify-end gap-2'>
<Button onClick={resetFilters} className='px-4 py-2'> <Button color='warning' onClick={resetFilters}>
Reset Reset
</Button> </Button>
<Button color='primary' onClick={handleSubmit}>
Submit
</Button>
</div> </div>
<div className='grid grid-cols-12 gap-4'> <div className='grid grid-cols-12 gap-4'>
<SelectInput <SelectInput
@@ -493,11 +511,17 @@ const PurchasesPerSupplierTab = () => {
/> />
</div> </div>
{isLoading ? ( {!isSubmitted ? (
<div className='mt-6 text-center text-gray-500'>Memuat data...</div> <div className='mt-6 text-center text-gray-500'>
Silakan pilih filter dan klik tombol Submit untuk menampilkan data.
</div>
) : isLoading ? (
<div className='w-full flex flex-row justify-center items-center p-4'>
<span className='loading loading-spinner loading-xl' />
</div>
) : data.length === 0 ? ( ) : data.length === 0 ? (
<div className='mt-6 text-center text-gray-500'> <div className='mt-6 text-center text-gray-500'>
Tidak ada data untuk ditampilkan. Tidak ada data yang dapat ditampilkan...
</div> </div>
) : ( ) : (
data.map((supplier) => { data.map((supplier) => {