Merge pull request #7 from dakshesh14/main

fix: workspace invitation page not showing workspaces
This commit is contained in:
Vamsi Kurama 2022-11-28 17:46:22 +05:30 committed by GitHub
commit 0be30c0b78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 82 deletions

View File

@ -1,30 +1,32 @@
import React, { useEffect } from "react"; import React from "react";
// next // next
import type { NextPage } from "next"; import type { NextPage } from "next";
// axios configurations
import { setAxiosHeader } from "configuration/axios-configuration";
// redirect // redirect
import redirect from "lib/redirect"; import redirect from "lib/redirect";
const withAuthWrapper = (WrappedComponent: NextPage) => { const withAuth = (WrappedComponent: NextPage) => {
const Wrapper: NextPage<any> = (props) => { const Wrapper: NextPage<any> = (props) => {
useEffect(() => {
if (props?.tokenDetails && props?.tokenDetails?.access_token) {
setAxiosHeader(props.tokenDetails.access_token);
}
}, [props]);
return <WrappedComponent {...props} />; return <WrappedComponent {...props} />;
}; };
Wrapper.getInitialProps = async (ctx) => { Wrapper.getInitialProps = async (ctx) => {
const componentProps = const isServer = typeof window === "undefined";
WrappedComponent.getInitialProps &&
(await WrappedComponent.getInitialProps(ctx)); const cookies = isServer ? ctx?.req?.headers.cookie : document.cookie;
return { ...componentProps };
const token = cookies?.split("accessToken=")?.[1]?.split(";")?.[0];
if (!token) {
redirect(ctx, "/signin");
}
const pageProps =
WrappedComponent.getInitialProps && (await WrappedComponent.getInitialProps(ctx));
return { ...pageProps };
}; };
return Wrapper; return Wrapper;
}; };
export default withAuthWrapper; export default withAuth;

View File

@ -1,7 +1,8 @@
// next imports // next imports
import type { NextPageContext } from "next";
import Router from "next/router"; import Router from "next/router";
const redirect = (context: any, target: any) => { const redirect = (context: NextPageContext, target: any) => {
if (context.res) { if (context.res) {
// server // server
// 303: "See other" // 303: "See other"

View File

@ -5,8 +5,6 @@ import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
// swr // swr
import useSWR from "swr"; import useSWR from "swr";
// headless ui
import { Dialog, Transition } from "@headlessui/react";
// services // services
import workspaceService from "lib/services/workspace.service"; import workspaceService from "lib/services/workspace.service";
import userService from "lib/services/user.service"; import userService from "lib/services/user.service";
@ -14,19 +12,16 @@ import userService from "lib/services/user.service";
import useUser from "lib/hooks/useUser"; import useUser from "lib/hooks/useUser";
// constants // constants
import { USER_WORKSPACE_INVITATIONS } from "constants/api-routes"; import { USER_WORKSPACE_INVITATIONS } from "constants/api-routes";
// hoc
import withAuthWrapper from "lib/hoc/withAuthWrapper";
// layouts // layouts
import DefaultLayout from "layouts/DefaultLayout"; import DefaultLayout from "layouts/DefaultLayout";
// ui // ui
import { Button, Spinner } from "ui"; import { Button, Spinner } from "ui";
// types // types
import type { IWorkspaceInvitation } from "types"; import type { IWorkspaceInvitation } from "types";
import { ChartBarIcon, ChevronRightIcon, CubeIcon, PlusIcon } from "@heroicons/react/24/outline"; import { CubeIcon, PlusIcon } from "@heroicons/react/24/outline";
import { EmptySpace, EmptySpaceItem } from "ui/EmptySpace"; import { EmptySpace, EmptySpaceItem } from "ui/EmptySpace";
const OnBoard: NextPage = () => { const OnBoard: NextPage = () => {
const [canRedirect, setCanRedirect] = useState(true);
const router = useRouter(); const router = useRouter();
const { workspaces, mutateWorkspaces, user } = useUser(); const { workspaces, mutateWorkspaces, user } = useUser();
@ -63,28 +58,18 @@ const OnBoard: NextPage = () => {
console.log(res); console.log(res);
await mutate(); await mutate();
await mutateWorkspaces(); await mutateWorkspaces();
router.push("/workspace");
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
}); });
}; };
// useEffect(() => {
// if (!invitations) return;
// else
// invitations.forEach((invite) => {
// if (invite.accepted)
// setInvitationsRespond((prevData) => {
// return [...prevData, invite.workspace.id];
// });
// });
// }, [invitations, router, workspaces]);
useEffect(() => { useEffect(() => {
if (workspaces && workspaces.length === 0) { userService.updateUserOnBoard().then((response) => {
setCanRedirect(false); console.log(response);
} });
}, [workspaces]); }, []);
return ( return (
<DefaultLayout <DefaultLayout
@ -101,7 +86,7 @@ const OnBoard: NextPage = () => {
</div> </div>
)} )}
<div className="w-full md:w-2/3 lg:w-1/3 p-8 rounded-lg"> <div className="w-full md:w-2/3 lg:w-1/3 p-8 rounded-lg">
{invitations ? ( {invitations && workspaces ? (
invitations.length > 0 ? ( invitations.length > 0 ? (
<div className="mt-3 sm:mt-5"> <div className="mt-3 sm:mt-5">
<div className="mt-2"> <div className="mt-2">
@ -139,23 +124,6 @@ const OnBoard: NextPage = () => {
Accept Accept
</label> </label>
</div> </div>
{/* <div className="h-full flex items-center gap-x-1">
<input
id={`${item.id}`}
aria-describedby="workspaces"
name={`${item.id}`}
checked={invitationsRespond.includes(item.workspace.id)}
value={item.workspace.name}
onChange={() => {
handleInvitation(item, invitationsRespond.includes(item.workspace.id) ? "withdraw" : "accepted");
}}
type="checkbox"
className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
/>
<label htmlFor={item.id} className="text-sm">
Reject
</label>
</div> */}
</div> </div>
</div> </div>
))} ))}
@ -167,27 +135,46 @@ const OnBoard: NextPage = () => {
</Button> </Button>
</div> </div>
</div> </div>
) : workspaces && workspaces.length > 0 ? (
<div className="mt-3 flex flex-col gap-y-3">
<h2 className="text-2xl font-medium mb-4">Your workspaces</h2>
{workspaces.map((workspace) => (
<div
className="flex items-center justify-between border px-4 py-2 rounded mb-2"
key={workspace.id}
>
<div className="flex items-center gap-x-2">
<CubeIcon className="h-5 w-5 text-gray-400" />
<Link href={"/workspace"}>
<a>{workspace.name}</a>
</Link>
</div>
<div className="flex items-center gap-x-2">
<p className="text-sm">{workspace.owner.first_name}</p>
</div>
</div>
))}
<Link href={"/workspace"}>
<Button type="button">Go to workspaces</Button>
</Link>
</div>
) : ( ) : (
invitations.length === 0 &&
workspaces.length === 0 && (
<EmptySpace <EmptySpace
title={`${ title="You don't have any workspaces yet"
canRedirect
? `You haven't been invited to any workspace yet.`
: "You don't have any workspaces, Start by creating one."
}`}
description="Your workspace is where you'll create projects, collaborate on your issues, and organize different streams of work in your Plane account." description="Your workspace is where you'll create projects, collaborate on your issues, and organize different streams of work in your Plane account."
> >
<EmptySpaceItem <EmptySpaceItem
Icon={canRedirect ? CubeIcon : PlusIcon} Icon={PlusIcon}
title={canRedirect ? "Continue to Dashboard" : "Create your Workspace"} title={"Create your Workspace"}
action={() => { action={() => {
userService.updateUserOnBoard().then((response) => { router.push("/create-workspace");
console.log(response);
});
router.push(canRedirect ? "/" : "/create-workspace");
}} }}
/> />
</EmptySpace> </EmptySpace>
) )
)
) : ( ) : (
<div className="w-full h-full flex justify-center items-center"> <div className="w-full h-full flex justify-center items-center">
<Spinner /> <Spinner />
@ -199,4 +186,4 @@ const OnBoard: NextPage = () => {
); );
}; };
export default withAuthWrapper(OnBoard); export default OnBoard;

View File

@ -8,8 +8,6 @@ import Image from "next/image";
import useUser from "lib/hooks/useUser"; import useUser from "lib/hooks/useUser";
// services // services
import authenticationService from "lib/services/authentication.service"; import authenticationService from "lib/services/authentication.service";
// hoc
import withAuthWrapper from "lib/hoc/withAuthWrapper";
// layouts // layouts
import DefaultLayout from "layouts/DefaultLayout"; import DefaultLayout from "layouts/DefaultLayout";
// social button // social button
@ -180,4 +178,4 @@ const SignIn: NextPage = () => {
); );
}; };
export default withAuthWrapper(SignIn); export default SignIn;

View File

@ -11,8 +11,6 @@ import workspaceService from "lib/services/workspace.service";
import { WORKSPACE_INVITATION } from "constants/fetch-keys"; import { WORKSPACE_INVITATION } from "constants/fetch-keys";
// hooks // hooks
import useUser from "lib/hooks/useUser"; import useUser from "lib/hooks/useUser";
// hoc
import withAuthWrapper from "lib/hoc/withAuthWrapper";
// layouts // layouts
import DefaultLayout from "layouts/DefaultLayout"; import DefaultLayout from "layouts/DefaultLayout";
// ui // ui
@ -149,4 +147,4 @@ const WorkspaceInvitation: NextPage = () => {
); );
}; };
export default withAuthWrapper(WorkspaceInvitation); export default WorkspaceInvitation;

View File

@ -9,6 +9,8 @@ import AdminLayout from "layouts/AdminLayout";
import useSWR from "swr"; import useSWR from "swr";
// hooks // hooks
import useUser from "lib/hooks/useUser"; import useUser from "lib/hooks/useUser";
// hoc
import withAuthWrapper from "lib/hoc/withAuthWrapper";
// fetch keys // fetch keys
import { USER_ISSUE } from "constants/fetch-keys"; import { USER_ISSUE } from "constants/fetch-keys";
// services // services
@ -167,4 +169,4 @@ const Workspace: NextPage = () => {
); );
}; };
export default Workspace; export default withAuthWrapper(Workspace);