From 4b84640d8b708d96a6350b37dd1aa568e9820eae Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Sun, 3 Dec 2023 10:01:00 +0530 Subject: [PATCH 1/5] fix: Language API --- apps/web/app/services/client/api/languages.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/web/app/services/client/api/languages.ts b/apps/web/app/services/client/api/languages.ts index e07c98399..48a158c1f 100644 --- a/apps/web/app/services/client/api/languages.ts +++ b/apps/web/app/services/client/api/languages.ts @@ -1,6 +1,8 @@ -import { ILanguageItemList, CreateResponse, PaginationResponse } from '@app/interfaces'; -import api from '../axios'; +import { get } from '../axios'; -export function getLanguageListAPI(is_system: boolean) { - return api.get>>(`/languages?is_system=${is_system}`); +export async function getLanguageListAPI(is_system: boolean) { + const endpoint = `/languages?is_system=${is_system}`; + const data = await get(endpoint, true); + + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; } From 31584adf431ee5ec26d91adb4e0b12e84076ab64 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Sun, 3 Dec 2023 10:50:23 +0530 Subject: [PATCH 2/5] fix: Invite Me api --- apps/web/app/hooks/features/useTeamInvitations.ts | 10 ++++++++-- apps/web/app/services/client/api/invite.ts | 9 ++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/web/app/hooks/features/useTeamInvitations.ts b/apps/web/app/hooks/features/useTeamInvitations.ts index f6c2d2da0..39b01d9b8 100644 --- a/apps/web/app/hooks/features/useTeamInvitations.ts +++ b/apps/web/app/hooks/features/useTeamInvitations.ts @@ -21,6 +21,8 @@ import { useQuery } from '../useQuery'; import { useAuthenticateUser } from './useAuthenticateUser'; export function useTeamInvitations() { + const { user } = useAuthenticateUser(); + const setTeamInvitations = useSetRecoilState(teamInvitationsState); const [myInvitationsList, setMyInvitationsList] = useRecoilState(myInvitationsState); @@ -87,11 +89,15 @@ export function useTeamInvitations() { ); const myInvitations = useCallback(() => { - myInvitationsQueryCall().then((res) => { + if (!user?.tenantId) { + return; + } + + myInvitationsQueryCall(user.tenantId).then((res) => { setMyInvitationsList(res.data.items); return res.data; }); - }, [myInvitationsQueryCall, setMyInvitationsList]); + }, [myInvitationsQueryCall, setMyInvitationsList, user]); const removeMyInvitation = useCallback( (id: string) => { setMyInvitationsList(myInvitationsList.filter((invitation) => invitation.id !== id)); diff --git a/apps/web/app/services/client/api/invite.ts b/apps/web/app/services/client/api/invite.ts index 7764b1c03..c2f517764 100644 --- a/apps/web/app/services/client/api/invite.ts +++ b/apps/web/app/services/client/api/invite.ts @@ -1,6 +1,6 @@ import { PaginationResponse } from '@app/interfaces/IDataResponse'; import { IInvitation, IInviteRequest, IMyInvitations, MyInvitationActionEnum, CreateResponse } from '@app/interfaces'; -import api from '../axios'; +import api, { get } from '../axios'; export function inviteByEmailsAPI(data: IInviteRequest) { return api.post>('/invite/emails', data); @@ -20,8 +20,11 @@ export function resendTeamInvitationsAPI(inviteId: string) { }); } -export function getMyInvitationsAPI() { - return api.get>('/invite/me'); +export async function getMyInvitationsAPI(tenantId: string) { + const endpoint = '/invite/me'; + const data = await get(endpoint, true, { tenantId }); + + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; } export function acceptRejectMyInvitationsAPI(invitationId: string, action: MyInvitationActionEnum) { From 34c32e35cf550a427993b3d68e5d82fa27d3d153 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Sun, 3 Dec 2023 11:07:39 +0530 Subject: [PATCH 3/5] fix: Invite API --- .../app/hooks/features/useTeamInvitations.ts | 7 ++++--- apps/web/app/services/client/api/invite.ts | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/web/app/hooks/features/useTeamInvitations.ts b/apps/web/app/hooks/features/useTeamInvitations.ts index 39b01d9b8..0ac8b0d85 100644 --- a/apps/web/app/hooks/features/useTeamInvitations.ts +++ b/apps/web/app/hooks/features/useTeamInvitations.ts @@ -59,12 +59,13 @@ export function useTeamInvitations() { ); useEffect(() => { - if (activeTeamId && firstLoad && isTeamManager) { - queryCall().then((res) => { + if (activeTeamId && firstLoad && isTeamManager && user?.tenantId) { + queryCall(user?.tenantId, user.employee.organizationId, 'EMPLOYEE', activeTeamId).then((res) => { + console.log(res.data?.items); setTeamInvitations(res.data?.items || []); }); } - }, [activeTeamId, firstLoad, isTeamManager, queryCall, setTeamInvitations]); + }, [activeTeamId, firstLoad, isTeamManager, queryCall, setTeamInvitations, user]); useEffect(() => { if (firstLoad) { diff --git a/apps/web/app/services/client/api/invite.ts b/apps/web/app/services/client/api/invite.ts index c2f517764..63e9ceb7c 100644 --- a/apps/web/app/services/client/api/invite.ts +++ b/apps/web/app/services/client/api/invite.ts @@ -1,13 +1,24 @@ import { PaginationResponse } from '@app/interfaces/IDataResponse'; -import { IInvitation, IInviteRequest, IMyInvitations, MyInvitationActionEnum, CreateResponse } from '@app/interfaces'; +import { IInvitation, IInviteRequest, MyInvitationActionEnum, CreateResponse } from '@app/interfaces'; import api, { get } from '../axios'; export function inviteByEmailsAPI(data: IInviteRequest) { return api.post>('/invite/emails', data); } -export function getTeamInvitationsAPI() { - return api.get>('/invite'); +export async function getTeamInvitationsAPI(tenantId: string, organizationId: string, role: string, teamId: string) { + const query = new URLSearchParams({ + 'where[tenantId]': tenantId, + 'where[organizationId]': organizationId, + 'where[role][name]': role, + 'where[teams][id][0]': teamId, + 'where[status]': 'INVITED' + }); + + const endpoint = `/invite?${query.toString()}`; + const data = await get(endpoint, true, { tenantId }); + + return process.env.NEXT_PUBLIC_GAUZY_API_SERVER_URL ? data.data : data; } export function removeTeamInvitationsAPI(invitationId: string) { From 971b33caa11b9c3192f136284b4c81210cc452f4 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Sun, 3 Dec 2023 11:42:07 +0530 Subject: [PATCH 4/5] Removed console --- apps/web/app/hooks/features/useTeamInvitations.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/web/app/hooks/features/useTeamInvitations.ts b/apps/web/app/hooks/features/useTeamInvitations.ts index 0ac8b0d85..5e1118437 100644 --- a/apps/web/app/hooks/features/useTeamInvitations.ts +++ b/apps/web/app/hooks/features/useTeamInvitations.ts @@ -61,7 +61,6 @@ export function useTeamInvitations() { useEffect(() => { if (activeTeamId && firstLoad && isTeamManager && user?.tenantId) { queryCall(user?.tenantId, user.employee.organizationId, 'EMPLOYEE', activeTeamId).then((res) => { - console.log(res.data?.items); setTeamInvitations(res.data?.items || []); }); } From 3490f4a64cb1461a4ff5cd0c6a140c1e29edcaf8 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Sun, 3 Dec 2023 11:45:30 +0530 Subject: [PATCH 5/5] fix: Build Issue --- apps/web/app/hooks/features/useLanguageSettings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/app/hooks/features/useLanguageSettings.ts b/apps/web/app/hooks/features/useLanguageSettings.ts index fc0a51adf..41534e576 100644 --- a/apps/web/app/hooks/features/useLanguageSettings.ts +++ b/apps/web/app/hooks/features/useLanguageSettings.ts @@ -39,7 +39,7 @@ export function useLanguageSettings() { if (user) { return queryCall(user.role.isSystem).then((res) => { setLanguages( - res?.data?.data?.items.filter((item) => APPLICATION_LANGUAGES_CODE.includes(item.code)) || [] + res?.data?.data?.items.filter((item: any) => APPLICATION_LANGUAGES_CODE.includes(item.code)) || [] ); return res; });