From d5b3ddb8ac0cf3177171c313027dbf8c9cd0c0ee Mon Sep 17 00:00:00 2001 From: Badal Khatri <81486442+badalkhatri0924@users.noreply.github.com> Date: Sat, 2 Dec 2023 19:19:42 +0530 Subject: [PATCH] Fix/api improvements (#1934) * User /me API Improved * Timer Status API Updated * Updated Working Employee API * fix: team task api * fix: Issue Type API * task status updated * fix: Version * fix: Organization Team API * fix: Label * fix: Label params * fix: Task Priorities * fix: Task Related Issue Type * Update issue-type.ts * Update task-labels.ts * Update tasks.ts * Update task-status.ts * Update task-related-issue-type.ts * Update employee.ts * Update organization-team.ts * Update task-priorities.ts --------- Co-authored-by: Ruslan K --- .../app/hooks/features/useAuthenticateUser.ts | 2 +- apps/web/app/hooks/features/useEmployee.ts | 11 ++++-- .../hooks/features/useOrganizationTeams.ts | 19 ++++++---- apps/web/app/hooks/features/useSettings.ts | 2 +- apps/web/app/hooks/features/useTeamTasks.ts | 20 +++++++++- apps/web/app/hooks/features/useTimer.ts | 6 +-- apps/web/app/services/client/api/auth.ts | 18 +++++++-- apps/web/app/services/client/api/employee.ts | 19 ++++++++-- .../web/app/services/client/api/issue-type.ts | 9 +++-- .../services/client/api/organization-team.ts | 32 ++++++++++++++-- .../app/services/client/api/task-labels.ts | 9 +++-- .../services/client/api/task-priorities.ts | 16 +++++--- .../client/api/task-related-issue-type.ts | 16 +++++--- .../app/services/client/api/task-status.ts | 10 +++-- .../app/services/client/api/task-version.ts | 10 +++-- apps/web/app/services/client/api/tasks.ts | 37 +++++++++++++++++-- apps/web/app/services/client/api/timer.ts | 12 ++++-- apps/web/app/services/client/axios.ts | 17 ++++++++- .../services/server/requests/issue-type.ts | 6 +-- .../services/server/requests/task-labels.ts | 4 +- .../server/requests/task-priorities.ts | 6 +-- .../requests/task-related-issue-type.ts | 6 +-- .../services/server/requests/task-version.ts | 6 +-- .../services/server/requests/taskStatus.ts | 6 +-- apps/web/lib/app/authenticator.tsx | 2 +- apps/web/lib/features/team/team-item.tsx | 2 +- apps/web/pages/api/issue-types/index.tsx | 4 +- apps/web/pages/api/tags/index.tsx | 4 +- apps/web/pages/api/tags/level.ts | 4 +- apps/web/pages/api/task-priorities/index.tsx | 4 +- .../api/task-related-issue-types/index.ts | 2 +- apps/web/pages/api/task-statuses/index.tsx | 4 +- apps/web/pages/api/task-versions/index.tsx | 4 +- apps/web/pages/api/user/me.ts | 2 +- 34 files changed, 241 insertions(+), 90 deletions(-) diff --git a/apps/web/app/hooks/features/useAuthenticateUser.ts b/apps/web/app/hooks/features/useAuthenticateUser.ts index 974b13fca..09b5b1fdd 100644 --- a/apps/web/app/hooks/features/useAuthenticateUser.ts +++ b/apps/web/app/hooks/features/useAuthenticateUser.ts @@ -27,7 +27,7 @@ export const useAuthenticateUser = (defaultUser?: IUser) => { return; } refreshUserQueryCall().then((res) => { - setUser(res.data.user); + setUser(res.data); }); }, [refreshUserQueryCall, setUser, refreshUserLoadingRef]); diff --git a/apps/web/app/hooks/features/useEmployee.ts b/apps/web/app/hooks/features/useEmployee.ts index 0a179b51c..902699cc1 100644 --- a/apps/web/app/hooks/features/useEmployee.ts +++ b/apps/web/app/hooks/features/useEmployee.ts @@ -4,8 +4,10 @@ import { useCallback, useEffect } from 'react'; import { useRecoilState } from 'recoil'; import { useQuery } from '../useQuery'; +import { useAuthenticateUser } from './useAuthenticateUser'; export const useEmployee = () => { + const { user } = useAuthenticateUser(); const [workingEmployees, setWorkingEmployees] = useRecoilState(workingEmployeesState); const [workingEmployeesEmail, setWorkingEmployeesEmail] = useRecoilState(workingEmployeesEmailState); @@ -13,14 +15,17 @@ export const useEmployee = () => { useQuery(getWorkingEmployeesAPI); const getWorkingEmployee = useCallback(() => { - getWorkingEmployeeQueryCall().then((data) => { + if (!user?.tenantId) { + return; + } + getWorkingEmployeeQueryCall(user?.tenantId, user?.employee.organizationId).then((data) => { if (data?.data?.items && data?.data?.items?.length) { const items = data.data.items || []; setWorkingEmployees(items); - setWorkingEmployeesEmail(items.map((item) => item.user?.email || '')); + setWorkingEmployeesEmail(items.map((item: any) => item.user?.email || '')); } }); - }, [getWorkingEmployeeQueryCall, setWorkingEmployees, setWorkingEmployeesEmail]); + }, [getWorkingEmployeeQueryCall, setWorkingEmployees, setWorkingEmployeesEmail, user]); useEffect(() => { getWorkingEmployee(); diff --git a/apps/web/app/hooks/features/useOrganizationTeams.ts b/apps/web/app/hooks/features/useOrganizationTeams.ts index faacc8968..a0d6b1fb7 100644 --- a/apps/web/app/hooks/features/useOrganizationTeams.ts +++ b/apps/web/app/hooks/features/useOrganizationTeams.ts @@ -226,20 +226,25 @@ export function useOrganizationTeams() { ); const loadTeamsData = useCallback(() => { - if (loadingRef.current || loadingRefTeam.current) { + if ( + loadingRef.current || + loadingRefTeam.current || + !user?.employee.organizationId || + !user?.employee.tenantId + ) { return; } let teamId = getActiveTeamIdCookie(); setActiveTeamId(teamId); - return queryCall().then((res) => { + return queryCall(user?.employee.organizationId, user?.employee.tenantId).then((res) => { if (res.data?.items && res.data?.items?.length === 0) { setIsTeamMember(false); } const latestTeams = res.data?.items || []; - const latestTeamsSorted = latestTeams.slice().sort((a, b) => a.name.localeCompare(b.name)); + const latestTeamsSorted = latestTeams.slice().sort((a: any, b: any) => a.name.localeCompare(b.name)); const teamsRefSorted = teamsRef.current.slice().sort((a, b) => a.name.localeCompare(b.name)); @@ -256,7 +261,7 @@ export function useOrganizationTeams() { // Handle case where user might Remove Account from all teams, // In such case need to update active team with Latest list of Teams - if (!latestTeams.find((team) => team.id === teamId) && latestTeams.length) { + if (!latestTeams.find((team: any) => team.id === teamId) && latestTeams.length) { setActiveTeam(latestTeams[0]); } else if (!latestTeams.length) { teamId = ''; @@ -274,7 +279,7 @@ export function useOrganizationTeams() { * (It prevents unnecessary re-rendering) */ if (!isEqual(latestTeamsSorted, teamsRefSorted)) { - setTeams([newTeam, ...latestTeams.filter((team) => team.id !== newTeam.id)]); + setTeams([newTeam, ...latestTeams.filter((team: any) => team.id !== newTeam.id)]); // Set Project Id to cookie // TODO: Make it dynamic when we add Dropdown in Navbar @@ -304,8 +309,8 @@ export function useOrganizationTeams() { loadingTeamsRef, setTeams, setTeamsUpdate, - user?.employee.organizationId, - user?.employee.tenantId + user?.employee?.organizationId, + user?.employee?.tenantId ]); const editOrganizationTeam = useCallback( diff --git a/apps/web/app/hooks/features/useSettings.ts b/apps/web/app/hooks/features/useSettings.ts index 55c1721b8..4c5af9828 100644 --- a/apps/web/app/hooks/features/useSettings.ts +++ b/apps/web/app/hooks/features/useSettings.ts @@ -17,7 +17,7 @@ export function useSettings() { (userData: Partial & { id: string }) => { return updateAvatarQueryCall(userData.id, userData).then((res) => { refreshUserQueryCall().then((result) => { - setUser(result.data.user); + setUser(result.data); }); return res; }); diff --git a/apps/web/app/hooks/features/useTeamTasks.ts b/apps/web/app/hooks/features/useTeamTasks.ts index d8755c3f6..595a45e2f 100644 --- a/apps/web/app/hooks/features/useTeamTasks.ts +++ b/apps/web/app/hooks/features/useTeamTasks.ts @@ -23,9 +23,11 @@ import { useFirstLoad } from '../useFirstLoad'; import { useQuery } from '../useQuery'; import { useSyncRef } from '../useSyncRef'; import { useOrganizationEmployeeTeams } from './useOrganizatioTeamsEmployee'; +import { useAuthenticateUser } from './useAuthenticateUser'; export function useTeamTasks() { const { updateOrganizationTeamEmployeeActiveTask } = useOrganizationEmployeeTeams(); + const { user } = useAuthenticateUser(); const setAllTasks = useSetRecoilState(teamTasksState); const tasks = useRecoilValue(tasksByTeamState); @@ -109,12 +111,26 @@ export function useTeamTasks() { response(true); }); } - return queryCall().then((res) => { + + if (!user || activeTeamRef.current?.id) { + return new Promise((response) => { + response(true); + }); + } + + return queryCall( + user?.employee.organizationId, + user?.employee.tenantId, + activeTeamRef.current?.projects && activeTeamRef.current?.projects.length + ? activeTeamRef.current?.projects[0].id + : '', + activeTeamRef.current?.id || '' + ).then((res) => { deepCheckAndUpdateTasks(res?.data?.items || [], deepCheck); return res; }); }, - [queryCall, deepCheckAndUpdateTasks, loadingRef] + [queryCall, deepCheckAndUpdateTasks, loadingRef, user, activeTeamRef] ); // Global loading state diff --git a/apps/web/app/hooks/features/useTimer.ts b/apps/web/app/hooks/features/useTimer.ts index 38eb65a5e..c24f0b132 100644 --- a/apps/web/app/hooks/features/useTimer.ts +++ b/apps/web/app/hooks/features/useTimer.ts @@ -191,10 +191,10 @@ export function useTimer() { const getTimerStatus = useCallback( (deepCheck?: boolean) => { - if (loadingRef.current) { + if (loadingRef.current || !user?.tenantId) { return; } - return queryCall().then((res) => { + return queryCall(user?.tenantId, user?.employee.organizationId).then((res) => { if (res.data && !isEqual(timerStatus, res.data)) { setTimerStatus((t) => { if (deepCheck) { @@ -206,7 +206,7 @@ export function useTimer() { return res; }); }, - [timerStatus, setTimerStatus, queryCall, loadingRef] + [timerStatus, setTimerStatus, queryCall, loadingRef, user] ); const toggleTimer = useCallback( diff --git a/apps/web/app/services/client/api/auth.ts b/apps/web/app/services/client/api/auth.ts index dea6fe2e7..e45048331 100644 --- a/apps/web/app/services/client/api/auth.ts +++ b/apps/web/app/services/client/api/auth.ts @@ -1,7 +1,7 @@ import { getRefreshTokenCookie } from '@app/helpers/cookies'; import { ISuccessResponse } from '@app/interfaces'; import { ILoginResponse, IRegisterDataAPI, ISigninEmailConfirmResponse } from '@app/interfaces/IAuthentication'; -import api from '../axios'; +import api, { get } from '../axios'; export const signInWithEmailAndCodeAPI = (email: string, code: string) => { return api.post(`/auth/login`, { @@ -31,8 +31,20 @@ export const signInEmailAPI = (email: string) => { }); }; -export const getAuthenticatedUserDataAPI = () => { - return api.get>(`/user/me`); +export const getAuthenticatedUserDataAPI = async () => { + const params = {} as { [x: string]: string }; + const relations = ['employee', 'role', 'tenant']; + + relations.forEach((rl, i) => { + params[`relations[${i}]`] = rl; + }); + + const query = new URLSearchParams(params); + + const endpoint = `/user/me?${query.toString()}`; + const data = await get(endpoint, true); + + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; }; export const verifyUserEmailByCodeAPI = (code: string) => { diff --git a/apps/web/app/services/client/api/employee.ts b/apps/web/app/services/client/api/employee.ts index 6f94e8ef5..54f942a91 100644 --- a/apps/web/app/services/client/api/employee.ts +++ b/apps/web/app/services/client/api/employee.ts @@ -1,6 +1,17 @@ -import { PaginationResponse, IWorkingEmployee } from '@app/interfaces'; -import api from '../axios'; +import { get } from '../axios'; -export function getWorkingEmployeesAPI() { - return api.get>('/employee/working'); +export async function getWorkingEmployeesAPI(tenantId: string, organizationId: string) { + const params = { + 'where[tenantId]': tenantId, + 'where[organizationId]': organizationId, + 'relations[0]': 'user' + }; + const query = new URLSearchParams(params); + + const endpoint = process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL + ? `/employee/pagination?${query.toString()}` + : '/employee/working'; + const data = await get(endpoint, true, { tenantId }); + + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; } diff --git a/apps/web/app/services/client/api/issue-type.ts b/apps/web/app/services/client/api/issue-type.ts index 709088ff2..59d7b7734 100644 --- a/apps/web/app/services/client/api/issue-type.ts +++ b/apps/web/app/services/client/api/issue-type.ts @@ -1,5 +1,5 @@ import { CreateResponse, DeleteResponse, IIssueTypesCreate } from '@app/interfaces'; -import api from '../axios'; +import api, { get } from '../axios'; export function createIssueTypeAPI(data: IIssueTypesCreate, tenantId?: string) { return api.post>('/issue-types', data, { @@ -21,6 +21,9 @@ export function deleteIssueTypeAPI(id: string) { return api.delete(`/issue-types/${id}`); } -export function getIssueTypeList(tenantId: string, organizationId: string, activeTeamId: string | null) { - return api.get(`/issue-types?tenantId=${tenantId}&organizationId=${organizationId}&activeTeamId=${activeTeamId}`); +export async function getIssueTypeList(tenantId: string, organizationId: string, activeTeamId: string | null) { + const endpoint = `/issue-types?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${activeTeamId}`; + const data = await get(endpoint, true, { tenantId }); + + return data; } diff --git a/apps/web/app/services/client/api/organization-team.ts b/apps/web/app/services/client/api/organization-team.ts index dd7412d67..f9222f3b0 100644 --- a/apps/web/app/services/client/api/organization-team.ts +++ b/apps/web/app/services/client/api/organization-team.ts @@ -4,13 +4,39 @@ import { IOrganizationTeamList, IOrganizationTeamWithMStatus, IOrganizationTeamUpdate, - IOrganizationTeam + IOrganizationTeam, + TimerSource } from '@app/interfaces'; import moment from 'moment'; import api, { get } from '../axios'; -export function getOrganizationTeamsAPI() { - return api.get>('/organization-team'); +export async function getOrganizationTeamsAPI(organizationId: string, tenantId: string) { + const relations = [ + 'members', + 'members.role', + 'members.employee', + 'members.employee.user', + 'createdBy', + 'createdBy.employee', + 'projects', + 'projects.repository' + ]; + + const params = { + 'where[organizationId]': organizationId, + 'where[tenantId]': tenantId, + source: TimerSource.TEAMS, + withLaskWorkedTask: 'true' + } as { [x: string]: string }; + + relations.forEach((rl, i) => { + params[`relations[${i}]`] = rl; + }); + const query = new URLSearchParams(params); + const endpoint = `/organization-team?${query.toString()}`; + + const data = await get(endpoint, true, { tenantId }); + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; } export function createOrganizationTeamAPI(name: string) { diff --git a/apps/web/app/services/client/api/task-labels.ts b/apps/web/app/services/client/api/task-labels.ts index 6aa94c6c6..6ad7bcd15 100644 --- a/apps/web/app/services/client/api/task-labels.ts +++ b/apps/web/app/services/client/api/task-labels.ts @@ -1,5 +1,5 @@ import { CreateResponse, DeleteResponse, ITaskLabelsCreate } from '@app/interfaces'; -import api from '../axios'; +import api, { get } from '../axios'; export function createTaskLabelsAPI(data: ITaskLabelsCreate, tenantId?: string) { return api.post>('/tags', data, { @@ -21,6 +21,9 @@ export function deleteTaskLabelsAPI(id: string) { return api.delete(`/tags/${id}`); } -export function getTaskLabelsList(tenantId: string, organizationId: string, activeTeamId: string | null) { - return api.get(`/tags/level?tenantId=${tenantId}&organizationId=${organizationId}&activeTeamId=${activeTeamId}`); +export async function getTaskLabelsList(tenantId: string, organizationId: string, organizationTeamId: string | null) { + const endpoint = `/tags/level?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`; + const data = await get(endpoint, true, { tenantId }); + + return data; } diff --git a/apps/web/app/services/client/api/task-priorities.ts b/apps/web/app/services/client/api/task-priorities.ts index 9c299cb4d..84a557d0c 100644 --- a/apps/web/app/services/client/api/task-priorities.ts +++ b/apps/web/app/services/client/api/task-priorities.ts @@ -1,5 +1,5 @@ import { CreateResponse, DeleteResponse, ITaskPrioritiesCreate } from '@app/interfaces'; -import api from '../axios'; +import api, { get } from '../axios'; export function createTaskPrioritiesAPI(data: ITaskPrioritiesCreate, tenantId?: string) { return api.post>('/task-priorities', data, { @@ -21,8 +21,14 @@ export function deleteTaskPrioritiesAPI(id: string) { return api.delete(`/task-priorities/${id}`); } -export function getTaskPrioritiesList(tenantId: string, organizationId: string, activeTeamId: string | null) { - return api.get( - `/task-priorities?tenantId=${tenantId}&organizationId=${organizationId}&activeTeamId=${activeTeamId}` - ); +export async function getTaskPrioritiesList( + tenantId: string, + organizationId: string, + organizationTeamId: string | null +) { + const endpoint = `/task-priorities?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`; + + const data = await get(endpoint, true, { tenantId }); + + return data; } diff --git a/apps/web/app/services/client/api/task-related-issue-type.ts b/apps/web/app/services/client/api/task-related-issue-type.ts index 155e6424d..e7ace2daf 100644 --- a/apps/web/app/services/client/api/task-related-issue-type.ts +++ b/apps/web/app/services/client/api/task-related-issue-type.ts @@ -1,5 +1,5 @@ import { CreateResponse, DeleteResponse, ITaskRelatedIssueTypeCreate } from '@app/interfaces'; -import api from '../axios'; +import api, { get } from '../axios'; export function createTaskRelatedIssueTypeAPI(data: ITaskRelatedIssueTypeCreate, tenantId?: string) { return api.post>('/task-related-issue-types', data, { @@ -21,8 +21,14 @@ export function deleteTaskRelatedIssueTypeAPI(id: string) { return api.delete(`/task-related-issue-types/${id}`); } -export function getTaskRelatedIssueTypeList(tenantId: string, organizationId: string, activeTeamId: string | null) { - return api.get( - `/task-related-issue-types?tenantId=${tenantId}&organizationId=${organizationId}&activeTeamId=${activeTeamId}` - ); +export async function getTaskRelatedIssueTypeList( + tenantId: string, + organizationId: string, + organizationTeamId: string | null +) { + const endpoint = `/task-related-issue-types?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`; + + const data = await get(endpoint, true, { tenantId }); + + return data; } diff --git a/apps/web/app/services/client/api/task-status.ts b/apps/web/app/services/client/api/task-status.ts index 4dafd1542..b523f9656 100644 --- a/apps/web/app/services/client/api/task-status.ts +++ b/apps/web/app/services/client/api/task-status.ts @@ -1,5 +1,5 @@ import { CreateResponse, DeleteResponse, ITaskStatusCreate } from '@app/interfaces'; -import api from '../axios'; +import api, { get } from '../axios'; export function createTaskStatusAPI(data: ITaskStatusCreate, tenantId?: string) { return api.post>('/task-statuses', data, { @@ -21,6 +21,10 @@ export function deleteTaskStatusAPI(id: string) { return api.delete(`/task-statuses/${id}`); } -export function getTaskStatusList(tenantId: string, organizationId: string, activeTeamId: string | null) { - return api.get(`/task-statuses?tenantId=${tenantId}&organizationId=${organizationId}&activeTeamId=${activeTeamId}`); +export async function getTaskStatusList(tenantId: string, organizationId: string, organizationTeamId: string | null) { + const endpoint = `/task-statuses?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`; + + const data = await get(endpoint, true, { tenantId }); + + return data; } diff --git a/apps/web/app/services/client/api/task-version.ts b/apps/web/app/services/client/api/task-version.ts index 34e67aad8..a5ae1614a 100644 --- a/apps/web/app/services/client/api/task-version.ts +++ b/apps/web/app/services/client/api/task-version.ts @@ -1,5 +1,5 @@ import { CreateResponse, DeleteResponse, ITaskVersionCreate } from '@app/interfaces'; -import api from '../axios'; +import api, { get } from '../axios'; export function createTaskVersionAPI(data: ITaskVersionCreate, tenantId?: string) { return api.post>('/task-versions', data, { @@ -21,6 +21,10 @@ export function deleteTaskVersionAPI(id: string) { return api.delete(`/task-versions/${id}`); } -export function getTaskVersionList(tenantId: string, organizationId: string, activeTeamId: string | null) { - return api.get(`/task-versions?tenantId=${tenantId}&organizationId=${organizationId}&activeTeamId=${activeTeamId}`); +export async function getTaskVersionList(tenantId: string, organizationId: string, organizationTeamId: string | null) { + const endpoint = `/task-versions?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`; + + const data = await get(endpoint, true, { tenantId }); + + return data; } diff --git a/apps/web/app/services/client/api/tasks.ts b/apps/web/app/services/client/api/tasks.ts index d8fedf87d..086f20eb6 100644 --- a/apps/web/app/services/client/api/tasks.ts +++ b/apps/web/app/services/client/api/tasks.ts @@ -1,14 +1,45 @@ import { CreateResponse, DeleteResponse, PaginationResponse } from '@app/interfaces/IDataResponse'; import { ICreateTask, ITeamTask } from '@app/interfaces/ITask'; import { ITasksTimesheet } from '@app/interfaces/ITimer'; -import api from '../axios'; +import api, { get } from '../axios'; export function getTasksByIdAPI(taskId: string) { return api.get>(`/tasks/${taskId}`); } -export function getTeamTasksAPI() { - return api.get>('/tasks/team'); +export async function getTeamTasksAPI(organizationId: string, tenantId: string, projectId: string, teamId: string) { + const relations = [ + 'tags', + 'teams', + 'members', + 'members.user', + 'creator', + 'linkedIssues', + 'linkedIssues.taskTo', + 'linkedIssues.taskFrom', + 'parent', + 'children' + ]; + + const obj = { + 'where[organizationId]': organizationId, + 'where[tenantId]': tenantId, + 'where[projectId]': projectId, + 'join[alias]': 'task', + 'join[leftJoinAndSelect][members]': 'task.members', + 'join[leftJoinAndSelect][user]': 'members.user', + 'where[teams][0]': teamId + } as Record; + + relations.forEach((rl, i) => { + obj[`relations[${i}]`] = rl; + }); + + const query = new URLSearchParams(obj); + const endpoint = `/tasks/team?${query.toString()}`; + const data = await get(endpoint, true, { tenantId }); + + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; } export function deleteTaskAPI(taskId: string) { diff --git a/apps/web/app/services/client/api/timer.ts b/apps/web/app/services/client/api/timer.ts index 759957888..45928cadb 100644 --- a/apps/web/app/services/client/api/timer.ts +++ b/apps/web/app/services/client/api/timer.ts @@ -1,8 +1,14 @@ import { ITimerStatus, IToggleTimerParams, TimerSource } from '@app/interfaces/ITimer'; -import api from '../axios'; +import api, { get } from '../axios'; -export function getTimerStatusAPI() { - return api.get('/timer/status'); +export async function getTimerStatusAPI(tenantId: string, organizationId: string) { + const params = new URLSearchParams({ tenantId, organizationId }); + const endpoint = process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL + ? `/timesheet/timer/status?${params.toString()}` + : '/timer/status'; + const data = await get(endpoint, true); + + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; } export function toggleTimerAPI(body: Pick) { diff --git a/apps/web/app/services/client/axios.ts b/apps/web/app/services/client/axios.ts index 216232ef2..92f3452d2 100644 --- a/apps/web/app/services/client/axios.ts +++ b/apps/web/app/services/client/axios.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-mixed-spaces-and-tabs */ import { API_BASE_URL, DEFAULT_APP_PATH } from '@app/constants'; import { getAccessTokenCookie, getActiveTeamIdCookie } from '@app/helpers/cookies'; import axios, { AxiosResponse } from 'axios'; @@ -70,8 +71,20 @@ apiDirect.interceptors.response.use( } ); -function get(endpoint: string, isDirect: boolean) { - return isDirect && process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? apiDirect.get(endpoint) : api.get(endpoint); +function get( + endpoint: string, + isDirect: boolean, + extras?: { + tenantId: string; + } +) { + return isDirect && process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL + ? apiDirect.get(endpoint, { + headers: { + ...(extras?.tenantId ? { 'tenant-id': extras?.tenantId } : {}) + } + }) + : api.get(endpoint); } export default api; diff --git a/apps/web/app/services/server/requests/issue-type.ts b/apps/web/app/services/server/requests/issue-type.ts index 48efbfa13..3ee5a737d 100644 --- a/apps/web/app/services/server/requests/issue-type.ts +++ b/apps/web/app/services/server/requests/issue-type.ts @@ -52,12 +52,12 @@ export function getIssueTypesListRequest( { organizationId, tenantId, - activeTeamId - }: { tenantId: string; organizationId: string; activeTeamId: string | null }, + organizationTeamId + }: { tenantId: string; organizationId: string; organizationTeamId: string | null }, bearer_token: string ) { return serverFetch({ - path: `/issue-types?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${activeTeamId}`, + path: `/issue-types?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`, method: 'GET', bearer_token }); diff --git a/apps/web/app/services/server/requests/task-labels.ts b/apps/web/app/services/server/requests/task-labels.ts index 08063489e..28ec48bd9 100644 --- a/apps/web/app/services/server/requests/task-labels.ts +++ b/apps/web/app/services/server/requests/task-labels.ts @@ -52,8 +52,8 @@ export function getTaskLabelsListRequest( { organizationId, tenantId, - activeTeamId: organizationTeamId - }: { tenantId: string; organizationId: string; activeTeamId: string | null }, + organizationTeamId: organizationTeamId + }: { tenantId: string; organizationId: string; organizationTeamId: string | null }, bearer_token: string ) { const params = new URLSearchParams({ diff --git a/apps/web/app/services/server/requests/task-priorities.ts b/apps/web/app/services/server/requests/task-priorities.ts index 149062218..e4098116b 100644 --- a/apps/web/app/services/server/requests/task-priorities.ts +++ b/apps/web/app/services/server/requests/task-priorities.ts @@ -52,12 +52,12 @@ export function getTaskPrioritiesListRequest( { organizationId, tenantId, - activeTeamId - }: { tenantId: string; organizationId: string; activeTeamId: string | null }, + organizationTeamId + }: { tenantId: string; organizationId: string; organizationTeamId: string | null }, bearer_token: string ) { return serverFetch({ - path: `/task-priorities?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${activeTeamId}`, + path: `/task-priorities?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`, method: 'GET', bearer_token }); diff --git a/apps/web/app/services/server/requests/task-related-issue-type.ts b/apps/web/app/services/server/requests/task-related-issue-type.ts index 32f5feb88..c0cb5744b 100644 --- a/apps/web/app/services/server/requests/task-related-issue-type.ts +++ b/apps/web/app/services/server/requests/task-related-issue-type.ts @@ -56,16 +56,16 @@ export function getTaskRelatedIssueTypeListRequest( { organizationId, tenantId, - activeTeamId + organizationTeamId }: { tenantId: string; organizationId: string; - activeTeamId: string | null; + organizationTeamId: string | null; }, bearer_token: string ) { return serverFetch({ - path: `/task-related-issue-types?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${activeTeamId}`, + path: `/task-related-issue-types?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`, method: 'GET', bearer_token }); diff --git a/apps/web/app/services/server/requests/task-version.ts b/apps/web/app/services/server/requests/task-version.ts index e18a22d12..2e037b804 100644 --- a/apps/web/app/services/server/requests/task-version.ts +++ b/apps/web/app/services/server/requests/task-version.ts @@ -52,16 +52,16 @@ export function getTaskVersionListRequest( { organizationId, tenantId, - activeTeamId + organizationTeamId }: { tenantId: string; organizationId: string; - activeTeamId: string | null; + organizationTeamId: string | null; }, bearer_token: string ) { return serverFetch({ - path: `/task-versions?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${activeTeamId}`, + path: `/task-versions?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`, method: 'GET', bearer_token }); diff --git a/apps/web/app/services/server/requests/taskStatus.ts b/apps/web/app/services/server/requests/taskStatus.ts index 737401ae4..7d8b860d8 100644 --- a/apps/web/app/services/server/requests/taskStatus.ts +++ b/apps/web/app/services/server/requests/taskStatus.ts @@ -52,16 +52,16 @@ export function getTaskStatusListRequest( { organizationId, tenantId, - activeTeamId + organizationTeamId }: { tenantId: string; organizationId: string; - activeTeamId: string | null; + organizationTeamId: string | null; }, bearer_token: string ) { return serverFetch({ - path: `/task-statuses?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${activeTeamId}`, + path: `/task-statuses?tenantId=${tenantId}&organizationId=${organizationId}&organizationTeamId=${organizationTeamId}`, method: 'GET', bearer_token }); diff --git a/apps/web/lib/app/authenticator.tsx b/apps/web/lib/app/authenticator.tsx index 83d180411..ea2dd9b17 100644 --- a/apps/web/lib/app/authenticator.tsx +++ b/apps/web/lib/app/authenticator.tsx @@ -47,7 +47,7 @@ export function withAuthentication(Component: NextPage, params: Params useEffect(() => { if (!user) { queryCall().then((res) => { - setUser(res.data.user); + setUser(res.data); }); } }, [queryCall, setUser, user]); diff --git a/apps/web/lib/features/team/team-item.tsx b/apps/web/lib/features/team/team-item.tsx index 1c8683dd2..ab274ae03 100644 --- a/apps/web/lib/features/team/team-item.tsx +++ b/apps/web/lib/features/team/team-item.tsx @@ -25,7 +25,7 @@ export function mapTeamItems(teams: IOrganizationTeamList[], onChangeActiveTeam: