Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project-Team mapping #1560

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion apps/web/app/helpers/cookies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions apps/web/app/hooks/features/useOrganizationTeams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getActiveTeamIdCookie,
setActiveProjectIdCookie,
setActiveTeamIdCookie,
setOrganizationIdCookie
} from '@app/helpers/cookies';
Expand Down Expand Up @@ -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]
);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion apps/web/app/hooks/features/useTeamTasks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-mixed-spaces-and-tabs */
import {
getActiveTaskIdCookie,
getActiveUserTaskCookie,
Expand Down Expand Up @@ -224,14 +225,21 @@ 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: `<p>${description}</p>` } : {}),
...(members ? { members } : {})
}).then((res) => {
deepCheckAndUpdateTasks(res?.data?.items || [], true);
return res;
});
},
[createQueryCall, deepCheckAndUpdateTasks]
[createQueryCall, deepCheckAndUpdateTasks, activeTeam]
);

const updateTask = useCallback(
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/interfaces/IOrganizationTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface IOrganizationTeamList {
profile_link?: string;
imageId?: string | null;
image?: IImageAssets | null;
projects?: IProject[];
}

export type IOrganizationTeamWithMStatus = IOrganizationTeamList;
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/interfaces/ITask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export interface ICreateTask {
estimate: number;
organizationId: string;
tenantId: string;
projectId?: string | null;
}

export interface ITaskLinkedIssue {
Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/services/server/guards/authenticated-guard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getAccessTokenCookie,
getActiveProjectIdCookie,
getActiveTaskIdCookie,
getActiveTeamIdCookie,
getOrganizationIdCookie,
Expand All @@ -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() || ''
Expand All @@ -39,6 +41,7 @@ export async function authenticatedGuard(
tenantId,
organizationId,
teamId,
taskId
taskId,
projectId
};
}
5 changes: 5 additions & 0 deletions apps/web/app/services/server/requests/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { IUser } from '@app/interfaces';
export function getTeamTasksRequest({
tenantId,
organizationId,
// TODO
// projectId,
bearer_token,
relations = [
'tags',
Expand All @@ -29,10 +31,13 @@ export function getTeamTasksRequest({
organizationId: string;
bearer_token: string;
relations?: string[];
projectId?: string;
}) {
const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId,
// TODO
// 'where[projectId]': projectId,
'join[alias]': 'task',
'join[leftJoinAndSelect][members]': 'task.members',
'join[leftJoinAndSelect][user]': 'members.user'
Expand Down
4 changes: 3 additions & 1 deletion apps/web/pages/api/tasks/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -37,6 +37,7 @@ export default async function handler(
tags: [],
organizationId,
tenantId,
projectId,
estimate: 0,
...body,
title // this must be called after ...body
Expand All @@ -47,6 +48,7 @@ export default async function handler(
const { data: tasks } = await getTeamTasksRequest({
tenantId,
organizationId,
projectId,
bearer_token: access_token
});

Expand Down