From 4e00e401e00a824d4fd472c0cbc0eaf4209bdaeb Mon Sep 17 00:00:00 2001 From: Keegan Potgieter Date: Tue, 12 Nov 2024 18:36:35 +1100 Subject: [PATCH] fix: remove duplicate initialised dependency --- .changeset/fresh-cooks-punch.md | 18 ++++++++++++++++++ src/context/subi-connect.tsx | 2 +- src/context/table/table-context.tsx | 6 +++--- src/hooks/use-account-payroll.tsx | 2 +- src/hooks/use-company.tsx | 2 ++ src/hooks/use-subi-connect-query.ts | 2 ++ 6 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .changeset/fresh-cooks-punch.md diff --git a/.changeset/fresh-cooks-punch.md b/.changeset/fresh-cooks-punch.md new file mode 100644 index 0000000..df1a54b --- /dev/null +++ b/.changeset/fresh-cooks-punch.md @@ -0,0 +1,18 @@ +--- +'@subifinancial/subi-connect': patch +--- + +### Bug Fixes + +- Fixed dependency array in `SubiConnectProvider` by removing duplicate `initialised` dependency +- Updated `DataTableProvider` to use `useSubiConnectQuery` instead of raw `useQuery` +- Removed unnecessary `async` wrapper in `useAccountPayrollSystem` query function +- Improved code formatting and readability in hooks with consistent spacing + +### Internal Changes + +- Refactored query implementation in table context to use `useSubiConnectQuery` +- Added proper type handling for query options in `useSubiConnectQuery` +- Enhanced query key organisation in company-related hooks + + diff --git a/src/context/subi-connect.tsx b/src/context/subi-connect.tsx index e5f2ba7..188c128 100644 --- a/src/context/subi-connect.tsx +++ b/src/context/subi-connect.tsx @@ -157,7 +157,7 @@ export const SubiConnectProvider = ({ cleanup, connectionService, } satisfies SubiConnectContext; - }, [isLoading, initialised, cleanup, connectionService, initialised.current]); + }, [isLoading, cleanup, connectionService, initialised.current]); return ( diff --git a/src/context/table/table-context.tsx b/src/context/table/table-context.tsx index 38c359b..0bddba0 100644 --- a/src/context/table/table-context.tsx +++ b/src/context/table/table-context.tsx @@ -2,6 +2,7 @@ import { useSubiConnectContext } from '../subi-connect'; import useSearchParams, { FILTER_SEARCH_PARAM_PREFIX, } from '@/hooks/internal/use-serach-params'; +import { useSubiConnectQuery } from '@/hooks/use-subi-connect-query'; import { createNestedObjectFromString } from '@/lib/utils'; import { SUBI_CONNECT_QUERY_KEY } from '@/types'; import type { @@ -14,7 +15,6 @@ import { type QueryKey, type UseQueryOptions, type UseQueryResult, - useQuery, } from '@tanstack/react-query'; import React from 'react'; @@ -191,10 +191,10 @@ export const DataTableProvider = ({ }); }; - const query = useQuery({ - ...queryOptions, + const query = useSubiConnectQuery({ queryKey: queryKey, queryFn: queryFunction, + ...queryOptions, }); const value = React.useMemo( diff --git a/src/hooks/use-account-payroll.tsx b/src/hooks/use-account-payroll.tsx index ee269c2..89ee41e 100644 --- a/src/hooks/use-account-payroll.tsx +++ b/src/hooks/use-account-payroll.tsx @@ -33,7 +33,7 @@ export const useAccountPayrollSystem = ( ); const queryFn = React.useCallback( - async () => getAccountPayroll(connectionService)({ payroll }), + () => getAccountPayroll(connectionService)({ payroll }), [payroll, connectionService], ); diff --git a/src/hooks/use-company.tsx b/src/hooks/use-company.tsx index cdee724..1c687bd 100644 --- a/src/hooks/use-company.tsx +++ b/src/hooks/use-company.tsx @@ -29,6 +29,7 @@ export const useCompany = (options?: UseCompanyOptions) => { BASE_COMPANY_QUERY_KEY, 'detail', ] as const; + return useSubiConnectQuery({ queryKey: queryKey, queryFn: getCompany(connectionService), @@ -53,6 +54,7 @@ export const useCompanyPayrollIntegrations = ( { context: connectionService.getContext() }, BASE_COMPANY_PAYROLL_INTEGRATIONS_QUERY_KEY, ] as const; + return useSubiConnectQuery({ queryKey: queryKey, queryFn: getCompanyPayrollIntegrations(connectionService), diff --git a/src/hooks/use-subi-connect-query.ts b/src/hooks/use-subi-connect-query.ts index b27c69a..f110e62 100644 --- a/src/hooks/use-subi-connect-query.ts +++ b/src/hooks/use-subi-connect-query.ts @@ -14,7 +14,9 @@ export function useSubiConnectQuery< TQueryKey extends QueryKey = QueryKey, >(options: UseQueryOptions) { const { initialised } = useSubiConnectContext(); + const { enabled, ...queryOptions } = options; + return useQuery({ ...queryOptions, enabled: initialised && enabled,