import React, { useState, useEffect } from "react";
import ReactGA from 'react-ga';
import Button from "@material-ui/core/Button";
import Checkbox from '@mui/material/Checkbox';
import AliceCarousel from 'react-alice-carousel';
import 'react-alice-carousel/lib/alice-carousel.css';
import SearchIcon from '@mui/icons-material/Search';
import EmailIcon from '@mui/icons-material/Email';
import NewReleasesIcon from '@mui/icons-material/NewReleases';
import ExtensionIcon from '@mui/icons-material/Extension';
import LightbulbIcon from '@mui/icons-material/Lightbulb';
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
import theme from '../theme';
import {
Fade,
IconButton,
FormGroup,
FormControl,
InputLabel,
FormLabel,
FormControlLabel,
Select,
MenuItem,
Grid,
Paper,
Typography,
TextField,
Zoom,
List,
ListItem,
ListItemText,
Divider,
Tooltip,
Chip,
} from "@material-ui/core";
import { useAlert } from "react-alert";
import { useNavigate, Link } from "react-router-dom";
import WorkflowSearch from '../components/Workflowsearch.jsx';
import AuthenticationItem from '../components/AuthenticationItem.jsx';
import WorkflowPaper from "../components/WorkflowPaper.jsx"
import UsecaseSearch from "../components/UsecaseSearch.jsx"
const responsive = {
0: { items: 1 },
};
const WelcomeForm = (props) => {
const { userdata, globalUrl, discoveryWrapper, setDiscoveryWrapper, appFramework, getFramework, activeStep, setActiveStep, steps, skipped, setSkipped, getApps, apps, handleSetSearch, usecaseButtons, defaultSearch, setDefaultSearch, selectionOpen, setSelectionOpen, } = props
const usecaseItems = [
,
,
,
]
const [discoveryData, setDiscoveryData] = React.useState({})
const [name, setName] = React.useState("")
const [orgName, setOrgName] = React.useState("")
const [role, setRole] = React.useState("")
const [orgType, setOrgType] = React.useState("")
const [finishedApps, setFinishedApps] = React.useState([])
const [authentication, setAuthentication] = React.useState([]);
const [newSelectedApp, setNewSelectedApp] = React.useState({})
const [thumbIndex, setThumbIndex] = useState(0);
const [thumbAnimation, setThumbAnimation] = useState(false);
const [clickdiff, setclickdiff] = useState(0);
const isCloud = window.location.host === "localhost:3002" || window.location.host === "shuffler.io";
const alert = useAlert();
let navigate = useNavigate();
const onNodeSelect = (label) => {
if (setDiscoveryWrapper !== undefined) {
setDiscoveryWrapper(
{"id": label}
)
}
setSelectionOpen(true)
setDefaultSearch(label)
}
useEffect(() => {
if (userdata.id === undefined) {
return
}
if (userdata.name !== undefined && userdata.name !== null && userdata.name.length > 0) {
setName(userdata.name)
}
if (userdata.active_org !== undefined && userdata.active_org.name !== undefined && userdata.active_org.name !== null && userdata.active_org.name.length > 0) {
setOrgName(userdata.active_org.name)
}
}, [userdata])
useEffect(() => {
if (discoveryWrapper === undefined || discoveryWrapper.id === undefined) {
setDefaultSearch("")
var newfinishedApps = finishedApps
newfinishedApps.push(defaultSearch)
setFinishedApps(finishedApps)
}
}, [discoveryWrapper])
useEffect(() => {
if (
window.location.search !== undefined &&
window.location.search !== null
) {
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
const foundTab = params["tab"];
if (foundTab !== null && foundTab !== undefined && !isNaN(foundTab)) {
if (foundTab === 3 || foundTab === "3") {
console.log("SET SEARCH!!")
//setclickdiff(240)
}
} else {
//navigate(`/welcome?tab=1`)
}
}
}, [])
const isStepOptional = step => {
return step === 1
}
const sendUserUpdate = (name, role, userId) => {
const data = {
"tutorial": "welcome",
"firstname": name,
"company_role": role,
"user_id": userId,
}
const url = `${globalUrl}/api/v1/users/updateuser`
fetch(url, {
mode: "cors",
method: "PUT",
body: JSON.stringify(data),
credentials: "include",
crossDomain: true,
withCredentials: true,
headers: {
"Content-Type": "application/json; charset=utf-8",
},
})
.then((response) =>
response.json().then((responseJson) => {
if (responseJson["success"] === false) {
console.log("Update user success")
//alert.error("Failed updating org: ", responseJson.reason);
} else {
console.log("Update success!")
//alert.success("Successfully edited org!");
}
})
)
.catch((error) => {
console.log("Update err: ", error.toString())
//alert.error("Err: " + error.toString());
});
}
const sendOrgUpdate = (orgname, company_type, orgId, priority) => {
var data = {
org_id: orgId,
};
if (orgname.length > 0) {
data.name = orgname
}
if (company_type.length > 0) {
data.company_type = company_type
}
if (priority.length > 0) {
data.priority = priority
}
const url = globalUrl + `/api/v1/orgs/${orgId}`;
fetch(url, {
mode: "cors",
method: "POST",
body: JSON.stringify(data),
credentials: "include",
crossDomain: true,
withCredentials: true,
headers: {
"Content-Type": "application/json; charset=utf-8",
},
})
.then((response) =>
response.json().then((responseJson) => {
if (responseJson["success"] === false) {
console.log("Update of org failed")
//alert.error("Failed updating org: ", responseJson.reason);
} else {
//alert.success("Successfully edited org!");
}
})
)
.catch((error) => {
console.log("Update err: ", error.toString())
//alert.error("Err: " + error.toString());
});
}
var workflowDelay = -50
const NewHits = ({ hits }) => {
const [mouseHoverIndex, setMouseHoverIndex] = useState(-1)
var counted = 0
const paperAppContainer = {
display: "flex",
flexWrap: "wrap",
alignContent: "space-between",
marginTop: 5,
}
return (
{hits.map((data, index) => {
workflowDelay += 50
if (index > 3) {
return null
}
return (
)
})}
)
}
const isStepSkipped = step => {
return skipped.has(step)
}
const handleNext = () => {
setDefaultSearch("")
if (activeStep === 0) {
console.log("Should send basic information about org (fetch)")
setclickdiff(0)
navigate(`/welcome?tab=2`)
if (isCloud) {
ReactGA.event({
category: "welcome",
action: "click_page_one_next",
label: "",
})
}
if (userdata.active_org !== undefined && userdata.active_org.id !== undefined && userdata.active_org.id !== null && userdata.active_org.id.length > 0) {
sendOrgUpdate(orgName, orgType, userdata.active_org.id, "")
}
if (userdata.id !== undefined && userdata.id !== null && userdata.id.length > 0) {
sendUserUpdate(name, role, userdata.id)
}
} else if (activeStep === 1) {
console.log("Should send secondary info about apps and other things")
setDiscoveryWrapper({})
setclickdiff(240)
//setclickdiff(0)
navigate(`/welcome?tab=3`)
//handleSetSearch("Enrichment", "2. Enrich")
handleSetSearch(usecaseButtons[0].name, usecaseButtons[0].usecase)
getApps()
// Make sure it's up to date
if (getFramework !== undefined) {
getFramework()
}
} else if (activeStep === 2) {
console.log("Should send third page with workflows activated and the like")
}
let newSkipped = skipped;
if (isStepSkipped(activeStep)) {
newSkipped = new Set(newSkipped.values());
newSkipped.delete(activeStep);
}
setActiveStep(prevActiveStep => prevActiveStep + 1);
setSkipped(newSkipped);
}
const handleBack = () => {
setActiveStep(prevActiveStep => prevActiveStep - 1);
if (activeStep === 2) {
setDiscoveryWrapper({})
if (getFramework !== undefined) {
getFramework()
}
setclickdiff(0)
navigate("/welcome?tab=2")
} else if (activeStep === 1) {
//setclickdiff(0)
navigate("/welcome?tab=1")
}
};
const handleSkip = () => {
setclickdiff(240)
if (!isStepOptional(activeStep)) {
throw new Error("You can't skip a step that isn't optional.");
}
setActiveStep(prevActiveStep => prevActiveStep + 1);
setSkipped(prevSkipped => {
const newSkipped = new Set(prevSkipped.values());
newSkipped.add(activeStep);
return newSkipped;
});
};
const handleReset = () => {
setActiveStep(0);
};
useEffect(() => {
console.log("Selected app changed (effect)")
}, [newSelectedApp])
//const buttonWidth = 145
const buttonWidth = 450
const buttonMargin = 10
const sizing = 475
const buttonStyle = {
flex: 1,
width: "100%",
padding: 25,
margin: buttonMargin,
fontSize: 18,
}
const slideNext = () => {
if (!thumbAnimation && thumbIndex < usecaseItems.length - 1) {
//handleSetSearch(usecaseButtons[0].name, usecaseButtons[0].usecase)
setThumbIndex(thumbIndex + 1);
} else if (!thumbAnimation && thumbIndex === usecaseItems.length - 1) {
setThumbIndex(0)
}
};
const slidePrev = () => {
if (!thumbAnimation && thumbIndex > 0) {
setThumbIndex(thumbIndex - 1);
} else if (!thumbAnimation && thumbIndex === 0) {
setThumbIndex(usecaseItems.length-1)
}
};
const newButtonStyle = {
padding: 22,
flex: 1,
margin: buttonMargin,
minWidth: buttonWidth,
maxWidth: buttonWidth,
}
const getStepContent = (step) => {
switch (step) {
case 0:
return (
{/*isCloud ? null :
This data will be used within the product and NOT be shared unless cloud synchronization is configured.
*/}
First, we need some more information in order to understand how we best can help you find relevant Usecases. This is optional, but highly encouraged.
{
setName(e.target.value)
}}
/>
{
setOrgName(e.target.value)
}}
/>
Your Role
{
setRole(e.target.value)
}}
>
Student
Security Analyst/Engineer
SOC Manager
C-Level
Other
Company Type
{
setOrgType(e.target.value)
}}
>
Education
MSSP
Security Product Company
Other
)
case 1:
return (
Clicks the buttons below to find your apps, then we will help you find relevant workflows. Can't find your app? {
if (window.drift !== undefined) {
window.drift.api.startInteraction({ interactionId: 340043 })
} else {
console.log("Couldn't find drift in window.drift and not .drift-open-chat with querySelector: ", window.drift)
}
}}>Contact our App Developers!
{/*The app framework helps us access and authenticate the most important APIs for you. */}
{/*
What is your development experience?
Beginner
Intermediate
Automation Ninja
*/}
{/*Find your integrations! */}
} onClick={(event) => { onNodeSelect("CASES") }} >
Case Management
} onClick={(event) => { onNodeSelect("SIEM") }} >
SIEM
} onClick={(event) => { onNodeSelect("ERADICATION") }} >
Endpoint
} onClick={(event) => { onNodeSelect("INTEL") }} >
Intel
} onClick={(event) => { onNodeSelect("EMAIL") }} >
Email
{/*
What do you want to automate first ?
{ onNodeSelect("Email") }} />}
label="Email"
labelPlacement="Email"
/>
{ onNodeSelect("SIEM") }} />}
label="SIEM"
labelPlacement="SIEM"
/>
{ onNodeSelect("EDR") }} />}
label="EDR"
labelPlacement="EDR"
/>
*/}
{/*
What tools do you use?
Email
SIEM
EDR
Chat System
*/}
)
case 2:
return (
These are some of our Workflow templates, used to start new Workflows. Use the right and left buttons to find new Usecases , and click the orange button to build it.
{/*
*/}
{/*
{usecaseButtons.map((usecase, index) => {
return (
{
console.log("Clicked: ", usecase.name)
if (defaultSearch === usecase.name) {
//setSelectedUsecaseCategory("")
} else {
handleSetSearch(usecase.name, usecase.usecase)
}
//addFilter(usecase.name.slice(3,usecase.name.length))
}}
variant="outlined"
color="primary"
/>
)
})}
*/}
{/*
*/}
{
slidePrev()
}}
>
{
slideNext()
}}
>
)
default:
return "unknown step"
}
}
return (
{/*selectionOpen ?
: null*/}
{activeStep === steps.length ? (
You Will be Redirected to getting Start Page Wait for 5-sec.
Reset
Getting Started
) : (
{getStepContent(activeStep)}
{activeStep === 2 || activeStep === 1 ?
Back
{activeStep === steps.length - 1 ? "Finish" : "Next"}
:
Back
{/*isStepOptional(activeStep) && (
Skip
)*/}
= 4 ? "contained" : "outlined" : "outlined"}
color="primary"
onClick={handleNext}
style={{marginLeft: 10, }}
disabled={activeStep === 0 ? orgName.length === 0 || name.length === 0 : false}
>
{activeStep === steps.length - 1 ? "Finish" : "Next"}
{activeStep === 0 ?
{
console.log("Skip!")
if (isCloud) {
ReactGA.event({
category: "welcome",
action: "click_page_one_skip",
label: "",
})
}
setActiveStep(1)
navigate(`/welcome?tab=2`)
}}
style={{marginLeft: 240, }}
disabled={activeStep !== 0}
>
Skip
: null}
}
)}
);
}
export default WelcomeForm