Prevent admin from resetting their own role.

This commit is contained in:
Mike Cao 2024-02-16 10:22:18 -08:00
parent 2e871af05b
commit f25cd93012
10 changed files with 66 additions and 31 deletions

View file

@ -0,0 +1,24 @@
import { createContext, ReactNode, useEffect } from 'react';
import { useModified, useUser } from 'components/hooks';
import { Loading } from 'react-basics';
export const UserContext = createContext(null);
export function UserProvider({ userId, children }: { userId: string; children: ReactNode }) {
const { modified } = useModified(`user:${userId}`);
const { data: user, isFetching, isLoading, refetch } = useUser(userId);
useEffect(() => {
if (modified) {
refetch();
}
}, [modified]);
if (isFetching && isLoading) {
return <Loading position="page" />;
}
return <UserContext.Provider value={user}>{children}</UserContext.Provider>;
}
export default UserProvider;