Explorar o código

Modified step handler to include data for finished onboardings

jnfrati %!s(int64=4) %!d(string=hai) anos
pai
achega
b217154a5e

+ 17 - 2
dashboard/src/main/home/ModalHandler.tsx

@@ -1,4 +1,4 @@
-import React, { useContext } from "react";
+import React, { useContext, useEffect } from "react";
 import useAuth from "shared/auth/useAuth";
 import useAuth from "shared/auth/useAuth";
 import { Context } from "shared/Context";
 import { Context } from "shared/Context";
 import Modal from "./modals/Modal";
 import Modal from "./modals/Modal";
@@ -15,9 +15,24 @@ const ModalHandler: React.FC<{
   setRefreshClusters: (x: boolean) => void;
   setRefreshClusters: (x: boolean) => void;
 }> = ({ setRefreshClusters }) => {
 }> = ({ setRefreshClusters }) => {
   const [isAuth] = useAuth();
   const [isAuth] = useAuth();
-  const { currentModal, setCurrentModal } = useContext(Context);
+  const { currentModal, setCurrentModal, currentProject } = useContext(Context);
+
+  useEffect(() => {
+    const projectOnboarding = localStorage.getItem(
+      `onboarding-${currentProject?.id}`
+    );
+    const parsedProjectOnboarding = JSON.parse(projectOnboarding);
+    if (parsedProjectOnboarding?.StepHandler?.finishedOnboarding === false) {
+      setCurrentModal("RedirectToOnboarding");
+    }
+  }, [currentProject?.id]);
+
   return (
   return (
     <>
     <>
+      {currentModal === "RedirectToOnboarding" && (
+        <a href="/onboarding/new-project"></a>
+      )}
+
       {currentModal === "ClusterInstructionsModal" && (
       {currentModal === "ClusterInstructionsModal" && (
         <Modal
         <Modal
           onRequestClose={() => setCurrentModal(null, null)}
           onRequestClose={() => setCurrentModal(null, null)}

+ 8 - 2
dashboard/src/main/home/onboarding/Onboarding.tsx

@@ -22,10 +22,16 @@ const Onboarding = () => {
 
 
   useEffect(() => {
   useEffect(() => {
     console.log(location);
     console.log(location);
-    if (snap.StepHandler.currentStep.url !== location.pathname) {
+    if (snap.StepHandler.finishedOnboarding) {
+      pushFiltered("/dashboard", []);
+    } else if (snap.StepHandler.currentStep.url !== location.pathname) {
       pushFiltered(snap.StepHandler.currentStep.url, []);
       pushFiltered(snap.StepHandler.currentStep.url, []);
     }
     }
-  }, [location.pathname, snap.StepHandler.currentStep.url]);
+  }, [
+    location.pathname,
+    snap.StepHandler.currentStep.url,
+    snap.StepHandler.finishedOnboarding,
+  ]);
 
 
   return (
   return (
     <StyledOnboarding>
     <StyledOnboarding>

+ 6 - 8
dashboard/src/main/home/onboarding/state/StepHandler.ts

@@ -40,7 +40,6 @@ const flow: FlowType = {
     provision_resources: {
     provision_resources: {
       previous: "connect_registry",
       previous: "connect_registry",
       url: "/onboarding/provision",
       url: "/onboarding/provision",
-      final: true,
       state_key: "provision_resources",
       state_key: "provision_resources",
     },
     },
   },
   },
@@ -50,8 +49,9 @@ type StepHandlerType = {
   flow: FlowType;
   flow: FlowType;
   currentStepName: StepKey;
   currentStepName: StepKey;
   currentStep: Step;
   currentStep: Step;
+  finishedOnboarding: boolean;
   actions: {
   actions: {
-    nextStep: () => { redirectUrl: string };
+    nextStep: () => void;
     clearState: () => void;
     clearState: () => void;
     restoreState: (prevState: StepHandlerType) => void;
     restoreState: (prevState: StepHandlerType) => void;
   };
   };
@@ -61,21 +61,19 @@ export const StepHandler: StepHandlerType = proxy({
   flow,
   flow,
   currentStepName: flow.initial,
   currentStepName: flow.initial,
   currentStep: flow.steps[flow.initial],
   currentStep: flow.steps[flow.initial],
+  finishedOnboarding: false,
   actions: {
   actions: {
     nextStep: () => {
     nextStep: () => {
       const cs = StepHandler.currentStep;
       const cs = StepHandler.currentStep;
       if (cs.final) {
       if (cs.final) {
-        return {
-          redirectUrl: "/dashboard?tab=provisioner",
-        };
+        StepHandler.finishedOnboarding = true;
+        return;
       }
       }
       const nextStepName = cs.next;
       const nextStepName = cs.next;
       const nextStep = flow.steps[nextStepName];
       const nextStep = flow.steps[nextStepName];
       StepHandler.currentStep = nextStep;
       StepHandler.currentStep = nextStep;
       StepHandler.currentStepName = nextStepName;
       StepHandler.currentStepName = nextStepName;
-      return {
-        redirectUrl: nextStep.url,
-      };
+      return;
     },
     },
     clearState: () => {
     clearState: () => {
       StepHandler.currentStepName = flow.initial;
       StepHandler.currentStepName = flow.initial;

+ 7 - 2
dashboard/src/main/home/onboarding/state/index.ts

@@ -24,10 +24,15 @@ export const OFState = proxy({
     },
     },
     saveState: () => {
     saveState: () => {
       const state = JSON.stringify(OFState);
       const state = JSON.stringify(OFState);
-      localStorage.setItem(`${OFState.StateHandler.project.id}`, state);
+      localStorage.setItem(
+        `onboarding-${OFState.StateHandler.project.id}`,
+        state
+      );
     },
     },
     restoreState: (projectId: number) => {
     restoreState: (projectId: number) => {
-      const notParsedPrevState = localStorage.getItem(`${projectId}`);
+      const notParsedPrevState = localStorage.getItem(
+        `onboarding-${projectId}`
+      );
       if (!notParsedPrevState) {
       if (!notParsedPrevState) {
         return;
         return;
       }
       }