From 4e47f4c1e2cfe6e2c2528870a0f32df25c5e70b6 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 17 Mar 2024 13:13:23 -0400 Subject: [PATCH] chore: Remove params requirement on fetchPage --- app/hooks/useRequest.ts | 10 +++++++++- app/scenes/Settings/Security.tsx | 2 +- app/stores/base/Store.ts | 2 +- server/models/AuthenticationProvider.ts | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/hooks/useRequest.ts b/app/hooks/useRequest.ts index 603cd4493..776d1fb83 100644 --- a/app/hooks/useRequest.ts +++ b/app/hooks/useRequest.ts @@ -16,10 +16,12 @@ type RequestResponse = { * A hook to make an API request and track its state within a component. * * @param requestFn The function to call to make the request, it should return a promise. + * @param makeRequestOnMount Whether to make the request when the component mounts. * @returns An object containing the request state and a function to start the request. */ export default function useRequest( - requestFn: () => Promise + requestFn: () => Promise, + makeRequestOnMount = false ): RequestResponse { const isMounted = useIsMounted(); const [data, setData] = React.useState(); @@ -48,5 +50,11 @@ export default function useRequest( return undefined; }, [requestFn, isMounted]); + React.useEffect(() => { + if (makeRequestOnMount) { + void request(); + } + }, [request, makeRequestOnMount]); + return { data, loading, error, request }; } diff --git a/app/scenes/Settings/Security.tsx b/app/scenes/Settings/Security.tsx index 473c936d5..d584d4463 100644 --- a/app/scenes/Settings/Security.tsx +++ b/app/scenes/Settings/Security.tsx @@ -41,7 +41,7 @@ function Security() { data: providers, loading, request, - } = useRequest(() => authenticationProviders.fetchPage({})); + } = useRequest(authenticationProviders.fetchPage); React.useEffect(() => { if (!providers && !loading) { diff --git a/app/stores/base/Store.ts b/app/stores/base/Store.ts index db7c1cb4c..e1b30fb62 100644 --- a/app/stores/base/Store.ts +++ b/app/stores/base/Store.ts @@ -262,7 +262,7 @@ export default abstract class Store { } @action - fetchPage = async (params: FetchPageParams | undefined): Promise => { + fetchPage = async (params?: FetchPageParams | undefined): Promise => { if (!this.actions.includes(RPCAction.List)) { throw new Error(`Cannot list ${this.modelName}`); } diff --git a/server/models/AuthenticationProvider.ts b/server/models/AuthenticationProvider.ts index 78d5c0efa..40531e3dc 100644 --- a/server/models/AuthenticationProvider.ts +++ b/server/models/AuthenticationProvider.ts @@ -74,7 +74,7 @@ class AuthenticationProvider extends Model< @Column(DataType.UUID) teamId: string; - @HasMany(() => UserAuthentication, "providerId") + @HasMany(() => UserAuthentication, "authenticationProviderId") userAuthentications: UserAuthentication[]; // instance methods