Skip to content

Commit

Permalink
[Feature] Show | Edit project information in the task details page (#…
Browse files Browse the repository at this point in the history
…3347)

* add project in task details page / possiblity to edit

* Update apps/web/components/pages/task/details-section/blocks/task-secondary-info.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Ruslan Konviser <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent f89d96d commit f37fac7
Show file tree
Hide file tree
Showing 21 changed files with 494 additions and 228 deletions.
21 changes: 20 additions & 1 deletion apps/web/app/api/organization-projects/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app';

import { editOrganizationProjectsRequest } from '@app/services/server/requests';
import { editOrganizationProjectsRequest, getOrganizationProjectRequest } from '@app/services/server/requests';
import { NextResponse } from 'next/server';

export async function PUT(req: Request, { params }: { params: { id: string } }) {
Expand All @@ -23,3 +23,22 @@ export async function PUT(req: Request, { params }: { params: { id: string } })

return $res(response.data);
}

export async function GET(req: Request, { params }: { params: { id: string } }) {
const res = new NextResponse();
if (!params.id) {
return;
}

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

if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });

const response = await getOrganizationProjectRequest({
bearer_token: access_token,
id: params.id,
tenantId
});

return $res(response.data);
}
19 changes: 18 additions & 1 deletion apps/web/app/api/organization-projects/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app';

import { createOrganizationProjectRequest } from '@app/services/server/requests';
import { createOrganizationProjectRequest, getOrganizationProjectsRequest } from '@app/services/server/requests';
import { NextResponse } from 'next/server';

export async function POST(req: Request) {
Expand All @@ -19,3 +19,20 @@ export async function POST(req: Request) {

return $res(response.data);
}

export async function GET(req: Request) {
const res = new NextResponse();

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

if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });


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

return $res(response.data);
}
122 changes: 73 additions & 49 deletions apps/web/app/hooks/features/useOrganizationProjects.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,83 @@
import {
editOrganizationProjectSettingAPI,
editOrganizationProjectAPI
editOrganizationProjectAPI,
getOrganizationProjectAPI,
getOrganizationProjectsAPI
} from '@app/services/client/api';
import { userState } from '@app/stores';
import { useCallback } from 'react';
import { useAtom } from 'jotai';
import { useQuery } from '../useQuery';
import { organizationProjectsState } from '@/app/stores/organization-projects';

export function useOrganizationProjects() {
const [user] = useAtom(userState);

const {
loading: editOrganizationProjectLoading,
queryCall: editOrganizationProjectQueryCall
} = useQuery(editOrganizationProjectAPI);

const {
loading: editOrganizationProjectSettingLoading,
queryCall: editOrganizationProjectSettingQueryCall
} = useQuery(editOrganizationProjectSettingAPI);

const editOrganizationProjectSetting = useCallback(
(id: string, data: any) => {
if (user?.tenantId) {
return editOrganizationProjectSettingQueryCall(
id,
data,
user?.tenantId || ''
).then((res) => {
return res;
});
}
},
[user, editOrganizationProjectSettingQueryCall]
);

const editOrganizationProject = useCallback(
(id: string, data: any) => {
if (user?.tenantId) {
return editOrganizationProjectQueryCall(
id,
data,
user?.tenantId || ''
).then((res) => {
return res;
});
}
},
[user, editOrganizationProjectQueryCall]
);

return {
editOrganizationProjectSetting,
editOrganizationProjectSettingLoading,
editOrganizationProject,
editOrganizationProjectLoading
};
const [user] = useAtom(userState);
const [organizationProjects, setOrganizationProjects] = useAtom(organizationProjectsState);

const { loading: editOrganizationProjectLoading, queryCall: editOrganizationProjectQueryCall } =
useQuery(editOrganizationProjectAPI);

const { loading: editOrganizationProjectSettingLoading, queryCall: editOrganizationProjectSettingQueryCall } =
useQuery(editOrganizationProjectSettingAPI);

const { loading: getOrganizationProjectLoading, queryCall: getOrganizationProjectQueryCall } =
useQuery(getOrganizationProjectAPI);

const { loading: getOrganizationProjectsLoading, queryCall: getOrganizationProjectsQueryCall } =
useQuery(getOrganizationProjectsAPI);

const editOrganizationProjectSetting = useCallback(
(id: string, data: any) => {
if (user?.tenantId) {
return editOrganizationProjectSettingQueryCall(id, data, user?.tenantId || '').then((res) => {
return res;
});
}
},
[user, editOrganizationProjectSettingQueryCall]
);

const editOrganizationProject = useCallback(
(id: string, data: any) => {
if (user?.tenantId) {
return editOrganizationProjectQueryCall(id, data, user?.tenantId || '').then((res) => {
return res;
});
}
},
[user, editOrganizationProjectQueryCall]
);

const getOrganizationProject = useCallback(
async (id: string) => {
try {
return await getOrganizationProjectQueryCall(id);
} catch (error) {
console.log(error);
}
},
[getOrganizationProjectQueryCall]
);

const getOrganizationProjects = useCallback(async () => {
try {
const res = await getOrganizationProjectsQueryCall();

setOrganizationProjects(res.data.items);
} catch (error) {
console.log(error);
}
}, [getOrganizationProjectsQueryCall, setOrganizationProjects]);

return {
editOrganizationProjectSetting,
editOrganizationProjectSettingLoading,
editOrganizationProject,
editOrganizationProjectLoading,
getOrganizationProject,
getOrganizationProjectLoading,
getOrganizationProjects,
getOrganizationProjectsLoading,
organizationProjects,
};
}
2 changes: 1 addition & 1 deletion apps/web/app/interfaces/ITask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ITeamTask = {
estimateMinutes?: number;
dueDate: string;
startDate?: string | null;
projectId: string;
projectId: string | null;
public: boolean;
taskStatusId?: string;
resolvedAt?: string;
Expand Down
28 changes: 26 additions & 2 deletions apps/web/app/services/client/api/organization-projects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { IProject } from '@app/interfaces';
import { put } from '../axios';
import { IProject, PaginationResponse } from '@app/interfaces';
import { get, put } from '../axios';
import qs from 'qs';
import { getOrganizationIdCookie, getTenantIdCookie } from '@/app/helpers';

export function editOrganizationProjectSettingAPI(id: string, data: any, tenantId?: string) {
return put<any>(`/organization-projects/setting/${id}`, data, {
Expand All @@ -12,3 +14,25 @@ export function editOrganizationProjectAPI(id: string, data: any, tenantId?: str
tenantId
});
}

export function getOrganizationProjectAPI(id: string, tenantId?: string) {
return get<IProject>(`/organization-projects/${id}`, {
tenantId
});
}

export function getOrganizationProjectsAPI() {

const organizationId = getOrganizationIdCookie();
const tenantId = getTenantIdCookie();

const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId,
}
const query = qs.stringify(obj);

return get<PaginationResponse<IProject>>(`/organization-projects?${query}`, {
tenantId
});
}
43 changes: 43 additions & 0 deletions apps/web/app/services/server/requests/organization-projects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import qs from 'qs';
import { serverFetch } from '../fetch';
import { IProject, PaginationResponse } from '@/app/interfaces';

export function editOrganizationProjectsSettingsRequest({
id,
Expand Down Expand Up @@ -39,3 +41,44 @@ export function editOrganizationProjectsRequest({
tenantId
});
}

export function getOrganizationProjectRequest({
id,
tenantId,
bearer_token
}: {
id: string;
tenantId: string;
bearer_token: string;
}) {
return serverFetch<IProject>({
path: `/organization-projects/${id}`,
method: 'GET',
bearer_token,
tenantId
});
}

export function getOrganizationProjectsRequest({
tenantId,
organizationId,
bearer_token
}: {
tenantId: string;
bearer_token: string;
organizationId : string;
}) {

const obj = {
'where[organizationId]': organizationId,
'where[tenantId]': tenantId,
}
const query = qs.stringify(obj);

return serverFetch<PaginationResponse<IProject>>({
path: `/organization-projects?${query}`,
method: 'GET',
bearer_token,
tenantId
});
}
4 changes: 4 additions & 0 deletions apps/web/app/stores/organization-projects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { atom } from "jotai";
import { IProject } from "../interfaces";

export const organizationProjectsState = atom<IProject[]>([])
Loading

0 comments on commit f37fac7

Please sign in to comment.