|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useContext, useEffect, useState } from "react";
|
|
|
+import React, { useContext, useEffect, useMemo, useState } from "react";
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
import gradient from "assets/gradient.png";
|
|
|
@@ -8,13 +8,13 @@ import InputRow from "components/form-components/InputRow";
|
|
|
import Helper from "components/form-components/Helper";
|
|
|
import TitleSection from "components/TitleSection";
|
|
|
import { useSnapshot } from "valtio";
|
|
|
-import { OnboardingState } from "../OnboardingState";
|
|
|
import { useRouting } from "shared/routing";
|
|
|
import { Context } from "shared/Context";
|
|
|
import api from "shared/api";
|
|
|
import SaveButton from "components/SaveButton";
|
|
|
|
|
|
import backArrow from "assets/back_arrow.png";
|
|
|
+import { OFState } from "../state";
|
|
|
|
|
|
type ValidationError = {
|
|
|
hasError: boolean;
|
|
|
@@ -22,21 +22,26 @@ type ValidationError = {
|
|
|
};
|
|
|
|
|
|
export const NewProjectFC = () => {
|
|
|
- const snap = useSnapshot(OnboardingState);
|
|
|
+ const snap = useSnapshot(OFState);
|
|
|
const { user, setProjects, setCurrentProject } = useContext(Context);
|
|
|
const { pushFiltered } = useRouting();
|
|
|
const [buttonStatus, setButtonStatus] = useState("");
|
|
|
+ const [name, setName] = useState("");
|
|
|
+ const { projects } = useContext(Context);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (snap.userId !== null) {
|
|
|
- window.analytics.track("provision_new-project", {
|
|
|
- userId: snap.userId,
|
|
|
- });
|
|
|
- }
|
|
|
- }, [snap.userId]);
|
|
|
+ // useEffect(() => {
|
|
|
+ // if (snap.userId !== null) {
|
|
|
+ // window.analytics.track("provision_new-project", {
|
|
|
+ // userId: snap.userId,
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }, [snap.userId]);
|
|
|
+
|
|
|
+ const isFirstProject = useMemo(() => {
|
|
|
+ return !(projects?.length >= 1);
|
|
|
+ }, [projects]);
|
|
|
|
|
|
const validateProjectName = (): ValidationError => {
|
|
|
- const name = snap.projectName;
|
|
|
if (name === "") {
|
|
|
return {
|
|
|
hasError: true,
|
|
|
@@ -64,7 +69,7 @@ export const NewProjectFC = () => {
|
|
|
};
|
|
|
|
|
|
const createProject = async () => {
|
|
|
- const { projectName } = snap;
|
|
|
+ const projectName = name;
|
|
|
setButtonStatus("loading");
|
|
|
const validation = validateProjectName();
|
|
|
|
|
|
@@ -90,7 +95,10 @@ export const NewProjectFC = () => {
|
|
|
setProjects(projectList);
|
|
|
setCurrentProject(project);
|
|
|
|
|
|
- pushFiltered("/onboarding/integrations", []);
|
|
|
+ OFState.actions.nextStep({
|
|
|
+ id: project.id,
|
|
|
+ name: project.name,
|
|
|
+ });
|
|
|
setButtonStatus("success");
|
|
|
} catch (error) {
|
|
|
setButtonStatus("Couldn't create project, try again.");
|
|
|
@@ -100,7 +108,7 @@ export const NewProjectFC = () => {
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
- {!snap.isFirstProject && (
|
|
|
+ {!isFirstProject && (
|
|
|
<BackButton
|
|
|
onClick={() => {
|
|
|
pushFiltered("/dashboard", []);
|
|
|
@@ -120,19 +128,18 @@ export const NewProjectFC = () => {
|
|
|
<InputWrapper>
|
|
|
<ProjectIcon>
|
|
|
<ProjectImage src={gradient} />
|
|
|
- <Letter>
|
|
|
- {snap.projectName ? snap.projectName[0].toUpperCase() : "-"}
|
|
|
- </Letter>
|
|
|
+ <Letter>{name ? name.toUpperCase().substring(0, 1) : "-"}</Letter>
|
|
|
</ProjectIcon>
|
|
|
<InputRow
|
|
|
type="string"
|
|
|
- value={snap.projectName}
|
|
|
+ value={name}
|
|
|
setValue={(x: string) => {
|
|
|
setButtonStatus("");
|
|
|
- OnboardingState.actions.setProjectName(x);
|
|
|
+ setName(x);
|
|
|
}}
|
|
|
placeholder="ex: perspective-vortex"
|
|
|
width="470px"
|
|
|
+ disabled={buttonStatus === "loading"}
|
|
|
/>
|
|
|
</InputWrapper>
|
|
|
<NewProjectSaveButton
|