Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Create new project from the project dropdown #3360

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
);
CREDO23 marked this conversation as resolved.
Show resolved Hide resolved

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