Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame^] | 1 | // 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 | |
| 5 | import {ReactElement} from 'react'; |
| 6 | import * as React from 'react' |
| 7 | import ReactDOM from 'react-dom'; |
| 8 | import styles from './IssueWizard.css'; |
| 9 | import DotMobileStepper from './issue-wizard/DotMobileStepper.tsx'; |
| 10 | import LandingStep from './issue-wizard/LandingStep.tsx'; |
| 11 | import 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 | */ |
| 17 | export 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 | */ |
| 65 | export function renderWizard(mount: HTMLElement): void { |
| 66 | ReactDOM.render(<IssueWizard />, mount); |
| 67 | } |