/* eslint-disable no-nested-ternary */ /* eslint-disable no-unexpected-multiline */ /* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable vars-on-top */ /* eslint-disable no-var */ /* eslint-disable func-names */ import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import Link from "next/link"; import { useRouter } from "next/router"; import { faGithub, faSlack } from "@fortawesome/free-brands-svg-icons"; import { faAngleDown, faArrowLeft, faArrowUpRightFromSquare, faBook, faCheck, faEnvelope, faInfinity, faInfo, faMobile, faPlus, faQuestion } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu"; import { tempLocalStorage } from "@app/components/utilities/checks/tempLocalStorage"; import SecurityClient from "@app/components/utilities/SecurityClient"; import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, Menu, MenuItem } from "@app/components/v2"; import { useOrganization, useSubscription, useUser, useWorkspace } from "@app/context"; import { usePopUp, useToggle } from "@app/hooks"; import { useGetOrgTrialUrl, useLogoutUser, useSelectOrganization } from "@app/hooks/api"; import { MfaMethod } from "@app/hooks/api/auth/types"; import { AuthMethod } from "@app/hooks/api/users/types"; import { ProjectType } from "@app/hooks/api/workspace/types"; import { InsecureConnectionBanner } from "@app/layouts/AppLayout/components/InsecureConnectionBanner"; import { ProjectSelect } from "@app/layouts/AppLayout/components/ProjectSelect"; import { navigateUserToOrg } from "@app/views/Login/Login.utils"; import { Mfa } from "@app/views/Login/Mfa"; import { CreateOrgModal } from "@app/views/Org/components"; import { ProjectSidebarItem } from "./components/ProjectSidebarItems"; import { WishForm } from "./components/WishForm/WishForm"; interface LayoutProps { children: React.ReactNode; } const supportOptions = [ [ , "Support Forum", "https://infisical.com/slack" ], [ , "Read Docs", "https://infisical.com/docs/documentation/getting-started/introduction" ], [ , "GitHub Issues", "https://github.com/Infisical/infisical/issues" ], [ , "Email Support", "mailto:support@infisical.com" ] ]; export const AppLayout = ({ children }: LayoutProps) => { const router = useRouter(); const { mutateAsync } = useGetOrgTrialUrl(); const { currentWorkspace } = useWorkspace(); const { orgs, currentOrg } = useOrganization(); const [shouldShowMfa, toggleShowMfa] = useToggle(false); const [requiredMfaMethod, setRequiredMfaMethod] = useState(MfaMethod.EMAIL); const [mfaSuccessCallback, setMfaSuccessCallback] = useState<() => void>(() => {}); const { user } = useUser(); const { subscription } = useSubscription(); const infisicalPlatformVersion = process.env.NEXT_PUBLIC_INFISICAL_PLATFORM_VERSION; const { popUp, handlePopUpToggle } = usePopUp(["createOrg"] as const); const { t } = useTranslation(); const { mutateAsync: selectOrganization } = useSelectOrganization(); const logout = useLogoutUser(); const logOutUser = async () => { try { console.log("Logging out..."); await logout.mutateAsync(); router.push("/login"); } catch (error) { console.error(error); } }; const changeOrg = async (orgId: string) => { const { token, isMfaEnabled, mfaMethod } = await selectOrganization({ organizationId: orgId }); if (isMfaEnabled) { SecurityClient.setMfaToken(token); if (mfaMethod) { setRequiredMfaMethod(mfaMethod); } toggleShowMfa.on(); setMfaSuccessCallback(() => () => changeOrg(orgId)); return; } await navigateUserToOrg(router, orgId); }; // TODO(akhilmhdh): This entire logic will be rechecked and will try to avoid // Placing the localstorage as much as possible // Wait till tony integrates the azure and its launched useEffect(() => { // Put a user in an org if they're not in one yet const putUserInOrg = async () => { if (tempLocalStorage("orgData.id") === "" && orgs?.[0]?.id) { localStorage.setItem("orgData.id", orgs?.[0]?.id); } }; putUserInOrg(); }, [router.query.id]); if (shouldShowMfa) { return (
toggleShowMfa.off()} />
); } return ( <>
{!window.isSecureContext && }
handlePopUpToggle("createOrg", false)} />
{children}

{` ${t("common.no-mobile")} `}

); };