feat: renamed old frontend and fixed some minor bugs

This commit is contained in:
=
2025-01-06 14:56:49 +05:30
parent 8c902d7699
commit 54377a44d3
2577 changed files with 35240 additions and 35116 deletions
@@ -1,53 +1,14 @@
import { createContext, ReactNode, useContext, useMemo } from "react";
import { useSuspenseQuery } from "@tanstack/react-query";
import { useGetUser } from "@app/hooks/api";
import { User, UserEnc } from "@app/hooks/api/types";
type TUserContext = {
user: User & UserEnc;
isLoading: boolean;
};
const UserContext = createContext<TUserContext | null>(null);
type Props = {
children: ReactNode;
};
export const UserProvider = ({ children }: Props): JSX.Element => {
const { data, isLoading } = useGetUser();
// memorize the workspace details for the context
const value = useMemo<TUserContext>(() => {
return {
user: data!,
isLoading
};
}, [data, isLoading]);
if (isLoading) {
return (
<div className="flex h-screen w-screen items-center justify-center bg-bunker-800">
<img
src="/images/loading/loading.gif"
height={70}
width={120}
decoding="async"
loading="lazy"
alt="infisical loading indicator"
/>
</div>
);
}
return <UserContext.Provider value={value}>{children}</UserContext.Provider>;
};
import { userKeys } from "@app/hooks/api";
import { fetchUserDetails } from "@app/hooks/api/users/queries";
export const useUser = () => {
const ctx = useContext(UserContext);
if (!ctx) {
throw new Error("useUser has to be used within <UserContext.Provider>");
}
const { data: user } = useSuspenseQuery({
queryKey: userKeys.getUser,
queryFn: fetchUserDetails,
staleTime: Infinity
});
return ctx;
return { user };
};
+1 -1
View File
@@ -1 +1 @@
export { UserProvider, useUser } from "./UserContext";
export { useUser } from "./UserContext";