fix: update dependencies in multiple tables to include updateSortingFilter in effect dependencies

This commit is contained in:
rstubryan
2025-10-09 11:35:22 +07:00
parent d7ae7e00d3
commit b561ed6193
8 changed files with 46 additions and 19 deletions
+2
View File
@@ -6,6 +6,8 @@
"dev": "eslint && next dev --turbopack", "dev": "eslint && next dev --turbopack",
"build": "next build --turbopack", "build": "next build --turbopack",
"start": "next start", "start": "next start",
"start": "npx serve@latest out",
"start:next": "next start",
"lint": "eslint" "lint": "eslint"
}, },
"dependencies": { "dependencies": {
@@ -231,7 +231,7 @@ const KandangsTable = () => {
updateSortingFilter('nameSort', nameSortFilter); updateSortingFilter('nameSort', nameSortFilter);
updateSortingFilter('locationSort', locationSortFilter); updateSortingFilter('locationSort', locationSortFilter);
updateSortingFilter('picSort', picSortFilter); updateSortingFilter('picSort', picSortFilter);
}, [sorting]); }, [sorting, updateSortingFilter]);
return ( return (
<> <>
@@ -230,7 +230,7 @@ const LocationsTable = () => {
updateSortingFilter('nameSort', nameSortFilter); updateSortingFilter('nameSort', nameSortFilter);
updateSortingFilter('addressSort', addressSortFilter); updateSortingFilter('addressSort', addressSortFilter);
updateSortingFilter('areaSort', areaSortFilter); updateSortingFilter('areaSort', areaSortFilter);
}, [sorting]); }, [sorting, updateSortingFilter]);
return ( return (
<> <>
@@ -99,7 +99,7 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
useEffect(() => { useEffect(() => {
formik.setValues(formikInitialValues); formik.setValues(formikInitialValues);
}, [formikInitialValues]); }, [formik, formikInitialValues]);
return ( return (
<section className='w-full max-w-xl'> <section className='w-full max-w-xl'>
@@ -66,7 +66,12 @@ const RowOptionsMenu = ({
color='error' color='error'
className='text-error hover:text-inherit' className='text-error hover:text-inherit'
> >
<Icon icon='mdi:delete-outline' width={16} height={16} className='justify-start text-sm' /> <Icon
icon='mdi:delete-outline'
width={16}
height={16}
className='justify-start text-sm'
/>
Delete Delete
</Button> </Button>
</div> </div>
@@ -96,7 +101,9 @@ const ProductCategoryTable = () => {
const deleteModal = useModal(); const deleteModal = useModal();
const [selectedProductCategory, setSelectedProductCategory] = useState<ProductCategory | undefined>(undefined); const [selectedProductCategory, setSelectedProductCategory] = useState<
ProductCategory | undefined
>(undefined);
const [isDeleteLoading, setIsDeleteLoading] = useState(false); const [isDeleteLoading, setIsDeleteLoading] = useState(false);
const [sorting, setSorting] = useState<SortingState>([]); const [sorting, setSorting] = useState<SortingState>([]);
@@ -186,7 +193,7 @@ const ProductCategoryTable = () => {
} else { } else {
updateFilter('nameSort', isNameSorted.desc ? 'desc' : 'asc'); updateFilter('nameSort', isNameSorted.desc ? 'desc' : 'asc');
} }
}, [sorting]); }, [sorting, updateFilter]);
return ( return (
<> <>
@@ -221,18 +228,30 @@ const ProductCategoryTable = () => {
</div> </div>
</div> </div>
<Table<ProductCategory> <Table<ProductCategory>
data={isResponseSuccess(productCategories) ? productCategories?.data : []} data={
isResponseSuccess(productCategories) ? productCategories?.data : []
}
columns={productCategoryColumns} columns={productCategoryColumns}
pageSize={tableFilterState.pageSize} pageSize={tableFilterState.pageSize}
page={isResponseSuccess(productCategories) ? productCategories?.meta?.page : 0} page={
totalItems={isResponseSuccess(productCategories) ? productCategories?.meta?.total_results : 0} isResponseSuccess(productCategories)
? productCategories?.meta?.page
: 0
}
totalItems={
isResponseSuccess(productCategories)
? productCategories?.meta?.total_results
: 0
}
onPageChange={setPage} onPageChange={setPage}
isLoading={isLoading} isLoading={isLoading}
sorting={sorting} sorting={sorting}
setSorting={setSorting} setSorting={setSorting}
className={{ className={{
containerClassName: cn({ containerClassName: cn({
'mb-20': isResponseSuccess(productCategories) && productCategories?.data?.length === 0, 'mb-20':
isResponseSuccess(productCategories) &&
productCategories?.data?.length === 0,
}), }),
tableWrapperClassName: 'overflow-x-auto min-h-full!', tableWrapperClassName: 'overflow-x-auto min-h-full!',
tableClassName: 'font-inter w-full table-auto min-h-full!', tableClassName: 'font-inter w-full table-auto min-h-full!',
@@ -263,4 +282,4 @@ const ProductCategoryTable = () => {
); );
}; };
export default ProductCategoryTable; export default ProductCategoryTable;
@@ -116,7 +116,9 @@ const ProductsTable = () => {
); );
const deleteModal = useModal(); const deleteModal = useModal();
const [selectedProduct, setSelectedProduct] = useState<Product | undefined>(undefined); const [selectedProduct, setSelectedProduct] = useState<Product | undefined>(
undefined
);
const [isDeleteLoading, setIsDeleteLoading] = useState(false); const [isDeleteLoading, setIsDeleteLoading] = useState(false);
const [sorting, setSorting] = useState<SortingState>([]); const [sorting, setSorting] = useState<SortingState>([]);
@@ -153,12 +155,14 @@ const ProductsTable = () => {
{ {
accessorKey: 'product_price', accessorKey: 'product_price',
header: 'Harga Produk', header: 'Harga Produk',
cell: (props) => props.row.original.product_price?.toLocaleString() ?? '-', cell: (props) =>
props.row.original.product_price?.toLocaleString() ?? '-',
}, },
{ {
accessorKey: 'selling_price', accessorKey: 'selling_price',
header: 'Harga Jual', header: 'Harga Jual',
cell: (props) => props.row.original.selling_price?.toLocaleString() ?? '-', cell: (props) =>
props.row.original.selling_price?.toLocaleString() ?? '-',
}, },
{ {
accessorKey: 'tax', accessorKey: 'tax',
@@ -261,13 +265,15 @@ const ProductsTable = () => {
const nameSortFilter = sorting.find((sortItem) => sortItem.id === 'name'); const nameSortFilter = sorting.find((sortItem) => sortItem.id === 'name');
const skuSortFilter = sorting.find((sortItem) => sortItem.id === 'sku'); const skuSortFilter = sorting.find((sortItem) => sortItem.id === 'sku');
const brandSortFilter = sorting.find((sortItem) => sortItem.id === 'brand'); const brandSortFilter = sorting.find((sortItem) => sortItem.id === 'brand');
const categorySortFilter = sorting.find((sortItem) => sortItem.id === 'product_category'); const categorySortFilter = sorting.find(
(sortItem) => sortItem.id === 'product_category'
);
updateSortingFilter('nameSort', nameSortFilter); updateSortingFilter('nameSort', nameSortFilter);
updateSortingFilter('skuSort', skuSortFilter); updateSortingFilter('skuSort', skuSortFilter);
updateSortingFilter('brandSort', brandSortFilter); updateSortingFilter('brandSort', brandSortFilter);
updateSortingFilter('categorySort', categorySortFilter); updateSortingFilter('categorySort', categorySortFilter);
}, [sorting]); }, [sorting, updateSortingFilter]);
return ( return (
<> <>
@@ -347,4 +353,4 @@ const ProductsTable = () => {
); );
}; };
export default ProductsTable; export default ProductsTable;
@@ -192,7 +192,7 @@ const UomsTable = () => {
} else { } else {
updateFilter('nameSort', isNameSorted.desc ? 'desc' : 'asc'); updateFilter('nameSort', isNameSorted.desc ? 'desc' : 'asc');
} }
}, [sorting]); }, [sorting, updateFilter]);
return ( return (
<> <>
@@ -270,7 +270,7 @@ const WarehousesTable = () => {
updateSortingFilter('areaSort', areaSortFilter); updateSortingFilter('areaSort', areaSortFilter);
updateSortingFilter('locationSort', locationSortFilter); updateSortingFilter('locationSort', locationSortFilter);
updateSortingFilter('kandangSort', kandangSortFilter); updateSortingFilter('kandangSort', kandangSortFilter);
}, [sorting]); }, [sorting, updateSortingFilter]);
return ( return (
<> <>