Skip to content

Commit

Permalink
Merge pull request #2071 from daostack/bugfix/CW-2053-toggle-of-creat…
Browse files Browse the repository at this point in the history
…ed-space

Somehow I don't see the "add space" option in the navbar #2053
  • Loading branch information
andreymikhadyuk authored Sep 13, 2023
2 parents 23acf4f + aedb66b commit 56f26db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -51,7 +51,12 @@ const ProjectCreation: FC<ProjectCreationProps> = (props) => {
</CenterWrapper>
);

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,
Expand All @@ -65,6 +70,9 @@ const ProjectCreation: FC<ProjectCreationProps> = (props) => {
name: createdProject.name,
directParent: createdProject.directParent,
hasMembership: true,
hasPermissionToAddProject: Object.values(governance.circles).some(
(circle) => circle.allowedActions[GovernanceActions.CREATE_PROJECT],
),
notificationsAmount: 0,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -75,8 +78,8 @@ const ProjectCreationForm: FC<ProjectCreationFormProps> = (props) => {
} = props;
const dispatch = useDispatch();
const projects = useSelector(selectCommonLayoutProjects);

const formRef = useRef<CreationFormRef>(null);
const { data: governance, fetchGovernance } = useGovernanceByCommonId();
const {
isProjectCreationLoading,
project,
Expand All @@ -95,6 +98,7 @@ const ProjectCreationForm: FC<ProjectCreationFormProps> = (props) => {
() => getInitialValues(governanceCircles, initialCommon),
[governanceCircles],
);
const projectId = initialCommon?.id || project?.id;

const existingProjectsNames = projects
.map((project) => project?.name)
Expand Down Expand Up @@ -134,13 +138,22 @@ const ProjectCreationForm: FC<ProjectCreationFormProps> = (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 (
<>
Expand Down

0 comments on commit 56f26db

Please sign in to comment.