feat(FE): Integrate UI store and pathname handling in table components

This commit is contained in:
rstubryan
2026-03-04 11:06:53 +07:00
parent 6e7dfebacc
commit 18ebf75aa7
3 changed files with 44 additions and 2 deletions
@@ -1,6 +1,8 @@
'use client';
import { ChangeEventHandler, useEffect, useMemo, useState } from 'react';
import { usePathname } from 'next/navigation';
import { useUiStore } from '@/stores/ui/ui.store';
import useSWR from 'swr';
import {
CellContext,
@@ -151,6 +153,9 @@ const RowOptionsMenu = ({
};
const ExpensesTable = () => {
const { searchValue, setSearchValue, setTableState } = useUiStore();
const pathname = usePathname();
const {
state: tableFilterState,
updateFilter,
@@ -507,7 +512,16 @@ const ExpensesTable = () => {
setIsRejectLoading(false);
};
useEffect(() => {
updateFilter('search', searchValue);
}, [searchValue, updateFilter]);
useEffect(() => {
setTableState('expense-table', pathname);
}, [pathname, setTableState]);
const searchChangeHandler: ChangeEventHandler<HTMLInputElement> = (e) => {
setSearchValue(e.target.value);
updateFilter('search', e.target.value);
};