forked from github/plane
fix: onboarding loop (#775)
* fix: dashboard workspace activity mutation * fix: onboarding loop
This commit is contained in:
parent
22c1f6f8e2
commit
725c9375ea
@ -7,12 +7,12 @@ import userService from "services/user.service";
|
||||
// constants
|
||||
import { CURRENT_USER } from "constants/fetch-keys";
|
||||
// types
|
||||
import type { IUser } from "types";
|
||||
import type { ICurrentUserResponse, IUser } from "types";
|
||||
|
||||
interface IUserContextProps {
|
||||
user?: IUser;
|
||||
isUserLoading: boolean;
|
||||
mutateUser: KeyedMutator<IUser>;
|
||||
mutateUser: KeyedMutator<ICurrentUserResponse>;
|
||||
assignedIssuesLength?: number;
|
||||
workspaceInvitesLength?: number;
|
||||
}
|
||||
@ -21,7 +21,7 @@ export const UserContext = createContext<IUserContextProps>({} as IUserContextPr
|
||||
|
||||
export const UserProvider = ({ children }: { children: ReactElement }) => {
|
||||
// API to fetch user information
|
||||
const { data, error, mutate } = useSWR<IUser>(CURRENT_USER, () => userService.currentUser(), {
|
||||
const { data, error, mutate } = useSWR(CURRENT_USER, () => userService.currentUser(), {
|
||||
shouldRetryOnError: false,
|
||||
});
|
||||
|
||||
|
@ -24,6 +24,7 @@ import Logo from "public/onboarding/logo.svg";
|
||||
import type { NextPage } from "next";
|
||||
// fetch-keys
|
||||
import { CURRENT_USER } from "constants/fetch-keys";
|
||||
import { ICurrentUserResponse } from "types";
|
||||
|
||||
const Onboarding: NextPage = () => {
|
||||
const [step, setStep] = useState(1);
|
||||
@ -76,7 +77,21 @@ const Onboarding: NextPage = () => {
|
||||
userService
|
||||
.updateUserOnBoard({ userRole })
|
||||
.then(() => {
|
||||
mutate(CURRENT_USER);
|
||||
mutate<ICurrentUserResponse>(
|
||||
CURRENT_USER,
|
||||
(prevData) => {
|
||||
if (!prevData) return prevData;
|
||||
|
||||
return {
|
||||
...prevData,
|
||||
user: {
|
||||
...prevData.user,
|
||||
is_onboarded: true,
|
||||
},
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
router.push("/");
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -2,7 +2,12 @@
|
||||
import APIService from "services/api.service";
|
||||
import trackEventServices from "services/track-event.service";
|
||||
|
||||
import type { IUser, IUserActivityResponse, IUserWorkspaceDashboard } from "types";
|
||||
import type {
|
||||
ICurrentUserResponse,
|
||||
IUser,
|
||||
IUserActivityResponse,
|
||||
IUserWorkspaceDashboard,
|
||||
} from "types";
|
||||
|
||||
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
||||
|
||||
@ -29,7 +34,7 @@ class UserService extends APIService {
|
||||
});
|
||||
}
|
||||
|
||||
async currentUser(): Promise<any> {
|
||||
async currentUser(): Promise<ICurrentUserResponse> {
|
||||
return this.get("/api/users/me/")
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
|
7
apps/app/types/users.d.ts
vendored
7
apps/app/types/users.d.ts
vendored
@ -15,6 +15,7 @@ export interface IUser {
|
||||
last_location: readonly string;
|
||||
created_location: readonly string;
|
||||
is_email_verified: boolean;
|
||||
is_onboarded: boolean;
|
||||
token: string;
|
||||
role: string;
|
||||
|
||||
@ -26,6 +27,12 @@ export interface IUser {
|
||||
[...rest: string]: any;
|
||||
}
|
||||
|
||||
export interface ICurrentUserResponse {
|
||||
assigned_issues: number;
|
||||
user: IUser;
|
||||
workspace_invites: number;
|
||||
}
|
||||
|
||||
export interface IUserLite {
|
||||
readonly id: string;
|
||||
first_name: string;
|
||||
|
Loading…
Reference in New Issue
Block a user