Advertisement
kopyl

Untitled

Aug 17th, 2022
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useState } from "react";
  2. import { Box, Grid } from "@mui/material";
  3. import { Header } from "components/common/header";
  4. import { Sidebar } from "components/auth/sidebar";
  5. import { OnboardingOuterBox } from "components/onboarding";
  6. import { AWS, AWSConnecting } from "./aws";
  7. import Repo from "./repo";
  8. import { apiCloudConnectionsList } from "api";
  9.  
  10. const moveToRepoSelectionIfHasCompleteConnections = (
  11.   connections: any,
  12.   changeStep: any,
  13.   setConnections: any
  14. ) => {
  15.   const completeConnections = connections?.results?.filter(
  16.     ({ status }: any) => status === "COMPLETE"
  17.   );
  18.  
  19.   if (completeConnections?.length) {
  20.     changeStep(3);
  21.   }
  22.  
  23.   // setConnections(connections);
  24. };
  25.  
  26. const Onboarding = () => {
  27.   const [currentStepNumber, setCurrentStepNumber] = useState(2);
  28.   const [isRepoSelected, setIsRepoSelected] = useState(false);
  29.   const [isAWSConnectionInitialized, setIsAWSConnectionInitialized] =
  30.     useState(false);
  31.   const [__connections, setConnections] = useState(null);
  32.  
  33.   const initializeAWSConnection = () => {
  34.     setIsAWSConnectionInitialized(true);
  35.   };
  36.   const suspendAWSConnection = () => {
  37.     setIsAWSConnectionInitialized(false);
  38.     setCurrentStepNumber(2);
  39.   };
  40.  
  41.   const changeStep = (stepNumber: number) => {
  42.     if (stepNumber === 2 && isAWSConnectionInitialized) {
  43.       setCurrentStepNumber(2.1);
  44.       return;
  45.     }
  46.     setCurrentStepNumber(stepNumber);
  47.   };
  48.  
  49.   const steps: any = {
  50.     2: (
  51.       <AWS
  52.         changeStep={changeStep}
  53.         initializeAWSConnection={initializeAWSConnection}
  54.       />
  55.     ),
  56.     2.1: <AWSConnecting suspendAWSConnection={suspendAWSConnection} />,
  57.     3: <Repo changeStep={changeStep} />,
  58.   };
  59.  
  60.   apiCloudConnectionsList().then((connections) => {
  61.     moveToRepoSelectionIfHasCompleteConnections(
  62.       connections,
  63.       changeStep,
  64.       setConnections
  65.     );
  66.   });
  67.  
  68.   return (
  69.     <Grid container spacing={0} direction="row" style={{ minHeight: "100%" }}>
  70.       <Grid container flex={3} direction="column">
  71.         <Header />
  72.         <OnboardingOuterBox>{steps[currentStepNumber]}</OnboardingOuterBox>
  73.       </Grid>
  74.       <Sidebar
  75.         changeStep={changeStep}
  76.         currentStep={Math.floor(currentStepNumber)}
  77.         isRepoSelected={isRepoSelected}
  78.       />
  79.     </Grid>
  80.   );
  81. };
  82.  
  83. export default Onboarding;
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement