2024-08-12 19:17:10 +05:30
|
|
|
import { useEffect, FC, useState } from "react";
|
2024-10-11 20:13:38 +05:30
|
|
|
// plane ui
|
2024-08-12 19:17:10 +05:30
|
|
|
import { EModalPosition, EModalWidth, ModalCore } from "@plane/ui";
|
2024-10-11 20:13:38 +05:30
|
|
|
// helpers
|
|
|
|
|
import { getAssetIdFromUrl } from "@/helpers/file.helper";
|
|
|
|
|
import { checkURLValidity } from "@/helpers/string.helper";
|
|
|
|
|
// plane web components
|
2024-08-12 18:24:42 +05:30
|
|
|
import { CreateProjectForm } from "@/plane-web/components/projects/create/root";
|
2024-10-11 20:13:38 +05:30
|
|
|
// plane web types
|
2024-08-12 18:24:42 +05:30
|
|
|
import { TProject } from "@/plane-web/types/projects";
|
2024-10-11 20:13:38 +05:30
|
|
|
// services
|
|
|
|
|
import { FileService } from "@/services/file.service";
|
|
|
|
|
const fileService = new FileService();
|
2024-03-08 17:38:42 +05:30
|
|
|
import { ProjectFeatureUpdate } from "./project-feature-update";
|
2022-11-19 19:51:26 +05:30
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
isOpen: boolean;
|
2023-10-17 20:34:16 +05:30
|
|
|
onClose: () => void;
|
2023-08-18 18:42:50 +05:30
|
|
|
setToFavorite?: boolean;
|
2023-10-17 20:34:16 +05:30
|
|
|
workspaceSlug: string;
|
2024-08-12 18:24:42 +05:30
|
|
|
data?: Partial<TProject>;
|
2022-11-19 19:51:26 +05:30
|
|
|
};
|
|
|
|
|
|
2024-03-08 17:38:42 +05:30
|
|
|
enum EProjectCreationSteps {
|
|
|
|
|
CREATE_PROJECT = "CREATE_PROJECT",
|
|
|
|
|
FEATURE_SELECTION = "FEATURE_SELECTION",
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-15 17:44:01 +05:30
|
|
|
export const CreateProjectModal: FC<Props> = (props) => {
|
2024-08-12 18:24:42 +05:30
|
|
|
const { isOpen, onClose, setToFavorite = false, workspaceSlug, data } = props;
|
2024-03-08 17:38:42 +05:30
|
|
|
// states
|
|
|
|
|
const [currentStep, setCurrentStep] = useState<EProjectCreationSteps>(EProjectCreationSteps.CREATE_PROJECT);
|
|
|
|
|
const [createdProjectId, setCreatedProjectId] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isOpen) {
|
|
|
|
|
setCurrentStep(EProjectCreationSteps.CREATE_PROJECT);
|
|
|
|
|
setCreatedProjectId(null);
|
|
|
|
|
}
|
|
|
|
|
}, [isOpen]);
|
2022-11-19 19:51:26 +05:30
|
|
|
|
2024-03-08 17:38:42 +05:30
|
|
|
const handleNextStep = (projectId: string) => {
|
|
|
|
|
if (!projectId) return;
|
|
|
|
|
setCreatedProjectId(projectId);
|
|
|
|
|
setCurrentStep(EProjectCreationSteps.FEATURE_SELECTION);
|
2023-07-25 15:43:28 +05:30
|
|
|
};
|
|
|
|
|
|
2024-10-11 20:13:38 +05:30
|
|
|
const handleCoverImageStatusUpdate = async (projectId: string, coverImage: string) => {
|
|
|
|
|
if (!checkURLValidity(coverImage)) {
|
|
|
|
|
await fileService.updateBulkProjectAssetsUploadStatus(workspaceSlug, projectId, projectId, {
|
|
|
|
|
asset_ids: [getAssetIdFromUrl(coverImage)],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-19 19:51:26 +05:30
|
|
|
return (
|
2024-08-12 19:17:10 +05:30
|
|
|
<ModalCore isOpen={isOpen} handleClose={onClose} position={EModalPosition.TOP} width={EModalWidth.XXL}>
|
|
|
|
|
{currentStep === EProjectCreationSteps.CREATE_PROJECT && (
|
|
|
|
|
<CreateProjectForm
|
|
|
|
|
setToFavorite={setToFavorite}
|
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
|
onClose={onClose}
|
2024-10-11 20:13:38 +05:30
|
|
|
updateCoverImageStatus={handleCoverImageStatusUpdate}
|
2024-08-12 19:17:10 +05:30
|
|
|
handleNextStep={handleNextStep}
|
|
|
|
|
data={data}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{currentStep === EProjectCreationSteps.FEATURE_SELECTION && (
|
|
|
|
|
<ProjectFeatureUpdate projectId={createdProjectId} workspaceSlug={workspaceSlug} onClose={onClose} />
|
|
|
|
|
)}
|
|
|
|
|
</ModalCore>
|
2022-11-19 19:51:26 +05:30
|
|
|
);
|
2024-03-15 17:44:01 +05:30
|
|
|
};
|