From 40903d51f6266318523866ef736bb8cc376e0bdf Mon Sep 17 00:00:00 2001 From: panteliselef Date: Wed, 7 Feb 2024 12:17:21 +0200 Subject: [PATCH 1/2] fix(shared): Return api errors from organization hooks --- .changeset/sixty-lions-obey.md | 5 +++++ packages/shared/src/react/hooks/useOrganization.tsx | 1 + packages/shared/src/react/hooks/useOrganizationList.tsx | 1 + packages/shared/src/react/hooks/usePagesOrInfinite.ts | 4 +++- packages/shared/src/react/types.ts | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/sixty-lions-obey.md diff --git a/.changeset/sixty-lions-obey.md b/.changeset/sixty-lions-obey.md new file mode 100644 index 0000000000..da7d6a614d --- /dev/null +++ b/.changeset/sixty-lions-obey.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': patch +--- + +Add `error` for each paginated property return by `useOrganization` and `useOrganizationList` hooks. diff --git a/packages/shared/src/react/hooks/useOrganization.tsx b/packages/shared/src/react/hooks/useOrganization.tsx index 7e7e463257..b049c6759e 100644 --- a/packages/shared/src/react/hooks/useOrganization.tsx +++ b/packages/shared/src/react/hooks/useOrganization.tsx @@ -94,6 +94,7 @@ type UseOrganization = ( const undefinedPaginatedResource = { data: undefined, count: undefined, + error: undefined, isLoading: false, isFetching: false, isError: false, diff --git a/packages/shared/src/react/hooks/useOrganizationList.tsx b/packages/shared/src/react/hooks/useOrganizationList.tsx index 2f879a92d3..65a7deeb0a 100644 --- a/packages/shared/src/react/hooks/useOrganizationList.tsx +++ b/packages/shared/src/react/hooks/useOrganizationList.tsx @@ -39,6 +39,7 @@ type UseOrganizationListParams = { const undefinedPaginatedResource = { data: undefined, count: undefined, + error: undefined, isLoading: false, isFetching: false, isError: false, diff --git a/packages/shared/src/react/hooks/usePagesOrInfinite.ts b/packages/shared/src/react/hooks/usePagesOrInfinite.ts index c44d097ce0..13d41506c8 100644 --- a/packages/shared/src/react/hooks/usePagesOrInfinite.ts +++ b/packages/shared/src/react/hooks/usePagesOrInfinite.ts @@ -194,7 +194,8 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options, const isLoading = triggerInfinite ? swrInfiniteIsLoading : swrIsLoading; const isFetching = triggerInfinite ? swrInfiniteIsValidating : swrIsValidating; - const isError = !!(triggerInfinite ? swrInfiniteError : swrError); + const error = (triggerInfinite ? swrInfiniteError : swrError) ?? null; + const isError = !!error; /** * Helpers */ @@ -227,6 +228,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options, return { data, count, + error, isLoading, isFetching, isError, diff --git a/packages/shared/src/react/types.ts b/packages/shared/src/react/types.ts index 7a8abff128..f6704a8964 100644 --- a/packages/shared/src/react/types.ts +++ b/packages/shared/src/react/types.ts @@ -1,5 +1,7 @@ import type { ClerkPaginatedResponse } from '@clerk/types'; +import type { ClerkAPIResponseError } from '../error'; + export type ValueOrSetter = (size: T | ((_size: T) => T)) => void; export type CacheSetter = ( @@ -9,6 +11,7 @@ export type CacheSetter = ( export type PaginatedResources = { data: T[]; count: number; + error: ClerkAPIResponseError | null; isLoading: boolean; isFetching: boolean; isError: boolean; From 42a467eb89e6b8d6af8036e5674f37786dba274d Mon Sep 17 00:00:00 2001 From: panteliselef Date: Thu, 8 Feb 2024 16:09:44 +0200 Subject: [PATCH 2/2] fix(shared): Update changeset to minor --- .changeset/sixty-lions-obey.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/sixty-lions-obey.md b/.changeset/sixty-lions-obey.md index da7d6a614d..553188fc99 100644 --- a/.changeset/sixty-lions-obey.md +++ b/.changeset/sixty-lions-obey.md @@ -1,5 +1,5 @@ --- -'@clerk/shared': patch +'@clerk/shared': minor --- Add `error` for each paginated property return by `useOrganization` and `useOrganizationList` hooks.