Skip to content

Commit

Permalink
add project in task details page / possiblity to edit
Browse files Browse the repository at this point in the history
  • Loading branch information
CREDO23 committed Nov 19, 2024
1 parent 5b1a6bd commit faa5214
Show file tree
Hide file tree
Showing 24 changed files with 499 additions and 231 deletions.
23 changes: 22 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,24 @@ 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
});

console.log(response);

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/IDailyPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export enum DailyPlanStatusEnum {
COMPLETED = 'completed'
}

export type IDailyPlanMode = 'today' | 'tomorow' | 'custom';
export type IDailyPlanMode = 'today' | 'tomorrow' | 'custom';
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[]>([])
2 changes: 1 addition & 1 deletion apps/web/components/pages/kanban/menu-kanban-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default function MenuKanbanCard({ item: task, member }: { item: ITeamTask
<PlanTask planMode="today" taskId={task.id} chooseMember={true} />
</li>
<li className="font-normal flex justify-between capitalize hover:bg-secondary-foreground/20 w-full text-left whitespace-nowrap text-sm hover:font-semibold hover:transition-all py-1 px-2">
<PlanTask planMode="tomorow" taskId={task.id} chooseMember={true} />
<PlanTask planMode="tomorrow" taskId={task.id} chooseMember={true} />
</li>
<li className="font-normal flex justify-between capitalize hover:bg-secondary-foreground/20 w-full text-left whitespace-nowrap text-sm hover:font-semibold hover:transition-all py-1 px-2">
<PlanTask planMode="custom" taskId={task.id} chooseMember={true} />
Expand Down
Loading

0 comments on commit faa5214

Please sign in to comment.