mirror of
https://github.com/aykhans/slash-e.git
synced 2025-09-09 18:40:44 +00:00
chore: update admin signup journey
This commit is contained in:
42
frontend/web/src/layouts/CommonContextProvider.tsx
Normal file
42
frontend/web/src/layouts/CommonContextProvider.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { createContext, useContext, useEffect, useState } from "react";
|
||||
import { useUserStore, useWorkspaceStore } from "@/stores";
|
||||
|
||||
interface Context {}
|
||||
|
||||
const CommonContext = createContext<Context>({});
|
||||
|
||||
const CommonContextProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const workspaceStore = useWorkspaceStore();
|
||||
const userStore = useUserStore();
|
||||
const [commonContext, setCommonContext] = useState<Context>({});
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
await Promise.all([workspaceStore.fetchWorkspaceProfile(), workspaceStore.fetchWorkspaceSetting(), userStore.fetchCurrentUser()]);
|
||||
} catch (error) {
|
||||
// Do nothing.
|
||||
}
|
||||
setInitialized(true);
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<CommonContext.Provider
|
||||
value={{
|
||||
...commonContext,
|
||||
setLocale: (locale: string) => setCommonContext({ ...commonContext, locale }),
|
||||
setAppearance: (appearance: string) => setCommonContext({ ...commonContext, appearance }),
|
||||
}}
|
||||
>
|
||||
{!initialized ? null : <>{children}</>}
|
||||
</CommonContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useCommonContext = () => {
|
||||
return useContext(CommonContext);
|
||||
};
|
||||
|
||||
export default CommonContextProvider;
|
Reference in New Issue
Block a user