Skip to content

Commit

Permalink
Merge pull request #2121 from ever-co/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Jan 25, 2024
2 parents d906659 + cf3d384 commit 191e7f8
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 152 deletions.
35 changes: 18 additions & 17 deletions apps/web/app/api/task-versions/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu
import { deleteTaskVersionRequest, editTaskVersionRequest } from '@app/services/server/requests/task-version';
import { NextResponse } from 'next/server';

export async function PUT(req: Request, { params }: { params: { id: string } }) {
export async function PUT(req: Request, { params }: { params: { id: string } }) {
const res = new NextResponse();
const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res);

Expand All @@ -12,29 +12,30 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
const { id } = params;

const datas = (await req.json()) as unknown as ITaskVersionCreate;
return $res(
await editTaskVersionRequest({
id,
datas,
bearer_token: access_token,
tenantId
})
);

const response = await editTaskVersionRequest({
id,
datas,
bearer_token: access_token,
tenantId
});

return $res(response.data);
}

export async function DELETE(req: Request, { params }: { params: { id: string } }) {
export async function DELETE(req: Request, { params }: { params: { id: string } }) {
const res = new NextResponse();
const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res);

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

const { id } = params;

return $res(
await deleteTaskVersionRequest({
id,
bearer_token: access_token,
tenantId
})
);
const response = await deleteTaskVersionRequest({
id,
bearer_token: access_token,
tenantId
});

return $res(response.data);
}
4 changes: 3 additions & 1 deletion apps/web/app/api/task-versions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ export async function POST(req: Request) {

const body = (await req.json()) as unknown as ITaskVersionCreate;

return $res(await createVersionRequest(body, access_token, body?.tenantId));
const response = await createVersionRequest(body, access_token, body?.tenantId);

return $res(response.data);
}
17 changes: 8 additions & 9 deletions apps/web/app/api/tasks/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export async function GET(req: Request, { params }: { params: { id: string } })

const { id: taskId } = params;

return $res(
await getTaskByIdRequest({
taskId: taskId as string,
tenantId,
organizationId,
bearer_token: access_token
})
);
const response = await getTaskByIdRequest({
taskId: taskId as string,
tenantId,
organizationId,
bearer_token: access_token
});

return $res(response.data);
}

export async function PUT(req: Request, { params }: { params: { id: string } }) {
Expand Down Expand Up @@ -52,4 +52,3 @@ export async function PUT(req: Request, { params }: { params: { id: string } })

return $res(tasks);
}
// Unauthorized;
32 changes: 16 additions & 16 deletions apps/web/app/api/user/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export async function PUT(req: Request) {

const body = (await req.json()) as unknown as IUser;

return $res(
await updateUserAvatarRequest(
{
data: body,
id: user.id as string,
tenantId
},
access_token
)
const response = await updateUserAvatarRequest(
{
data: body,
id: user.id as string,
tenantId
},
access_token
);

return $res(response.data);
}

export async function DELETE(req: Request) {
Expand All @@ -46,11 +46,11 @@ export async function DELETE(req: Request) {
const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res);
if (!user) return $res('Unauthorized');

return $res(
await deleteUserRequest({
id: user.id,
bearer_token: access_token,
tenantId
})
);
const response = await deleteUserRequest({
id: user.id,
bearer_token: access_token,
tenantId
});

return $res(response.data);
}
12 changes: 6 additions & 6 deletions apps/web/app/api/user/reset/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export async function DELETE(req: Request) {
const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res);
if (!user) return $res('Unauthorized');

return $res(
await resetUserRequest({
bearer_token: access_token,
tenantId
})
);
const response = await resetUserRequest({
bearer_token: access_token,
tenantId
});

return $res(response.data);
}
135 changes: 68 additions & 67 deletions apps/web/app/hooks/features/useKanban.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,86 @@
import { kanbanBoardState } from "@app/stores/kanban";
import { useTaskStatus } from "./useTaskStatus";
import { useRecoilState } from "recoil";
import { useEffect, useState } from "react";
import { ITaskStatusItemList, ITeamTask } from "@app/interfaces";
import { useTeamTasks } from "./useTeamTasks";
import { kanbanBoardState } from '@app/stores/kanban';
import { useTaskStatus } from './useTaskStatus';
import { useRecoilState } from 'recoil';
import { useEffect, useState } from 'react';
import { ITaskStatusItemList, ITeamTask } from '@app/interfaces';
import { useTeamTasks } from './useTeamTasks';

export function useKanban() {
const [loading, setLoading] = useState<boolean>(true);

const [loading, setLoading] = useState<boolean>(true);

const [kanbanBoard, setKanbanBoard] = useRecoilState(kanbanBoardState);
const [kanbanBoard, setKanbanBoard] = useRecoilState(kanbanBoardState);

const taskStatusHook = useTaskStatus();
const taskStatusHook = useTaskStatus();

const { tasks, tasksFetching, updateTask } = useTeamTasks();
const { tasks, tasksFetching, updateTask } = useTeamTasks();

/**
* format data for kanban board
*/
useEffect(()=> {
if(!taskStatusHook.loading && !tasksFetching) {
let kanban = {};
/**
* format data for kanban board
*/
useEffect(() => {
if (!taskStatusHook.loading && !tasksFetching) {
let kanban = {};

const getTasksByStatus = (status: string | undefined) => {
return tasks.filter((task: ITeamTask)=> {
return task.status === status
})
}
const getTasksByStatus = (status: string | undefined) => {
return tasks.filter((task: ITeamTask) => {
return task.status === status;
});
};

taskStatusHook.taskStatus.map((taskStatus: ITaskStatusItemList,)=> {
kanban = {
...kanban,
[taskStatus.name ? taskStatus.name : ''] : getTasksByStatus(taskStatus.name)
}
});
setKanbanBoard(kanban)
setLoading(false)
}
},[taskStatusHook.loading, tasksFetching])
taskStatusHook.taskStatus.map((taskStatus: ITaskStatusItemList) => {
kanban = {
...kanban,
[taskStatus.name ? taskStatus.name : '']: getTasksByStatus(taskStatus.name)
};
});
setKanbanBoard(kanban);
setLoading(false);
}
}, [taskStatusHook.loading, tasksFetching]);

/**
* collapse or show kanban column
*/
const toggleColumn = (column: string, status: boolean) => {
const columnData = taskStatusHook.taskStatus.filter((taskStatus: ITaskStatusItemList,)=> {
return taskStatus.name === column
});
/**
* collapse or show kanban column
*/
const toggleColumn = (column: string, status: boolean) => {
const columnData = taskStatusHook.taskStatus.filter((taskStatus: ITaskStatusItemList) => {
return taskStatus.name === column;
});

const columnId = columnData[0].id;
const columnId = columnData[0].id;

taskStatusHook.editTaskStatus(columnId, {
isCollapsed: status
});
}
};

const isColumnCollapse = (column: string) => {
const columnData = taskStatusHook.taskStatus.filter((taskStatus: ITaskStatusItemList,)=> {
return taskStatus.name === column
});
const isColumnCollapse = (column: string) => {
const columnData = taskStatusHook.taskStatus.filter((taskStatus: ITaskStatusItemList) => {
return taskStatus.name === column;
});

return columnData[0].isCollapsed
}
return columnData[0].isCollapsed;
};

const reorderStatus = (itemStatus: string, index: number) => {
taskStatusHook.taskStatus.filter((status: ITaskStatusItemList)=> {
return status.name === itemStatus
}).map((status: ITaskStatusItemList)=> {
taskStatusHook.editTaskStatus(status.id, {
order: index
});
})
}
const reorderStatus = (itemStatus: string, index: number) => {
taskStatusHook.taskStatus
.filter((status: ITaskStatusItemList) => {
return status.name === itemStatus;
})
.map((status: ITaskStatusItemList) => {
taskStatusHook.editTaskStatus(status.id, {
order: index
});
});
};

return {
data: kanbanBoard,
isLoading: loading,
columns: taskStatusHook.taskStatus,
updateKanbanBoard: setKanbanBoard,
updateTaskStatus: updateTask,
toggleColumn,
isColumnCollapse,
reorderStatus
}
}
return {
data: kanbanBoard,
isLoading: loading,
columns: taskStatusHook.taskStatus,
updateKanbanBoard: setKanbanBoard,
updateTaskStatus: updateTask,
toggleColumn,
isColumnCollapse,
reorderStatus
};
}
3 changes: 2 additions & 1 deletion apps/web/app/hooks/features/usePublicOrganizationTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ export function usePublicOrganizationTeams() {
return res;
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[queryCall, setTeams, setAllTasks, setPublicTeam, teams, publicTeam]
);

const loadPublicTeamMiscData = useCallback(
(profileLink: string, teamId: string) => {
return queryCallMiscData(profileLink, teamId).then((res) => {
if (res.data.status === 404) {
if (res.data?.status === 404) {
setTeams([]);
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/hooks/features/useTeamTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function useTeamTasks() {
const getTaskById = useCallback(
(taskId: string) => {
return getTasksByIdQueryCall(taskId).then((res) => {
setDetailedTask(res?.data?.data || null);
setDetailedTask(res?.data || null);
return res;
});
},
Expand Down
37 changes: 37 additions & 0 deletions apps/web/app/hooks/useInfinityFetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use client';

import React from 'react';

export const getPartData = ({ offset = 0, limit = 10, arr = [] }: { offset?: number; limit?: number; arr: any[] }) =>
arr.slice(0, offset * limit + limit);

export const useInfinityScrolling = (arr: any) => {
const [offset, setOffset] = React.useState(0);
const [data, setData] = React.useState<any[]>(arr);

const getSomeTasks = React.useCallback(
(offset: number) => {
setData(getPartData({ arr, limit: 10, offset }));
},
[arr]
);

const nextOffset = React.useCallback(() => {
setOffset((prev) => prev + 1);
setData((prev) => getPartData({ arr: prev, limit: 10, offset }));
}, [offset]);

React.useEffect(() => {
console.log({ offset });
getSomeTasks(offset);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [offset]);

return {
offset,
setOffset,
getSomeTasks,
nextOffset,
data
};
};
6 changes: 3 additions & 3 deletions apps/web/app/services/client/api/settings.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IUser } from '@app/interfaces';
import api from '../axios';
import { post, put } from '../axios';

export function savePersonalSettingsAPI(id: string, data: any) {
return api.post<IUser>(`/user/${id}`, { ...data });
return post<IUser>(`/user/${id}`, { ...data });
}

// update/delete profile avatar for user setting
export function updateUserAvatarAPI(id: string, body: Partial<IUser>) {
return api.put<IUser>(`/user/${id}`, body);
return put<IUser>(`/user/${id}`, body);
}
Loading

0 comments on commit 191e7f8

Please sign in to comment.