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
|
// constants
|
||||||
import { CURRENT_USER } from "constants/fetch-keys";
|
import { CURRENT_USER } from "constants/fetch-keys";
|
||||||
// types
|
// types
|
||||||
import type { IUser } from "types";
|
import type { ICurrentUserResponse, IUser } from "types";
|
||||||
|
|
||||||
interface IUserContextProps {
|
interface IUserContextProps {
|
||||||
user?: IUser;
|
user?: IUser;
|
||||||
isUserLoading: boolean;
|
isUserLoading: boolean;
|
||||||
mutateUser: KeyedMutator<IUser>;
|
mutateUser: KeyedMutator<ICurrentUserResponse>;
|
||||||
assignedIssuesLength?: number;
|
assignedIssuesLength?: number;
|
||||||
workspaceInvitesLength?: number;
|
workspaceInvitesLength?: number;
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ export const UserContext = createContext<IUserContextProps>({} as IUserContextPr
|
|||||||
|
|
||||||
export const UserProvider = ({ children }: { children: ReactElement }) => {
|
export const UserProvider = ({ children }: { children: ReactElement }) => {
|
||||||
// API to fetch user information
|
// 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,
|
shouldRetryOnError: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import Logo from "public/onboarding/logo.svg";
|
|||||||
import type { NextPage } from "next";
|
import type { NextPage } from "next";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
import { CURRENT_USER } from "constants/fetch-keys";
|
import { CURRENT_USER } from "constants/fetch-keys";
|
||||||
|
import { ICurrentUserResponse } from "types";
|
||||||
|
|
||||||
const Onboarding: NextPage = () => {
|
const Onboarding: NextPage = () => {
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState(1);
|
||||||
@ -76,7 +77,21 @@ const Onboarding: NextPage = () => {
|
|||||||
userService
|
userService
|
||||||
.updateUserOnBoard({ userRole })
|
.updateUserOnBoard({ userRole })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate(CURRENT_USER);
|
mutate<ICurrentUserResponse>(
|
||||||
|
CURRENT_USER,
|
||||||
|
(prevData) => {
|
||||||
|
if (!prevData) return prevData;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...prevData,
|
||||||
|
user: {
|
||||||
|
...prevData.user,
|
||||||
|
is_onboarded: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
router.push("/");
|
router.push("/");
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -2,7 +2,12 @@
|
|||||||
import APIService from "services/api.service";
|
import APIService from "services/api.service";
|
||||||
import trackEventServices from "services/track-event.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;
|
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/")
|
return this.get("/api/users/me/")
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.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;
|
last_location: readonly string;
|
||||||
created_location: readonly string;
|
created_location: readonly string;
|
||||||
is_email_verified: boolean;
|
is_email_verified: boolean;
|
||||||
|
is_onboarded: boolean;
|
||||||
token: string;
|
token: string;
|
||||||
role: string;
|
role: string;
|
||||||
|
|
||||||
@ -26,6 +27,12 @@ export interface IUser {
|
|||||||
[...rest: string]: any;
|
[...rest: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICurrentUserResponse {
|
||||||
|
assigned_issues: number;
|
||||||
|
user: IUser;
|
||||||
|
workspace_invites: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IUserLite {
|
export interface IUserLite {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
first_name: string;
|
first_name: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user