From be7706e62e7f306b392a0f6cab8b1b29c9af82be Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Wed, 14 Jun 2023 14:04:25 +0530 Subject: [PATCH] chore: updating last_workspace_id under user (#1289) * chore: onboarding steps workflow verification * chore: onboarding onboarding variable update * chore: role check in onboarding * chore: updated last_workspace_id under user --- .../workspace/create-workspace-form.tsx | 15 ++++++++++++++- apps/app/pages/onboarding.tsx | 11 +---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/app/components/workspace/create-workspace-form.tsx b/apps/app/components/workspace/create-workspace-form.tsx index fdc078cf0..507d88ea7 100644 --- a/apps/app/components/workspace/create-workspace-form.tsx +++ b/apps/app/components/workspace/create-workspace-form.tsx @@ -6,6 +6,7 @@ import { mutate } from "swr"; import { Controller, useForm } from "react-hook-form"; // services import workspaceService from "services/workspace.service"; +import userService from "services/user.service"; // hooks import useToast from "hooks/use-toast"; // ui @@ -77,7 +78,7 @@ export const CreateWorkspaceForm: React.FC = ({ message: "Workspace created successfully.", }); mutate(USER_WORKSPACES, (prevData) => [res, ...(prevData ?? [])]); - onSubmit(res); + updateLastWorkspaceIdUnderUSer(res); }) .catch((err) => { console.error(err); @@ -93,6 +94,18 @@ export const CreateWorkspaceForm: React.FC = ({ }); }; + // update last_workspace_id + const updateLastWorkspaceIdUnderUSer = (workspace: any) => { + userService + .updateUser({ last_workspace_id: workspace.id }) + .then((res) => { + onSubmit(workspace); + }) + .catch((err) => { + console.log(err); + }); + }; + useEffect( () => () => { // when the component unmounts set the default values to whatever user typed in diff --git a/apps/app/pages/onboarding.tsx b/apps/app/pages/onboarding.tsx index 65c860e9b..cc6b742df 100644 --- a/apps/app/pages/onboarding.tsx +++ b/apps/app/pages/onboarding.tsx @@ -96,16 +96,7 @@ const Onboarding: NextPage = () => { ) ?? userWorkspaces[0]; if (lastActiveWorkspace) { - userService - .updateUser({ - last_workspace_id: lastActiveWorkspace.id, - }) - .then((res) => { - mutateUser(); - }) - .catch((err) => { - console.log(err); - }); + mutateUser(); Router.push(`/${lastActiveWorkspace.slug}`); return; } else {