mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: removed old auth wrapper and replaced the imports with new auth wrapper
This commit is contained in:
parent
e592c0015d
commit
2e8453bd69
@ -1,4 +1,3 @@
|
||||
export * from "./user-wrapper";
|
||||
export * from "./workspace-wrapper";
|
||||
export * from "./project-wrapper";
|
||||
export * from "./admin-wrapper";
|
||||
|
@ -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}</>;
|
||||
});
|
@ -1,8 +1,9 @@
|
||||
import { FC, ReactNode } from "react";
|
||||
// layout
|
||||
import { CommandPalette } from "@/components/command-palette";
|
||||
import { UserAuthWrapper } from "@/layouts/auth-layout";
|
||||
import { ProfileLayoutSidebar } from "@/layouts/settings-layout";
|
||||
// wrappers
|
||||
import { AuthenticationWrapper } from "@/lib/wrappers";
|
||||
// components
|
||||
|
||||
interface IProfileSettingsLayout {
|
||||
@ -16,7 +17,7 @@ export const ProfileSettingsLayout: FC<IProfileSettingsLayout> = (props) => {
|
||||
return (
|
||||
<>
|
||||
<CommandPalette />
|
||||
<UserAuthWrapper>
|
||||
<AuthenticationWrapper>
|
||||
<div className="relative flex h-screen w-full overflow-hidden">
|
||||
<ProfileLayoutSidebar />
|
||||
<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>
|
||||
</main>
|
||||
</div>
|
||||
</UserAuthWrapper>
|
||||
</AuthenticationWrapper>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
@ -10,11 +10,12 @@ import { PageHead } from "@/components/core";
|
||||
import { CreateWorkspaceForm } from "@/components/workspace";
|
||||
import { useUser } from "@/hooks/store";
|
||||
// layouts
|
||||
import { UserAuthWrapper } from "@/layouts/auth-layout";
|
||||
import DefaultLayout from "@/layouts/default-layout";
|
||||
// components
|
||||
// images
|
||||
import { NextPageWithLayout } from "@/lib/types";
|
||||
// wrappers
|
||||
import { AuthenticationWrapper } from "@/lib/wrappers";
|
||||
import BlackHorizontalLogo from "public/plane-logos/black-horizontal-with-blue-logo.svg";
|
||||
import WhiteHorizontalLogo from "public/plane-logos/white-horizontal-with-blue-logo.svg";
|
||||
// types
|
||||
@ -79,9 +80,9 @@ const CreateWorkspacePage: NextPageWithLayout = observer(() => {
|
||||
|
||||
CreateWorkspacePage.getLayout = function getLayout(page: ReactElement) {
|
||||
return (
|
||||
<UserAuthWrapper>
|
||||
<AuthenticationWrapper>
|
||||
<DefaultLayout>{page} </DefaultLayout>
|
||||
</UserAuthWrapper>
|
||||
</AuthenticationWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -22,10 +22,11 @@ import { ROLE } from "@/constants/workspace";
|
||||
import { truncateText } from "@/helpers/string.helper";
|
||||
import { getUserRole } from "@/helpers/user.helper";
|
||||
import { useEventTracker, useUser, useWorkspace } from "@/hooks/store";
|
||||
import { UserAuthWrapper } from "@/layouts/auth-layout";
|
||||
import DefaultLayout from "@/layouts/default-layout";
|
||||
// types
|
||||
import { NextPageWithLayout } from "@/lib/types";
|
||||
// wrappers
|
||||
import { AuthenticationWrapper } from "@/lib/wrappers";
|
||||
// services
|
||||
import { UserService } from "@/services/user.service";
|
||||
import { WorkspaceService } from "@/services/workspace.service";
|
||||
@ -238,9 +239,9 @@ const UserInvitationsPage: NextPageWithLayout = observer(() => {
|
||||
|
||||
UserInvitationsPage.getLayout = function getLayout(page: ReactElement) {
|
||||
return (
|
||||
<UserAuthWrapper>
|
||||
<AuthenticationWrapper>
|
||||
<DefaultLayout>{page}</DefaultLayout>
|
||||
</UserAuthWrapper>
|
||||
</AuthenticationWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -12,13 +12,16 @@ import { InviteMembers, CreateOrJoinWorkspaces, ProfileSetup } from "@/component
|
||||
// constants
|
||||
import { USER_ONBOARDING_COMPLETED } from "@/constants/event-tracker";
|
||||
import { USER_WORKSPACES_LIST } from "@/constants/fetch-keys";
|
||||
// helpers
|
||||
import { EPageTypes } from "@/helpers/authentication.helper";
|
||||
// hooks
|
||||
import { useUser, useWorkspace, useUserProfile, useEventTracker } from "@/hooks/store";
|
||||
// layouts
|
||||
import { UserAuthWrapper } from "@/layouts/auth-layout";
|
||||
import DefaultLayout from "@/layouts/default-layout";
|
||||
// lib types
|
||||
import { NextPageWithLayout } from "@/lib/types";
|
||||
// wrappers
|
||||
import { AuthenticationWrapper } from "@/lib/wrappers";
|
||||
// services
|
||||
import { WorkspaceService } from "@/services/workspace.service";
|
||||
|
||||
@ -183,9 +186,9 @@ const OnboardingPage: NextPageWithLayout = observer(() => {
|
||||
|
||||
OnboardingPage.getLayout = function getLayout(page: ReactElement) {
|
||||
return (
|
||||
<UserAuthWrapper>
|
||||
<AuthenticationWrapper pageType={EPageTypes.ONBOARDING}>
|
||||
<DefaultLayout>{page}</DefaultLayout>
|
||||
</UserAuthWrapper>
|
||||
</AuthenticationWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user