Skip to content

Commit

Permalink
[Feature] Create new project from the project dropdown (#3360)
Browse files Browse the repository at this point in the history
* createw new project in add task or task detail page

* add project dropdown in task creation process

* add coderabit suggetions
  • Loading branch information
CREDO23 authored Nov 27, 2024
1 parent 4eccf23 commit e5617bc
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 180 deletions.
27 changes: 26 additions & 1 deletion apps/web/app/hooks/features/useOrganizationProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import {
editOrganizationProjectSettingAPI,
editOrganizationProjectAPI,
getOrganizationProjectAPI,
getOrganizationProjectsAPI
getOrganizationProjectsAPI,
createOrganizationProjectAPI
} 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';
import { getOrganizationIdCookie, getTenantIdCookie } from '@/app/helpers';

export function useOrganizationProjects() {
const [user] = useAtom(userState);
Expand All @@ -26,6 +28,9 @@ export function useOrganizationProjects() {
const { loading: getOrganizationProjectsLoading, queryCall: getOrganizationProjectsQueryCall } =
useQuery(getOrganizationProjectsAPI);

const { loading: createOrganizationProjectLoading, queryCall: createOrganizationProjectQueryCall } =
useQuery(createOrganizationProjectAPI);

const editOrganizationProjectSetting = useCallback(
(id: string, data: any) => {
if (user?.tenantId) {
Expand Down Expand Up @@ -69,6 +74,24 @@ export function useOrganizationProjects() {
}
}, [getOrganizationProjectsQueryCall, setOrganizationProjects]);

const createOrganizationProject = useCallback(
async (data: { name: string }) => {
try {
const organizationId = getOrganizationIdCookie();
const tenantId = getTenantIdCookie();

const res = await createOrganizationProjectQueryCall({ ...data, organizationId, tenantId });

setOrganizationProjects([...organizationProjects, res.data]);

return res.data;
} catch (error) {
console.error(error);
}
},
[createOrganizationProjectQueryCall, organizationProjects, setOrganizationProjects]
);

return {
editOrganizationProjectSetting,
editOrganizationProjectSettingLoading,
Expand All @@ -79,5 +102,7 @@ export function useOrganizationProjects() {
getOrganizationProjects,
getOrganizationProjectsLoading,
organizationProjects,
createOrganizationProject,
createOrganizationProjectLoading
};
}
11 changes: 3 additions & 8 deletions apps/web/app/services/client/api/projects.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { IProject } from '@app/interfaces';
import { IProject, IProjectCreate } from '@app/interfaces';
import { post } from '../axios';

type Params = {
name: string;
tenantId: string;
organizationId: string;
};
export function createOrganizationProjectAPI(data: IProjectCreate) {

export function createOrganizationProjectAPI(params: Params) {
return post<IProject>(`/organization-projects`, params);
return post<IProject>(`/organization-projects`, data);
}
Loading

0 comments on commit e5617bc

Please sign in to comment.