1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 05:45:22 +02:00

refactor(auth): cache user data [EE-4935] (#8380)

This commit is contained in:
Chaim Lev-Ari 2023-01-26 07:40:05 +05:30 committed by GitHub
parent a748e15c16
commit 00bbf4ac63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 46 deletions

View file

@ -2,6 +2,8 @@ import { ComponentType } from 'react';
import { UserProvider } from '@/react/hooks/useUser';
import { withReactQuery } from './withReactQuery';
export function withCurrentUser<T>(
WrappedComponent: ComponentType<T>
): ComponentType<T> {
@ -12,13 +14,14 @@ export function withCurrentUser<T>(
function WrapperComponent(props: T) {
return (
<UserProvider>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<WrappedComponent {...props} />
</UserProvider>
);
}
WrapperComponent.displayName = displayName;
WrapperComponent.displayName = `withCurrentUser(${displayName})`;
return WrapperComponent;
// User provider makes a call to the API to get the current user.
// We need to wrap it with React Query to make that call.
return withReactQuery(WrapperComponent);
}

View file

@ -10,13 +10,12 @@ export function withI18nSuspense<T>(
function WrapperComponent(props: T) {
return (
<Suspense fallback="Loading translations...">
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<WrappedComponent {...props} />
</Suspense>
);
}
WrapperComponent.displayName = displayName;
WrapperComponent.displayName = `withI18nSuspense(${displayName})`;
return WrapperComponent;
}

View file

@ -14,13 +14,12 @@ export function withReactQuery<T>(
function WrapperComponent(props: T) {
return (
<QueryClientProvider client={queryClient}>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<WrappedComponent {...props} />
</QueryClientProvider>
);
}
WrapperComponent.displayName = displayName;
WrapperComponent.displayName = `withReactQuery(${displayName})`;
return WrapperComponent;
}

View file

@ -11,13 +11,12 @@ export function withUIRouter<T>(
function WrapperComponent(props: T) {
return (
<UIRouterContextComponent>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<WrappedComponent {...props} />
</UIRouterContextComponent>
);
}
WrapperComponent.displayName = displayName;
WrapperComponent.displayName = `withUIRouter(${displayName})`;
return WrapperComponent;
}