From 07beff73c7a2c003f05e5a966d0a4084626f1128 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Sat, 14 Oct 2023 05:58:51 +0530 Subject: [PATCH 1/3] WIP: Project-Team mapping --- apps/web/app/constants.ts | 1 + apps/web/app/helpers/cookies/index.ts | 12 +++++++++++- apps/web/app/hooks/features/useOrganizationTeams.ts | 13 +++++++++++++ apps/web/app/hooks/features/useTeamTasks.ts | 10 +++++++++- apps/web/app/interfaces/IOrganizationTeam.ts | 1 + apps/web/app/interfaces/ITask.ts | 1 + .../services/server/guards/authenticated-guard.ts | 5 ++++- apps/web/app/services/server/requests/tasks.ts | 3 +++ apps/web/pages/api/tasks/team.ts | 4 +++- 9 files changed, 46 insertions(+), 4 deletions(-) diff --git a/apps/web/app/constants.ts b/apps/web/app/constants.ts index 45a5328ff..0df9a505b 100644 --- a/apps/web/app/constants.ts +++ b/apps/web/app/constants.ts @@ -25,6 +25,7 @@ export const ORGANIZATION_ID_COOKIE_NAME = 'auth-organization-id'; export const ACTIVE_LANGUAGE_COOKIE_NAME = 'auth-active-language'; export const ACTIVE_TIMEZONE_COOKIE_NAME = 'auth-timezone'; export const NO_TEAM_POPUP_SHOW_COOKIE_NAME = 'no-team-popup-show'; +export const ACTIVE_PROJECT_COOKIE_NAME = 'auth-active-project'; // Recaptcha export const RECAPTCHA_SITE_KEY = process.env.NEXT_PUBLIC_CAPTCHA_SITE_KEY; diff --git a/apps/web/app/helpers/cookies/index.ts b/apps/web/app/helpers/cookies/index.ts index f43070183..ead60ed20 100644 --- a/apps/web/app/helpers/cookies/index.ts +++ b/apps/web/app/helpers/cookies/index.ts @@ -10,7 +10,8 @@ import { ACTIVE_USER_TASK_COOKIE_NAME, NO_TEAM_POPUP_SHOW_COOKIE_NAME, ACTIVE_USER_ID_COOKIE_NAME, - MEET_JWT_TOKEN_COOKIE_NAME + MEET_JWT_TOKEN_COOKIE_NAME, + ACTIVE_PROJECT_COOKIE_NAME } from '@app/constants'; import { IDecodedRefreshToken } from '@app/interfaces/IAuthentication'; import { deleteCookie, getCookie, setCookie } from './helpers'; @@ -180,6 +181,15 @@ export function setActiveTeamIdCookie(teamIds: string, ctx?: NextCtx) { return setCookie(ACTIVE_TEAM_COOKIE_NAME, teamIds, { ...(ctx || {}) }); } +// Active Project id +export function getActiveProjectIdCookie(ctx?: NextCtx) { + return getCookie(ACTIVE_PROJECT_COOKIE_NAME, { ...(ctx || {}) }) as string; +} + +export function setActiveProjectIdCookie(teamIds: string, ctx?: NextCtx) { + return setCookie(ACTIVE_PROJECT_COOKIE_NAME, teamIds, { ...(ctx || {}) }); +} + // Organization Id export function getOrganizationIdCookie(ctx: NextCtx) { return getCookie(ORGANIZATION_ID_COOKIE_NAME, { ...ctx }) as string; diff --git a/apps/web/app/hooks/features/useOrganizationTeams.ts b/apps/web/app/hooks/features/useOrganizationTeams.ts index 12646adb0..791a66349 100644 --- a/apps/web/app/hooks/features/useOrganizationTeams.ts +++ b/apps/web/app/hooks/features/useOrganizationTeams.ts @@ -1,5 +1,6 @@ import { getActiveTeamIdCookie, + setActiveProjectIdCookie, setActiveTeamIdCookie, setOrganizationIdCookie } from '@app/helpers/cookies'; @@ -239,6 +240,12 @@ export function useOrganizationTeams() { setOrganizationIdCookie(team.organizationId); // This must be called at the end (Update store) setActiveTeamId(team.id); + + // Set Project Id to cookie + // TODO: Make it dynamic when we add Dropdown in Navbar + if (team && team.projects && team.projects.length) { + setActiveProjectIdCookie(team.projects[0].id); + } }, [setActiveTeamId] ); @@ -297,6 +304,12 @@ export function useOrganizationTeams() { newTeam, ...latestTeams.filter((team) => team.id !== newTeam.id) ]); + + // Set Project Id to cookie + // TODO: Make it dynamic when we add Dropdown in Navbar + if (newTeam && newTeam.projects && newTeam.projects.length) { + setActiveProjectIdCookie(newTeam.projects[0].id); + } } }); return res; diff --git a/apps/web/app/hooks/features/useTeamTasks.ts b/apps/web/app/hooks/features/useTeamTasks.ts index 6edac0be4..a270e0010 100644 --- a/apps/web/app/hooks/features/useTeamTasks.ts +++ b/apps/web/app/hooks/features/useTeamTasks.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-mixed-spaces-and-tabs */ import { getActiveTaskIdCookie, getActiveUserTaskCookie, @@ -224,6 +225,13 @@ export function useTeamTasks() { priority, size, tags, + // Set Project Id to cookie + // TODO: Make it dynamic when we add Dropdown in Navbar + ...(activeTeam?.projects && activeTeam?.projects.length > 0 + ? { + projectId: activeTeam.projects[0].id + } + : {}), ...(description ? { description: `

${description}

` } : {}), ...(members ? { members } : {}) }).then((res) => { @@ -231,7 +239,7 @@ export function useTeamTasks() { return res; }); }, - [createQueryCall, deepCheckAndUpdateTasks] + [createQueryCall, deepCheckAndUpdateTasks, activeTeam] ); const updateTask = useCallback( diff --git a/apps/web/app/interfaces/IOrganizationTeam.ts b/apps/web/app/interfaces/IOrganizationTeam.ts index 25ebe29f4..f45e00cf0 100644 --- a/apps/web/app/interfaces/IOrganizationTeam.ts +++ b/apps/web/app/interfaces/IOrganizationTeam.ts @@ -59,6 +59,7 @@ export interface IOrganizationTeamList { profile_link?: string; imageId?: string | null; image?: IImageAssets | null; + projects?: IProject[]; } export type IOrganizationTeamWithMStatus = IOrganizationTeamList; diff --git a/apps/web/app/interfaces/ITask.ts b/apps/web/app/interfaces/ITask.ts index 918368291..a8cbe5c2b 100644 --- a/apps/web/app/interfaces/ITask.ts +++ b/apps/web/app/interfaces/ITask.ts @@ -169,6 +169,7 @@ export interface ICreateTask { estimate: number; organizationId: string; tenantId: string; + projectId?: string | null; } export interface ITaskLinkedIssue { diff --git a/apps/web/app/services/server/guards/authenticated-guard.ts b/apps/web/app/services/server/guards/authenticated-guard.ts index d06320b40..9a5248668 100644 --- a/apps/web/app/services/server/guards/authenticated-guard.ts +++ b/apps/web/app/services/server/guards/authenticated-guard.ts @@ -1,5 +1,6 @@ import { getAccessTokenCookie, + getActiveProjectIdCookie, getActiveTaskIdCookie, getActiveTeamIdCookie, getOrganizationIdCookie, @@ -17,6 +18,7 @@ export async function authenticatedGuard( const organizationId = getOrganizationIdCookie({ req, res }); const teamId = getActiveTeamIdCookie({ req, res }); const taskId = getActiveTaskIdCookie({ req, res }); + const projectId = getActiveProjectIdCookie({ req, res }); const r_res = await currentAuthenticatedUserRequest({ bearer_token: access_token?.toString() || '' @@ -39,6 +41,7 @@ export async function authenticatedGuard( tenantId, organizationId, teamId, - taskId + taskId, + projectId }; } diff --git a/apps/web/app/services/server/requests/tasks.ts b/apps/web/app/services/server/requests/tasks.ts index c94503cb9..ba01dadc2 100644 --- a/apps/web/app/services/server/requests/tasks.ts +++ b/apps/web/app/services/server/requests/tasks.ts @@ -11,6 +11,7 @@ import { IUser } from '@app/interfaces'; export function getTeamTasksRequest({ tenantId, organizationId, + projectId, bearer_token, relations = [ 'tags', @@ -27,12 +28,14 @@ export function getTeamTasksRequest({ }: { tenantId: string; organizationId: string; + projectId: string; bearer_token: string; relations?: string[]; }) { const obj = { 'where[organizationId]': organizationId, 'where[tenantId]': tenantId, + 'where[projectId]': projectId, 'join[alias]': 'task', 'join[leftJoinAndSelect][members]': 'task.members', 'join[leftJoinAndSelect][user]': 'members.user' diff --git a/apps/web/pages/api/tasks/team.ts b/apps/web/pages/api/tasks/team.ts index 20b11eda7..337d5c008 100644 --- a/apps/web/pages/api/tasks/team.ts +++ b/apps/web/pages/api/tasks/team.ts @@ -10,7 +10,7 @@ export default async function handler( req: NextApiRequest, res: NextApiResponse ) { - const { $res, user, tenantId, organizationId, access_token } = + const { $res, user, tenantId, organizationId, access_token, projectId } = await authenticatedGuard(req, res); if (!user) return $res(); @@ -37,6 +37,7 @@ export default async function handler( tags: [], organizationId, tenantId, + projectId, estimate: 0, ...body, title // this must be called after ...body @@ -47,6 +48,7 @@ export default async function handler( const { data: tasks } = await getTeamTasksRequest({ tenantId, organizationId, + projectId, bearer_token: access_token }); From d1d73f87fce4ae3098c1d617e6d0e6d034393559 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Sat, 14 Oct 2023 13:40:17 +0530 Subject: [PATCH 2/3] fix: Build issue --- apps/web/app/services/server/requests/tasks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/app/services/server/requests/tasks.ts b/apps/web/app/services/server/requests/tasks.ts index ba01dadc2..92a72a234 100644 --- a/apps/web/app/services/server/requests/tasks.ts +++ b/apps/web/app/services/server/requests/tasks.ts @@ -28,9 +28,9 @@ export function getTeamTasksRequest({ }: { tenantId: string; organizationId: string; - projectId: string; bearer_token: string; relations?: string[]; + projectId?: string; }) { const obj = { 'where[organizationId]': organizationId, From 594b94f73d3ec3033436383b63c1dc2f896e8bd5 Mon Sep 17 00:00:00 2001 From: Badal Khatri Date: Mon, 16 Oct 2023 11:31:46 +0530 Subject: [PATCH 3/3] Updated get task --- apps/web/app/services/server/requests/tasks.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/app/services/server/requests/tasks.ts b/apps/web/app/services/server/requests/tasks.ts index 92a72a234..ae77ebb8e 100644 --- a/apps/web/app/services/server/requests/tasks.ts +++ b/apps/web/app/services/server/requests/tasks.ts @@ -11,7 +11,8 @@ import { IUser } from '@app/interfaces'; export function getTeamTasksRequest({ tenantId, organizationId, - projectId, + // TODO + // projectId, bearer_token, relations = [ 'tags', @@ -35,7 +36,8 @@ export function getTeamTasksRequest({ const obj = { 'where[organizationId]': organizationId, 'where[tenantId]': tenantId, - 'where[projectId]': projectId, + // TODO + // 'where[projectId]': projectId, 'join[alias]': 'task', 'join[leftJoinAndSelect][members]': 'task.members', 'join[leftJoinAndSelect][user]': 'members.user'