Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 1 | // Copyright 2021 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 React from 'react'; |
| 6 | import { makeStyles } from '@material-ui/styles'; |
| 7 | import { RoleSelection } from './RoleSelection/RoleSelection.tsx'; |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 8 | import {ISSUE_WIZARD_PERSONAS_DETAIL, IssueWizardPersona} from '../IssueWizardTypes.tsx'; |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 9 | |
| 10 | const useStyles = makeStyles({ |
| 11 | flex: { |
| 12 | display: 'flex', |
| 13 | justifyContent: 'space-between', |
| 14 | } |
| 15 | }); |
| 16 | |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 17 | const getUserGroupSelectors = ( |
| 18 | value: IssueWizardPersona, |
| 19 | onSelectorClick: |
| 20 | (selector: string) => |
| 21 | (event: React.MouseEvent<HTMLElement>) => any) => { |
| 22 | const selectors = new Array(); |
| 23 | Object.entries(ISSUE_WIZARD_PERSONAS_DETAIL).forEach(([key, persona]) => { |
| 24 | selectors.push( |
| 25 | <RoleSelection |
| 26 | checked={IssueWizardPersona[value] === key} |
| 27 | handleOnClick={onSelectorClick(key)} |
| 28 | value={persona.name} |
| 29 | description={persona.description} |
| 30 | inputProps={{ 'aria-label': persona.name }} |
| 31 | /> |
| 32 | ); |
| 33 | }); |
| 34 | return selectors; |
| 35 | } |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 36 | /** |
| 37 | * RadioDescription contains a set of radio buttons and descriptions (RoleSelection) |
| 38 | * to be chosen from in the landing step of the Issue Wizard. |
| 39 | * |
| 40 | * @returns React.ReactElement |
| 41 | */ |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 42 | type Props = { |
| 43 | selectedRadio: IssueWizardPersona, |
| 44 | onClickRadio: Function, |
| 45 | } |
| 46 | |
| 47 | export const RadioDescription = (props: Props): React.ReactElement => { |
| 48 | const { selectedRadio, onClickRadio } = props; |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 49 | const classes = useStyles(); |
| 50 | |
| 51 | const handleRoleSelectionClick = (userGroup: string) => |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 52 | (event: React.MouseEvent<HTMLElement>) => onClickRadio(userGroup); |
| 53 | |
| 54 | const userGroupsSelectors = getUserGroupSelectors(selectedRadio, handleRoleSelectionClick); |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 55 | |
| 56 | return ( |
| 57 | <div className={classes.flex}> |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 58 | {userGroupsSelectors} |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 59 | </div> |
| 60 | ); |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 61 | } |