From a45ce4cdfc7f7b66ef2a5bfed7c7e616407f2127 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 20 Mar 2024 18:09:46 +0530 Subject: [PATCH] remove cached file --- ui/src/contexts/app.tsx | 82 ----------------------------------------- 1 file changed, 82 deletions(-) delete mode 100644 ui/src/contexts/app.tsx diff --git a/ui/src/contexts/app.tsx b/ui/src/contexts/app.tsx deleted file mode 100644 index 65dac5a86..000000000 --- a/ui/src/contexts/app.tsx +++ /dev/null @@ -1,82 +0,0 @@ -import * as R from "ramda"; -import { PropsWithChildren, createContext, useEffect, useState } from "react"; -import { V1Beta1Organization } from "@raystack/frontier"; -import { useFrontier } from "@raystack/frontier/react"; - -type OrgMap = Record; - -interface AppContextValue { - orgMap: OrgMap; - isAdmin: boolean; - isLoading: boolean; - organizations: V1Beta1Organization[]; -} - -const AppContextDefaultValue = { - orgMap: {}, - isAdmin: false, - isLoading: false, - organizations: [], -}; - -export const AppContext = createContext( - AppContextDefaultValue -); - -export const AppConextProvider: React.FC = function ({ - children, -}) { - const { client, user, isUserLoading } = useFrontier(); - const [isOrgListLoading, setIsOrgListLoading] = useState(false); - const [isAdmin, setIsAdmin] = useState(false); - const [enabledOrganizations, setEnabledOrganizations] = useState< - V1Beta1Organization[] - >([]); - const [disabledOrganizations, setDisabledOrganizations] = useState< - V1Beta1Organization[] - >([]); - - const isUserEmpty = R.either(R.isEmpty, R.isNil)(user); - - useEffect(() => { - async function getOrganizations() { - setIsOrgListLoading(true); - try { - const [orgResp, disabledOrgResp] = await Promise.all([ - client?.adminServiceListAllOrganizations(), - client?.adminServiceListAllOrganizations({ state: "disabled" }), - ]); - if (orgResp?.data?.organizations) { - setEnabledOrganizations(orgResp?.data?.organizations); - } - if (disabledOrgResp?.data?.organizations) { - setDisabledOrganizations(disabledOrgResp?.data?.organizations); - } - setIsAdmin(true); - } catch (error) { - setIsAdmin(false); - } finally { - setIsOrgListLoading(false); - } - } - - if (!isUserEmpty) { - getOrganizations(); - } - }, [client, isUserEmpty]); - - const isLoading = isOrgListLoading || isUserLoading; - const organizations = [...enabledOrganizations, ...disabledOrganizations]; - - const orgMap = organizations.reduce((acc, org) => { - const orgId = org?.id || ""; - if (orgId) acc[orgId] = org; - return acc; - }, {} as OrgMap); - - return ( - - {children} - - ); -};