Skip to content

Commit

Permalink
Merge pull request #2120 from ever-co/feat/static-build-support-8
Browse files Browse the repository at this point in the history
Feat/Next-Frontend APIs
  • Loading branch information
evereq authored Jan 25, 2024
2 parents 900bf62 + 8d4ae4c commit 236c373
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 148 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
};
}
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
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);
}
24 changes: 7 additions & 17 deletions apps/web/app/services/client/api/task-version.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import {
CreateResponse,
DeleteResponse,
ITaskVersionCreate,
ITaskVersionItemList,
PaginationResponse
} from '@app/interfaces';
import api, { get } from '../axios';
import { DeleteResponse, ITaskVersionCreate, ITaskVersionItemList, PaginationResponse } from '@app/interfaces';
import { deleteApi, get, post, put } from '../axios';

export function createTaskVersionAPI(data: ITaskVersionCreate, tenantId?: string) {
return api.post<CreateResponse<ITaskVersionCreate>>('/task-versions', data, {
headers: {
'Tenant-Id': tenantId
}
return post<ITaskVersionCreate>('/task-versions', data, {
tenantId
});
}

export function editTaskVersionAPI(id: string, data: ITaskVersionCreate, tenantId?: string) {
return api.put<CreateResponse<ITaskVersionCreate>>(`/task-versions/${id}`, data, {
headers: {
'Tenant-Id': tenantId
}
return put<ITaskVersionCreate>(`/task-versions/${id}`, data, {
tenantId
});
}

export function deleteTaskVersionAPI(id: string) {
return api.delete<DeleteResponse>(`/task-versions/${id}`);
return deleteApi<DeleteResponse>(`/task-versions/${id}`);
}

export async function getTaskVersionList(tenantId: string, organizationId: string, organizationTeamId: string | null) {
Expand Down
Loading

0 comments on commit 236c373

Please sign in to comment.