chore: removed old auth wrapper and replaced the imports with new auth wrapper

This commit is contained in:
gurusainath 2024-05-02 18:08:38 +05:30
parent e592c0015d
commit 2e8453bd69
6 changed files with 18 additions and 66 deletions

View File

@ -1,4 +1,3 @@
export * from "./user-wrapper";
export * from "./workspace-wrapper"; export * from "./workspace-wrapper";
export * from "./project-wrapper"; export * from "./project-wrapper";
export * from "./admin-wrapper"; export * from "./admin-wrapper";

View File

@ -1,53 +0,0 @@
import { FC, ReactNode } from "react";
import { observer } from "mobx-react";
import { useRouter } from "next/router";
import useSWR from "swr";
// import useSWRImmutable from "swr/immutable";
// ui
import { Spinner } from "@plane/ui";
// hooks
import { USER_WORKSPACES_LIST } from "@/constants/fetch-keys";
import { useUser, useUserProfile, useWorkspace } from "@/hooks/store";
export interface IUserAuthWrapper {
children: ReactNode;
}
export const UserAuthWrapper: FC<IUserAuthWrapper> = observer((props) => {
const { children } = props;
// store hooks
const { fetchCurrentUser, data: currentUser, error: currentUserError } = useUser();
const { fetchUserProfile } = useUserProfile();
const { fetchWorkspaces } = useWorkspace();
// router
const router = useRouter();
// fetching user information
const { error } = useSWR("CURRENT_USER_DETAILS", () => fetchCurrentUser(), {
shouldRetryOnError: false,
});
useSWR("CURRENT_USER_PROFILE_DETAILS", () => fetchUserProfile(), {
shouldRetryOnError: false,
});
// fetching all workspaces
const { isLoading: workspaceLoader } = useSWR(USER_WORKSPACES_LIST, () => fetchWorkspaces(), {
shouldRetryOnError: false,
});
if ((!currentUser && !currentUserError) || workspaceLoader) {
return (
<div className="grid h-screen place-items-center bg-custom-background-100 p-4">
<div className="flex flex-col items-center gap-3 text-center">
<Spinner />
</div>
</div>
);
}
if (error) {
const redirectTo = router.asPath;
router.push(`/?next_path=${redirectTo}`);
return null;
}
return <>{children}</>;
});

View File

@ -1,8 +1,9 @@
import { FC, ReactNode } from "react"; import { FC, ReactNode } from "react";
// layout // layout
import { CommandPalette } from "@/components/command-palette"; import { CommandPalette } from "@/components/command-palette";
import { UserAuthWrapper } from "@/layouts/auth-layout";
import { ProfileLayoutSidebar } from "@/layouts/settings-layout"; import { ProfileLayoutSidebar } from "@/layouts/settings-layout";
// wrappers
import { AuthenticationWrapper } from "@/lib/wrappers";
// components // components
interface IProfileSettingsLayout { interface IProfileSettingsLayout {
@ -16,7 +17,7 @@ export const ProfileSettingsLayout: FC<IProfileSettingsLayout> = (props) => {
return ( return (
<> <>
<CommandPalette /> <CommandPalette />
<UserAuthWrapper> <AuthenticationWrapper>
<div className="relative flex h-screen w-full overflow-hidden"> <div className="relative flex h-screen w-full overflow-hidden">
<ProfileLayoutSidebar /> <ProfileLayoutSidebar />
<main className="relative flex h-full w-full flex-col overflow-hidden bg-custom-background-100"> <main className="relative flex h-full w-full flex-col overflow-hidden bg-custom-background-100">
@ -24,7 +25,7 @@ export const ProfileSettingsLayout: FC<IProfileSettingsLayout> = (props) => {
<div className="h-full w-full overflow-hidden">{children}</div> <div className="h-full w-full overflow-hidden">{children}</div>
</main> </main>
</div> </div>
</UserAuthWrapper> </AuthenticationWrapper>
</> </>
); );
}; };

View File

@ -10,11 +10,12 @@ import { PageHead } from "@/components/core";
import { CreateWorkspaceForm } from "@/components/workspace"; import { CreateWorkspaceForm } from "@/components/workspace";
import { useUser } from "@/hooks/store"; import { useUser } from "@/hooks/store";
// layouts // layouts
import { UserAuthWrapper } from "@/layouts/auth-layout";
import DefaultLayout from "@/layouts/default-layout"; import DefaultLayout from "@/layouts/default-layout";
// components // components
// images // images
import { NextPageWithLayout } from "@/lib/types"; import { NextPageWithLayout } from "@/lib/types";
// wrappers
import { AuthenticationWrapper } from "@/lib/wrappers";
import BlackHorizontalLogo from "public/plane-logos/black-horizontal-with-blue-logo.svg"; import BlackHorizontalLogo from "public/plane-logos/black-horizontal-with-blue-logo.svg";
import WhiteHorizontalLogo from "public/plane-logos/white-horizontal-with-blue-logo.svg"; import WhiteHorizontalLogo from "public/plane-logos/white-horizontal-with-blue-logo.svg";
// types // types
@ -79,9 +80,9 @@ const CreateWorkspacePage: NextPageWithLayout = observer(() => {
CreateWorkspacePage.getLayout = function getLayout(page: ReactElement) { CreateWorkspacePage.getLayout = function getLayout(page: ReactElement) {
return ( return (
<UserAuthWrapper> <AuthenticationWrapper>
<DefaultLayout>{page} </DefaultLayout> <DefaultLayout>{page} </DefaultLayout>
</UserAuthWrapper> </AuthenticationWrapper>
); );
}; };

View File

@ -22,10 +22,11 @@ import { ROLE } from "@/constants/workspace";
import { truncateText } from "@/helpers/string.helper"; import { truncateText } from "@/helpers/string.helper";
import { getUserRole } from "@/helpers/user.helper"; import { getUserRole } from "@/helpers/user.helper";
import { useEventTracker, useUser, useWorkspace } from "@/hooks/store"; import { useEventTracker, useUser, useWorkspace } from "@/hooks/store";
import { UserAuthWrapper } from "@/layouts/auth-layout";
import DefaultLayout from "@/layouts/default-layout"; import DefaultLayout from "@/layouts/default-layout";
// types // types
import { NextPageWithLayout } from "@/lib/types"; import { NextPageWithLayout } from "@/lib/types";
// wrappers
import { AuthenticationWrapper } from "@/lib/wrappers";
// services // services
import { UserService } from "@/services/user.service"; import { UserService } from "@/services/user.service";
import { WorkspaceService } from "@/services/workspace.service"; import { WorkspaceService } from "@/services/workspace.service";
@ -238,9 +239,9 @@ const UserInvitationsPage: NextPageWithLayout = observer(() => {
UserInvitationsPage.getLayout = function getLayout(page: ReactElement) { UserInvitationsPage.getLayout = function getLayout(page: ReactElement) {
return ( return (
<UserAuthWrapper> <AuthenticationWrapper>
<DefaultLayout>{page}</DefaultLayout> <DefaultLayout>{page}</DefaultLayout>
</UserAuthWrapper> </AuthenticationWrapper>
); );
}; };

View File

@ -12,13 +12,16 @@ import { InviteMembers, CreateOrJoinWorkspaces, ProfileSetup } from "@/component
// constants // constants
import { USER_ONBOARDING_COMPLETED } from "@/constants/event-tracker"; import { USER_ONBOARDING_COMPLETED } from "@/constants/event-tracker";
import { USER_WORKSPACES_LIST } from "@/constants/fetch-keys"; import { USER_WORKSPACES_LIST } from "@/constants/fetch-keys";
// helpers
import { EPageTypes } from "@/helpers/authentication.helper";
// hooks // hooks
import { useUser, useWorkspace, useUserProfile, useEventTracker } from "@/hooks/store"; import { useUser, useWorkspace, useUserProfile, useEventTracker } from "@/hooks/store";
// layouts // layouts
import { UserAuthWrapper } from "@/layouts/auth-layout";
import DefaultLayout from "@/layouts/default-layout"; import DefaultLayout from "@/layouts/default-layout";
// lib types // lib types
import { NextPageWithLayout } from "@/lib/types"; import { NextPageWithLayout } from "@/lib/types";
// wrappers
import { AuthenticationWrapper } from "@/lib/wrappers";
// services // services
import { WorkspaceService } from "@/services/workspace.service"; import { WorkspaceService } from "@/services/workspace.service";
@ -183,9 +186,9 @@ const OnboardingPage: NextPageWithLayout = observer(() => {
OnboardingPage.getLayout = function getLayout(page: ReactElement) { OnboardingPage.getLayout = function getLayout(page: ReactElement) {
return ( return (
<UserAuthWrapper> <AuthenticationWrapper pageType={EPageTypes.ONBOARDING}>
<DefaultLayout>{page}</DefaultLayout> <DefaultLayout>{page}</DefaultLayout>
</UserAuthWrapper> </AuthenticationWrapper>
); );
}; };