blob: de5e8fb6b62bb946d5e6c2cc5c042196b02a5f6f [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {ReactElement} from 'react';
6import * as React from 'react'
7import ReactDOM from 'react-dom';
8import styles from './IssueWizard.css';
9import DotMobileStepper from './issue-wizard/DotMobileStepper.tsx';
10import LandingStep from './issue-wizard/LandingStep.tsx';
11import DetailsStep from './issue-wizard/DetailsStep.tsx'
12
13/**
14 * Base component for the issue filing wizard, wrapper for other components.
15 * @return Issue wizard JSX.
16 */
17export function IssueWizard(): ReactElement {
18 const [checkExisting, setCheckExisting] = React.useState(false);
19 const [userType, setUserType] = React.useState('End User');
20 const [activeStep, setActiveStep] = React.useState(0);
21 const [category, setCategory] = React.useState('');
22 const [textValues, setTextValues] = React.useState(
23 {
24 oneLineSummary: '',
25 stepsToReproduce: '',
26 describeProblem: '',
27 additionalComments: ''
28 });
29
30 let nextEnabled;
31 let page;
32 if (activeStep === 0){
33 page = <LandingStep
34 checkExisting={checkExisting}
35 setCheckExisting={setCheckExisting}
36 userType={userType}
37 setUserType={setUserType}
38 category={category}
39 setCategory={setCategory}
40 />;
41 nextEnabled = checkExisting && userType && (category != '');
42 } else if (activeStep === 1){
43 page = <DetailsStep textValues={textValues} setTextValues={setTextValues} category={category}/>;
44 nextEnabled = (textValues.oneLineSummary.trim() !== '') &&
45 (textValues.stepsToReproduce.trim() !== '') &&
46 (textValues.describeProblem.trim() !== '');
47 }
48
49 return (
50 <>
51 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins"></link>
52 <div className={styles.container}>
53 {page}
54 <DotMobileStepper nextEnabled={nextEnabled} activeStep={activeStep} setActiveStep={setActiveStep}/>
55 </div>
56 </>
57 );
58}
59
60/**
61 * Renders the issue filing wizard page.
62 * @param mount HTMLElement that the React component should be
63 * added to.
64 */
65export function renderWizard(mount: HTMLElement): void {
66 ReactDOM.render(<IssueWizard />, mount);
67}