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
This commit is contained in:
guru_sainath 2023-06-14 14:04:25 +05:30 committed by GitHub
parent 4083f623a0
commit be7706e62e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import { mutate } from "swr";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
// services // services
import workspaceService from "services/workspace.service"; import workspaceService from "services/workspace.service";
import userService from "services/user.service";
// hooks // hooks
import useToast from "hooks/use-toast"; import useToast from "hooks/use-toast";
// ui // ui
@ -77,7 +78,7 @@ export const CreateWorkspaceForm: React.FC<Props> = ({
message: "Workspace created successfully.", message: "Workspace created successfully.",
}); });
mutate<IWorkspace[]>(USER_WORKSPACES, (prevData) => [res, ...(prevData ?? [])]); mutate<IWorkspace[]>(USER_WORKSPACES, (prevData) => [res, ...(prevData ?? [])]);
onSubmit(res); updateLastWorkspaceIdUnderUSer(res);
}) })
.catch((err) => { .catch((err) => {
console.error(err); console.error(err);
@ -93,6 +94,18 @@ export const CreateWorkspaceForm: React.FC<Props> = ({
}); });
}; };
// 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( useEffect(
() => () => { () => () => {
// when the component unmounts set the default values to whatever user typed in // when the component unmounts set the default values to whatever user typed in

View File

@ -96,16 +96,7 @@ const Onboarding: NextPage = () => {
) ?? userWorkspaces[0]; ) ?? userWorkspaces[0];
if (lastActiveWorkspace) { if (lastActiveWorkspace) {
userService
.updateUser({
last_workspace_id: lastActiveWorkspace.id,
})
.then((res) => {
mutateUser(); mutateUser();
})
.catch((err) => {
console.log(err);
});
Router.push(`/${lastActiveWorkspace.slug}`); Router.push(`/${lastActiveWorkspace.slug}`);
return; return;
} else { } else {