2022-11-19 14:21:26 +00:00
|
|
|
// services
|
2023-01-26 18:12:20 +00:00
|
|
|
import APIService from "services/api.service";
|
2023-03-29 06:54:19 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
|
|
|
|
2023-04-11 06:55:21 +00:00
|
|
|
import type {
|
|
|
|
ICurrentUserResponse,
|
|
|
|
IUser,
|
|
|
|
IUserActivityResponse,
|
|
|
|
IUserWorkspaceDashboard,
|
|
|
|
} from "types";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
class UserService extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
|
|
|
}
|
|
|
|
|
|
|
|
currentUserConfig() {
|
|
|
|
return {
|
|
|
|
url: `${this.baseURL}/api/users/me/`,
|
|
|
|
headers: this.getHeaders(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-13 05:55:33 +00:00
|
|
|
async userIssues(workspaceSlug: string): Promise<any> {
|
2023-01-26 18:12:20 +00:00
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/my-issues/`)
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-11 06:55:21 +00:00
|
|
|
async currentUser(): Promise<ICurrentUserResponse> {
|
2023-01-26 18:12:20 +00:00
|
|
|
return this.get("/api/users/me/")
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
2023-04-08 12:35:54 +00:00
|
|
|
throw error?.response;
|
2022-11-19 14:21:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-16 14:56:25 +00:00
|
|
|
async updateUser(data: Partial<IUser>): Promise<any> {
|
2023-01-26 18:12:20 +00:00
|
|
|
return this.patch("/api/users/me/", data)
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async updateUserOnBoard({ userRole }: any, user: ICurrentUserResponse | undefined): Promise<any> {
|
2023-04-03 18:27:19 +00:00
|
|
|
return this.patch("/api/users/me/onboard/", {
|
|
|
|
is_onboarded: true,
|
|
|
|
})
|
2023-03-29 06:54:19 +00:00
|
|
|
.then((response) => {
|
2023-04-03 18:27:19 +00:00
|
|
|
if (trackEvent)
|
2023-06-06 16:06:00 +00:00
|
|
|
trackEventServices.trackUserOnboardingCompleteEvent(
|
|
|
|
{
|
|
|
|
user_role: userRole ?? "None",
|
|
|
|
},
|
|
|
|
user
|
|
|
|
);
|
2023-03-29 06:54:19 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-15 20:06:21 +00:00
|
|
|
|
2023-07-12 14:25:08 +00:00
|
|
|
async updateUserTourCompleted(user: ICurrentUserResponse): Promise<any> {
|
|
|
|
return this.patch("/api/users/me/tour-completed/", {
|
|
|
|
is_tour_completed: true,
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
if (trackEvent)
|
|
|
|
trackEventServices.trackUserTourCompleteEvent(
|
|
|
|
{
|
|
|
|
user_role: user.role ?? "None",
|
|
|
|
},
|
|
|
|
user
|
|
|
|
);
|
|
|
|
return response?.data;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:34:41 +00:00
|
|
|
async getUserActivity(): Promise<IUserActivityResponse> {
|
|
|
|
return this.get("/api/users/activities/")
|
2023-03-15 20:06:21 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-23 10:24:59 +00:00
|
|
|
|
2023-03-24 05:36:52 +00:00
|
|
|
async userWorkspaceDashboard(
|
|
|
|
workspaceSlug: string,
|
|
|
|
month: number
|
|
|
|
): Promise<IUserWorkspaceDashboard> {
|
|
|
|
return this.get(`/api/users/me/workspaces/${workspaceSlug}/dashboard/`, {
|
|
|
|
params: {
|
|
|
|
month: month,
|
|
|
|
},
|
|
|
|
})
|
2023-03-23 10:24:59 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-06-06 16:06:13 +00:00
|
|
|
|
|
|
|
async forgotPassword(data: { email: string }): Promise<any> {
|
|
|
|
return this.post(`/api/forgot-password/`, data)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async resetPassword(
|
|
|
|
uidb64: string,
|
|
|
|
token: string,
|
|
|
|
data: {
|
|
|
|
new_password: string;
|
|
|
|
confirm_password: string;
|
|
|
|
}
|
|
|
|
): Promise<any> {
|
|
|
|
return this.post(`/api/reset-password/${uidb64}/${token}/`, data)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-11-19 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new UserService();
|