diff --git a/src/pages/commonCreation/components/ProjectCreation/ProjectCreation.tsx b/src/pages/commonCreation/components/ProjectCreation/ProjectCreation.tsx index 72c1f6112d..5dd74b89c6 100644 --- a/src/pages/commonCreation/components/ProjectCreation/ProjectCreation.tsx +++ b/src/pages/commonCreation/components/ProjectCreation/ProjectCreation.tsx @@ -8,7 +8,7 @@ import { GovernanceActions } from "@/shared/constants"; import { useRoutesContext } from "@/shared/contexts"; import { useCommon, useGovernance } from "@/shared/hooks/useCases"; import { LongLeftArrowIcon } from "@/shared/icons"; -import { Common, Project } from "@/shared/models"; +import { Common, Governance, Project } from "@/shared/models"; import { Container, Loader } from "@/shared/ui-kit"; import { commonActions, ProjectsStateItem } from "@/store/states"; import { CenterWrapper } from "../CenterWrapper"; @@ -51,7 +51,12 @@ const ProjectCreation: FC = (props) => { ); - const handleCreatedProject = (createdProject: Common) => { + const handleCreatedProject = (data: { + project: Common; + governance: Governance; + }) => { + const { project: createdProject, governance } = data; + if (isEditing) { CommonEventEmitter.emit(CommonEvent.ProjectUpdated, { commonId: createdProject.id, @@ -65,6 +70,9 @@ const ProjectCreation: FC = (props) => { name: createdProject.name, directParent: createdProject.directParent, hasMembership: true, + hasPermissionToAddProject: Object.values(governance.circles).some( + (circle) => circle.allowedActions[GovernanceActions.CREATE_PROJECT], + ), notificationsAmount: 0, }; diff --git a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx index 683c2fc63b..dfe07cfd45 100644 --- a/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx +++ b/src/pages/commonCreation/components/ProjectCreation/components/ProjectCreationForm/ProjectCreationForm.tsx @@ -2,8 +2,11 @@ import React, { FC, useCallback, useEffect, useMemo, useRef } from "react"; import { useDispatch, useSelector } from "react-redux"; import { useCommonUpdate } from "@/pages/OldCommon/components/CommonListContainer/EditCommonModal/useCases"; import { usePreventReload } from "@/shared/hooks"; -import { useProjectCreation } from "@/shared/hooks/useCases"; -import { Circles, Common, Project } from "@/shared/models"; +import { + useGovernanceByCommonId, + useProjectCreation, +} from "@/shared/hooks/useCases"; +import { Circles, Common, Governance, Project } from "@/shared/models"; import { Loader, LoaderVariant, @@ -27,7 +30,7 @@ interface ProjectCreationFormProps { governanceCircles: Circles; initialCommon?: Project; isEditing: boolean; - onFinish: (createdProject: Common) => void; + onFinish: (data: { project: Common; governance: Governance }) => void; onCancel: () => void; } @@ -75,8 +78,8 @@ const ProjectCreationForm: FC = (props) => { } = props; const dispatch = useDispatch(); const projects = useSelector(selectCommonLayoutProjects); - const formRef = useRef(null); + const { data: governance, fetchGovernance } = useGovernanceByCommonId(); const { isProjectCreationLoading, project, @@ -95,6 +98,7 @@ const ProjectCreationForm: FC = (props) => { () => getInitialValues(governanceCircles, initialCommon), [governanceCircles], ); + const projectId = initialCommon?.id || project?.id; const existingProjectsNames = projects .map((project) => project?.name) @@ -134,13 +138,22 @@ const ProjectCreationForm: FC = (props) => { }; }, []); + useEffect(() => { + if (projectId) { + fetchGovernance(projectId); + } + }, [projectId]); + useEffect(() => { const finalProject = project || updatedProject; - if (finalProject) { - onFinish(finalProject); + if (finalProject && governance) { + onFinish({ + project: finalProject, + governance, + }); } - }, [project, updatedProject]); + }, [project, updatedProject, governance]); return ( <>