diff --git a/pages/invitations.tsx b/pages/invitations.tsx index a38fb48e6..cb0d378e9 100644 --- a/pages/invitations.tsx +++ b/pages/invitations.tsx @@ -5,8 +5,6 @@ import Link from "next/link"; import { useRouter } from "next/router"; // swr import useSWR from "swr"; -// headless ui -import { Dialog, Transition } from "@headlessui/react"; // services import workspaceService from "lib/services/workspace.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"; // constants import { USER_WORKSPACE_INVITATIONS } from "constants/api-routes"; -// hoc -import withAuthWrapper from "lib/hoc/withAuthWrapper"; // layouts import DefaultLayout from "layouts/DefaultLayout"; // ui import { Button, Spinner } from "ui"; // 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"; const OnBoard: NextPage = () => { - const [canRedirect, setCanRedirect] = useState(true); const router = useRouter(); const { workspaces, mutateWorkspaces, user } = useUser(); @@ -63,28 +58,18 @@ const OnBoard: NextPage = () => { console.log(res); await mutate(); await mutateWorkspaces(); + router.push("/workspace"); }) .catch((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(() => { - if (workspaces && workspaces.length === 0) { - setCanRedirect(false); - } - }, [workspaces]); + userService.updateUserOnBoard().then((response) => { + console.log(response); + }); + }, []); return ( { )}
- {invitations ? ( + {invitations && workspaces ? ( invitations.length > 0 ? (
@@ -139,23 +124,6 @@ const OnBoard: NextPage = () => { Accept
- {/*
- { - 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" - /> - -
*/}
))} @@ -167,26 +135,45 @@ const OnBoard: NextPage = () => { + ) : workspaces && workspaces.length > 0 ? ( +
+

Your workspaces

+ {workspaces.map((workspace) => ( +
+
+ + + {workspace.name} + +
+
+

{workspace.owner.first_name}

+
+
+ ))} + + + +
) : ( - - { - userService.updateUserOnBoard().then((response) => { - console.log(response); - }); - router.push(canRedirect ? "/" : "/create-workspace"); - }} - /> - + invitations.length === 0 && + workspaces.length === 0 && ( + + { + router.push("/create-workspace"); + }} + /> + + ) ) ) : (
@@ -199,4 +186,4 @@ const OnBoard: NextPage = () => { ); }; -export default withAuthWrapper(OnBoard); +export default OnBoard;