fix: workspace invitation page not showing workspaces

This commit is contained in:
Dakshesh Jain 2022-11-25 15:48:00 +05:30
parent 09e5e631b6
commit 6e7d59cf4f

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;