Skip to content

Commit

Permalink
Merge pull request #3052 from ever-co/develop
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
evereq authored Sep 19, 2024
2 parents 68082e0 + bbeae2e commit 0a0f1f1
Show file tree
Hide file tree
Showing 20 changed files with 451 additions and 248 deletions.
12 changes: 10 additions & 2 deletions apps/web/app/api/daily-plan/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ export async function GET(req: Request, { params }: INextParams) {
return;
}

const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res);
const {
$res,
user,
tenantId,
organizationId,
teamId: organizationTeamId,
access_token
} = await authenticatedGuard(req, res);
if (!user) return $res('Unauthorized');

const response = await getDayPlansByEmployee({
bearer_token: access_token,
employeeId: id,
organizationId,
tenantId
tenantId,
organizationTeamId
});

return $res(response.data);
Expand Down
12 changes: 10 additions & 2 deletions apps/web/app/api/daily-plan/me/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ import { NextResponse } from 'next/server';
export async function GET(req: Request) {
const res = new NextResponse();

const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res);
const {
$res,
user,
tenantId,
organizationId,
teamId: organizationTeamId,
access_token
} = await authenticatedGuard(req, res);

if (!user) return $res('Unauthorized');

const response = await getMyDailyPlansRequest({
bearer_token: access_token,
organizationId,
tenantId
tenantId,
organizationTeamId
});

return $res(response.data);
Expand Down
12 changes: 10 additions & 2 deletions apps/web/app/api/daily-plan/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ export async function POST(req: Request) {
export async function GET(req: Request) {
const res = new NextResponse();

const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res);
const {
$res,
user,
tenantId,
organizationId,
teamId: organizationTeamId,
access_token
} = await authenticatedGuard(req, res);
if (!user) return $res('Unauthorized');

const response = await getAllDayPlans({
bearer_token: access_token,
organizationId,
tenantId
tenantId,
organizationTeamId
});

return $res(response.data);
Expand Down
12 changes: 10 additions & 2 deletions apps/web/app/api/daily-plan/task/[taskId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ export async function GET(req: Request, { params }: INextParams) {
return;
}

const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res);
const {
$res,
user,
tenantId,
organizationId,
teamId: organizationTeamId,
access_token
} = await authenticatedGuard(req, res);

if (!user) return $res('Unauthorized');

const response = await getPlansByTask({
taskId,
bearer_token: access_token,
organizationId,
tenantId
tenantId,
organizationTeamId
});

return $res(response.data);
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ export const DAILY_PLAN_SUGGESTION_MODAL_DATE = 'daily-plan-suggestion-modal-dat
export const TASKS_ESTIMATE_HOURS_MODAL_DATE = 'tasks-estimate-hours-modal-date';
export const DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE = 'daily-plan-estimate-hours-modal';
export const DEFAULT_PLANNED_TASK_ID = 'default-planned-task-id';
export const LAST_OPTION__CREATE_DAILY_PLAN_MODAL = 'last-option--create-daily-plan-modal';
export const HAS_VISITED_OUTSTANDING_TAB = 'has-visited-outstanding-tab';

// OAuth provider's keys

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/hooks/features/useAuthTeamTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function useAuthTeamTasks(user: IUser | undefined) {

const planned = useMemo(() => {
const outStandingTasksCount = estimatedTotalTime(
outstandingPlans.map((plan) => plan.tasks?.map((task) => task))
outstandingPlans?.map((plan) => plan.tasks?.map((task) => task))
).totalTasks;

const todayTasksCOunt = getTotalTasks(todayPlan);
Expand Down
4 changes: 3 additions & 1 deletion apps/web/app/hooks/features/useDailyPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export function useDailyPlan() {
);
}, [profileDailyPlans]);


const todayTasks = useMemo(() => {
return todayPlan
.map((plan) => {
Expand Down Expand Up @@ -355,8 +356,9 @@ export function useDailyPlan() {
if (firstLoad) {
getMyDailyPlans();
getAllDayPlans();
getEmployeeDayPlans(user?.employee.id || '');
}
}, [getMyDailyPlans, getAllDayPlans, firstLoad]);
}, [getMyDailyPlans, activeTeam?.id, getAllDayPlans, firstLoad, getEmployeeDayPlans, user?.employee.id]);

return {
dailyPlan,
Expand Down
3 changes: 2 additions & 1 deletion apps/web/app/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export * from './ITheme';
export * from './IRolePermissions';
export * from './ITimer';
export * from './IProject';
export * from './ILiveKiteCredentials'
export * from './ILiveKiteCredentials';
export * from './IBaseModel';

export * from './integrations/IGithubRepositories';
export * from './integrations/IGithubMetadata';
Expand Down
29 changes: 19 additions & 10 deletions apps/web/app/services/client/api/daily-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ import { deleteApi, get, post, put } from '../axios';
import {
DeleteResponse,
ICreateDailyPlan,
ID,
IDailyPlan,
IDailyPlanTasksUpdate,
IRemoveTaskFromManyPlans,
IUpdateDailyPlan,
PaginationResponse
} from '@app/interfaces';
import { getOrganizationIdCookie, getTenantIdCookie } from '@app/helpers';
import { getActiveTeamIdCookie, getOrganizationIdCookie, getTenantIdCookie } from '@app/helpers';

export function getAllDayPlansAPI() {
export function getAllDayPlansAPI(activeTeamId?: ID) {
const organizationId = getOrganizationIdCookie();
const tenantId = getTenantIdCookie();
const organizationTeamId = getActiveTeamIdCookie();

const relations = ['employee', 'tasks', 'employee.user', 'tasks.members', 'tasks.members.user'];

const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': activeTeamId || organizationTeamId
} as Record<string, string>;

relations.forEach((relation, i) => {
Expand All @@ -30,15 +33,17 @@ export function getAllDayPlansAPI() {
return get<PaginationResponse<IDailyPlan>>(`/daily-plan?${query}`, { tenantId });
}

export function getMyDailyPlansAPI() {
export function getMyDailyPlansAPI(activeTeamId?: ID) {
const organizationId = getOrganizationIdCookie();
const tenantId = getTenantIdCookie();
const organizationTeamId = getActiveTeamIdCookie();

const relations = ['employee', 'tasks', 'employee.user', 'tasks.members', 'tasks.members.user'];

const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': activeTeamId || organizationTeamId
} as Record<string, string>;

relations.forEach((relation, i) => {
Expand All @@ -49,15 +54,17 @@ export function getMyDailyPlansAPI() {
return get<PaginationResponse<IDailyPlan>>(`/daily-plan/me?${query}`, { tenantId });
}

export function getDayPlansByEmployeeAPI(employeeId?: string) {
export function getDayPlansByEmployeeAPI(employeeId?: string, activeTeamId?: ID) {
const organizationId = getOrganizationIdCookie();
const tenantId = getTenantIdCookie();
const organizationTeamId = getActiveTeamIdCookie();

const relations = ['employee', 'tasks', 'employee.user', 'tasks.members', 'tasks.members.user'];

const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': activeTeamId || organizationTeamId
} as Record<string, string>;

relations.forEach((relation, i) => {
Expand All @@ -71,10 +78,12 @@ export function getDayPlansByEmployeeAPI(employeeId?: string) {
export function getPlansByTaskAPI(taskId?: string) {
const organizationId = getOrganizationIdCookie();
const tenantId = getTenantIdCookie();
const organizationTeamId = getActiveTeamIdCookie();

const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': organizationTeamId
} as Record<string, string>;

const query = qs.stringify(obj);
Expand Down Expand Up @@ -106,9 +115,9 @@ export function removeTaskFromPlanAPI(data: IDailyPlanTasksUpdate, planId: strin
return put<IDailyPlan>(`/daily-plan/${planId}/task`, { ...data, organizationId }, { tenantId });
}

export function removeManyTaskFromPlansAPI({ taskId, data }: { taskId: string, data: IRemoveTaskFromManyPlans }) {
export function removeManyTaskFromPlansAPI({ taskId, data }: { taskId: string; data: IRemoveTaskFromManyPlans }) {
const organizationId = getOrganizationIdCookie();
return put<IDailyPlan[]>(`/daily-plan/${taskId}/remove`, { ...data, organizationId })
return put<IDailyPlan[]>(`/daily-plan/${taskId}/remove`, { ...data, organizationId });
}

export function deleteDailyPlanAPI(planId: string) {
Expand Down
60 changes: 43 additions & 17 deletions apps/web/app/services/server/requests/daily-plan.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import qs from 'qs';
import { ICreateDailyPlan, IDailyPlan, IDailyPlanTasksUpdate, IRemoveTaskFromManyPlans, IUpdateDailyPlan } from '@app/interfaces/IDailyPlan';
import {
ICreateDailyPlan,
IDailyPlan,
IDailyPlanTasksUpdate,
IRemoveTaskFromManyPlans,
IUpdateDailyPlan
} from '@app/interfaces/IDailyPlan';
import { serverFetch } from '../fetch';
import { DeleteResponse } from '@app/interfaces';
import { DeleteResponse, ID } from '@app/interfaces';

export function getAllDayPlans({
organizationId,
tenantId,
organizationTeamId,
bearer_token,
relations = ['employee', 'tasks', 'employee.user', 'tasks.members', 'tasks.members.user']
}: {
organizationId: string;
tenantId: string;
organizationId: ID;
tenantId: ID;
organizationTeamId: ID;
bearer_token: string;
relations?: string[];
}) {
const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': organizationTeamId
} as Record<string, string>;

relations.forEach((relation, i) => {
Expand All @@ -35,17 +44,20 @@ export function getAllDayPlans({
export function getMyDailyPlansRequest({
organizationId,
tenantId,
organizationTeamId,
bearer_token,
relations = ['employee', 'tasks', 'employee.user', 'tasks.members', 'tasks.members.user']
}: {
organizationId: string;
tenantId: string;
organizationId: ID;
tenantId: ID;
organizationTeamId: ID;
bearer_token: string;
relations?: string[];
}) {
const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': organizationTeamId
} as Record<string, string>;

relations.forEach((relation, i) => {
Expand All @@ -65,18 +77,21 @@ export function getDayPlansByEmployee({
employeeId,
organizationId,
tenantId,
organizationTeamId,
bearer_token,
relations = ['employee', 'tasks', 'employee.user', 'tasks.members', 'tasks.members.user']
}: {
employeeId: string;
organizationId: string;
tenantId: string;
employeeId: ID;
organizationId: ID;
tenantId: ID;
organizationTeamId: ID;
bearer_token: string;
relations?: string[];
}) {
const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': organizationTeamId
} as Record<string, string>;

relations.forEach((relation, i) => {
Expand All @@ -96,16 +111,19 @@ export function getPlansByTask({
taskId,
organizationId,
tenantId,
organizationTeamId,
bearer_token
}: {
taskId: string;
organizationId: string;
tenantId: string;
organizationId: ID;
tenantId: ID;
organizationTeamId: ID;
bearer_token: string;
}) {
const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId
'where[tenantId]': tenantId,
'where[organizationTeamId]': organizationTeamId
} as Record<string, string>;

const query = qs.stringify(obj);
Expand Down Expand Up @@ -203,11 +221,19 @@ export function deleteDailyPlanRequest({ planId, bearer_token }: { planId: strin
});
}

export function deleteDailyPlansManyRequest({ bearer_token, taskId, data }: { bearer_token?: string, taskId: string, data: IRemoveTaskFromManyPlans }) {
export function deleteDailyPlansManyRequest({
bearer_token,
taskId,
data
}: {
bearer_token?: string;
taskId: string;
data: IRemoveTaskFromManyPlans;
}) {
return serverFetch<IDailyPlan[]>({
method: 'PUT',
path: `/daily-plan/${taskId}/remove`,
body: data,
bearer_token,
bearer_token
});
}
6 changes: 5 additions & 1 deletion apps/web/lib/app/init-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function InitState() {
const { firstLoadIssueTypeData } = useIssueType();
const { firstLoadTaskRelatedIssueTypeData, loadTaskRelatedIssueTypeData } = useTaskRelatedIssueType();

const { firstLoadDailyPlanData } = useDailyPlan();
const { firstLoadDailyPlanData, getAllDayPlans, getMyDailyPlans, getEmployeeDayPlans } = useDailyPlan();
const { firstLoadTimeLogs } = useTimeLogs();

const { firstLoadDataEmployee } = useEmployee();
Expand Down Expand Up @@ -125,6 +125,10 @@ function InitState() {
useRefreshIntervalV2(loadTaskRelatedIssueTypeData, sixty_two_seconds, true);
useRefreshIntervalV2(loadTaskVersionData, sixty_two_seconds, true);

useRefreshIntervalV2(getAllDayPlans, sixty_two_seconds, true);
useRefreshIntervalV2(getMyDailyPlans, sixty_two_seconds, true);
useRefreshIntervalV2(getEmployeeDayPlans, sixty_two_seconds, true);

return <></>;
};
return Component;
Expand Down
Loading

0 comments on commit 0a0f1f1

Please sign in to comment.