import { useState } from "react"; import Image from "next/image"; import Router, { useRouter } from "next/router"; import { mutate } from "swr"; // services import userService from "services/user.service"; import workspaceService from "services/workspace.service"; // hooks import useUserAuth from "hooks/use-user-auth"; // layouts import DefaultLayout from "layouts/default-layout"; import { UserAuthorizationLayout } from "layouts/auth-layout/user-authorization-wrapper"; // components import { InviteMembers, OnboardingCard, OnboardingLogo, UserDetails, Workspace, } from "components/onboarding"; // ui import { PrimaryButton } from "components/ui"; // constant import { ONBOARDING_CARDS } from "constants/workspace"; // types import type { NextPage } from "next"; import { ICurrentUserResponse } from "types"; // fetch-keys import { CURRENT_USER } from "constants/fetch-keys"; const Onboarding: NextPage = () => { const [step, setStep] = useState(1); const [userRole, setUserRole] = useState(null); const [workspace, setWorkspace] = useState(); const router = useRouter(); const { user } = useUserAuth("onboarding"); console.log("user", user); return (
{step <= 3 ? (
{step === 1 ? ( ) : step === 2 ? ( ) : ( )}
) : (
{step === 4 ? ( ) : step === 5 ? ( ) : step === 6 ? ( ) : step === 7 ? ( ) : ( )}
{ if (step === 8) { userService .updateUserOnBoard({ userRole }) .then(async () => { mutate( CURRENT_USER, (prevData) => { if (!prevData) return prevData; return { ...prevData, user: { ...prevData.user, is_onboarded: true, }, }; }, false ); const userWorkspaces = await workspaceService.userWorkspaces(); const lastActiveWorkspace = userWorkspaces.find( (workspace) => workspace.id === user?.last_workspace_id ); if (lastActiveWorkspace) { Router.push(`/${lastActiveWorkspace.slug}`); return; } else if (userWorkspaces.length > 0) { Router.push(`/${userWorkspaces[0].slug}`); return; } else { const invitations = await workspaceService.userWorkspaceInvitations(); if (invitations.length > 0) { Router.push(`/invitations`); return; } else { Router.push(`/create-workspace`); return; } } }) .catch((err) => { console.log(err); }); } else setStep((prevData) => prevData + 1); }} > {step === 4 || step === 8 ? "Get Started" : "Next"}
)}
Logged in: {user?.email}
); }; export default Onboarding;