diff --git a/src/components/pages/finance/FinanceTable.tsx b/src/components/pages/finance/FinanceTable.tsx index 505e411f..c6584b96 100644 --- a/src/components/pages/finance/FinanceTable.tsx +++ b/src/components/pages/finance/FinanceTable.tsx @@ -1,4 +1,10 @@ -import { ChangeEventHandler, useMemo, useState } from 'react'; +import { + ChangeEventHandler, + useEffect, + useMemo, + useRef, + useState, +} from 'react'; import { CellContext } from '@tanstack/react-table'; import { useSearchParams } from 'next/navigation'; import useSWR from 'swr'; @@ -33,6 +39,7 @@ import RequirePermission from '@/components/helper/RequirePermission'; import { Icon } from '@iconify/react'; import RowDropdownOptions from '@/components/table/RowDropdownOptions'; import RowCollapseOptions from '@/components/table/RowCollapseOptions'; +import { useUiStore } from '@/stores/ui/ui.store'; const RowOptionsMenu = ({ type = 'dropdown', @@ -133,6 +140,9 @@ const RowOptionsMenu = ({ }; const FinanceTable = () => { + const { searchValue, setSearchValue, resetSearchValue } = useUiStore(); + const previousPathRef = useRef(null); + const { state: tableFilterState, updateFilter, @@ -141,7 +151,7 @@ const FinanceTable = () => { toQueryString: getTableFilterQueryString, } = useTableFilter({ initial: { - search: '', + search: searchValue, transactionType: '', bankId: '', customerId: '', @@ -167,7 +177,7 @@ const FinanceTable = () => { const [searchParams, setSearchParams] = useSearchParams(); const deleteModal = useModal(); const [pendingFilters, setPendingFilters] = useState({ - search: '', + search: searchValue, transactionType: '', bankId: '', customerId: '', @@ -296,6 +306,7 @@ const FinanceTable = () => { }; const submitFilterHandler = () => { updateFilter('search', pendingFilters.search); + setSearchValue(pendingFilters.search); updateFilter('transactionType', pendingFilters.transactionType); updateFilter('bankId', pendingFilters.bankId); updateFilter('customerId', pendingFilters.customerId); @@ -324,6 +335,7 @@ const FinanceTable = () => { setPendingFilters(emptyFilters); updateFilter('search', ''); + resetSearchValue(); updateFilter('transactionType', ''); updateFilter('bankId', ''); updateFilter('customerId', ''); @@ -447,6 +459,26 @@ const FinanceTable = () => { }, ]; }, []); + + useEffect(() => { + // Store current path on mount + previousPathRef.current = window.location.pathname; + + return () => { + const currentPath = window.location.pathname; + + // if both paths are within /finance module + const isCurrentPathFinance = currentPath.includes('/finance'); + const isPreviousPathFinance = + previousPathRef.current?.includes('/finance'); + + // reset if we outside finance module entirely + if (isPreviousPathFinance && !isCurrentPathFinance) { + resetSearchValue(); + } + }; + }, [resetSearchValue]); + return (
diff --git a/src/components/pages/finance/add/FormFinanceAdd.tsx b/src/components/pages/finance/add/FormFinanceAdd.tsx index 4189521e..29e311cc 100644 --- a/src/components/pages/finance/add/FormFinanceAdd.tsx +++ b/src/components/pages/finance/add/FormFinanceAdd.tsx @@ -251,7 +251,11 @@ const FormFinanceAdd = ({ } required isClearable - isDisabled={!formik.values.party_type_option?.value} + isDisabled={ + !formik.values.party_type_option?.value || + (type === 'edit' && + formik.values.party_type_option.value == 'SUPPLIER') + } /> Submit diff --git a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx index cb46c0e1..a63caa94 100644 --- a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx +++ b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx @@ -396,7 +396,7 @@ const FormFinanceAddInitialBalance = ({ diff --git a/src/components/pages/finance/add/injection/FormFinanceInjection.tsx b/src/components/pages/finance/add/injection/FormFinanceInjection.tsx index d685619d..ff49005c 100644 --- a/src/components/pages/finance/add/injection/FormFinanceInjection.tsx +++ b/src/components/pages/finance/add/injection/FormFinanceInjection.tsx @@ -257,7 +257,7 @@ const FormFinanceInjection = ({