chore: Remove params requirement on fetchPage

This commit is contained in:
Tom Moor
2024-03-17 13:13:23 -04:00
parent 8bd0aa43bc
commit 4e47f4c1e2
4 changed files with 12 additions and 4 deletions

View File

@ -16,10 +16,12 @@ type RequestResponse<T> = {
* 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<T = unknown>(
requestFn: () => Promise<T>
requestFn: () => Promise<T>,
makeRequestOnMount = false
): RequestResponse<T> {
const isMounted = useIsMounted();
const [data, setData] = React.useState<T>();
@ -48,5 +50,11 @@ export default function useRequest<T = unknown>(
return undefined;
}, [requestFn, isMounted]);
React.useEffect(() => {
if (makeRequestOnMount) {
void request();
}
}, [request, makeRequestOnMount]);
return { data, loading, error, request };
}

View File

@ -41,7 +41,7 @@ function Security() {
data: providers,
loading,
request,
} = useRequest(() => authenticationProviders.fetchPage({}));
} = useRequest(authenticationProviders.fetchPage);
React.useEffect(() => {
if (!providers && !loading) {

View File

@ -262,7 +262,7 @@ export default abstract class Store<T extends Model> {
}
@action
fetchPage = async (params: FetchPageParams | undefined): Promise<T[]> => {
fetchPage = async (params?: FetchPageParams | undefined): Promise<T[]> => {
if (!this.actions.includes(RPCAction.List)) {
throw new Error(`Cannot list ${this.modelName}`);
}

View File

@ -74,7 +74,7 @@ class AuthenticationProvider extends Model<
@Column(DataType.UUID)
teamId: string;
@HasMany(() => UserAuthentication, "providerId")
@HasMany(() => UserAuthentication, "authenticationProviderId")
userAuthentications: UserAuthentication[];
// instance methods