|
| 1 | +import React, { useCallback } from 'react'; |
| 2 | +import { Container, Typography, Radio, Button, Box, Card, CardActionArea, CardContent } from '@material-ui/core'; |
| 3 | +import { Product } from '../common/types'; |
| 4 | + |
| 5 | +type Props = { |
| 6 | + product: Product; |
| 7 | + handleOptionChange: (value: string) => void; |
| 8 | + executeSetup: () => void; |
| 9 | + handleNext: () => void; |
| 10 | + handleBack?: () => void; |
| 11 | + signInText: string; |
| 12 | + valueSet: { |
| 13 | + cloud: string; |
| 14 | + server: string; |
| 15 | + none: string; |
| 16 | + }; |
| 17 | +}; |
| 18 | +const OnboardingRadio = ({ |
| 19 | + checked, |
| 20 | + handleValueChange, |
| 21 | + value, |
| 22 | + title, |
| 23 | + description, |
| 24 | +}: { |
| 25 | + checked: string; |
| 26 | + handleValueChange: (v: string) => void; |
| 27 | + value: string; |
| 28 | + title: string; |
| 29 | + description?: string; |
| 30 | +}) => { |
| 31 | + return ( |
| 32 | + <Card variant="outlined" style={{ width: '100%' }}> |
| 33 | + <CardActionArea |
| 34 | + onClick={() => { |
| 35 | + handleValueChange(value); |
| 36 | + }} |
| 37 | + > |
| 38 | + <CardContent style={formControlStyles}> |
| 39 | + <Radio size="small" checked={checked === value} /> |
| 40 | + <Box flexDirection={'column'}> |
| 41 | + <Typography style={{ fontWeight: 'bold' }}>{title}</Typography> |
| 42 | + {description && <Typography>{description}</Typography>} |
| 43 | + </Box> |
| 44 | + </CardContent> |
| 45 | + </CardActionArea> |
| 46 | + </Card> |
| 47 | + ); |
| 48 | +}; |
| 49 | + |
| 50 | +export const JiraBitbucketOnboarding: React.FC<Props> = ({ |
| 51 | + product, |
| 52 | + handleOptionChange, |
| 53 | + executeSetup, |
| 54 | + handleNext, |
| 55 | + handleBack, |
| 56 | + signInText, |
| 57 | + valueSet, |
| 58 | +}) => { |
| 59 | + const [checked, setChecked] = React.useState(''); |
| 60 | + |
| 61 | + const handleValueChange = useCallback( |
| 62 | + (value: string) => { |
| 63 | + setChecked(value); |
| 64 | + handleOptionChange(value); |
| 65 | + }, |
| 66 | + [handleOptionChange], |
| 67 | + ); |
| 68 | + |
| 69 | + return ( |
| 70 | + <Container maxWidth="xs"> |
| 71 | + <Box style={wrapperStyles} flexDirection="column"> |
| 72 | + <Typography style={{ fontWeight: 'bold' }} variant="h2"> |
| 73 | + What version of {product} do you use? |
| 74 | + </Typography> |
| 75 | + <Box flexDirection="column" style={radioGroupStyles}> |
| 76 | + <OnboardingRadio |
| 77 | + checked={checked} |
| 78 | + handleValueChange={handleValueChange} |
| 79 | + value={valueSet.cloud} |
| 80 | + title="Cloud" |
| 81 | + description="For most of our users. The URL for accessing your site will typically be in the format mysite.atlassian.net" |
| 82 | + /> |
| 83 | + <OnboardingRadio |
| 84 | + checked={checked} |
| 85 | + handleValueChange={handleValueChange} |
| 86 | + value={valueSet.server} |
| 87 | + title="Server" |
| 88 | + description="For users with a custom site. The URL is usually a custom domain or IP address set up by your organization" |
| 89 | + /> |
| 90 | + <OnboardingRadio |
| 91 | + checked={checked} |
| 92 | + handleValueChange={handleValueChange} |
| 93 | + value={valueSet.none} |
| 94 | + title={product === 'Jira' ? "I don't have Jira" : "I don't have Bitbucket"} |
| 95 | + /> |
| 96 | + </Box> |
| 97 | + <Box |
| 98 | + style={{ |
| 99 | + display: 'flex', |
| 100 | + justifyContent: 'space-between', |
| 101 | + alignItems: 'flex-start', |
| 102 | + alignSelf: 'stretch', |
| 103 | + }} |
| 104 | + > |
| 105 | + <Button |
| 106 | + disabled={!handleBack} |
| 107 | + onClick={() => { |
| 108 | + handleBack && handleBack(); |
| 109 | + }} |
| 110 | + size="small" |
| 111 | + > |
| 112 | + Back |
| 113 | + </Button> |
| 114 | + <Button |
| 115 | + size="small" |
| 116 | + variant="contained" |
| 117 | + onClick={() => { |
| 118 | + executeSetup(); |
| 119 | + handleNext(); |
| 120 | + }} |
| 121 | + > |
| 122 | + {signInText} |
| 123 | + </Button> |
| 124 | + </Box> |
| 125 | + </Box> |
| 126 | + </Container> |
| 127 | + ); |
| 128 | +}; |
| 129 | + |
| 130 | +const wrapperStyles = { |
| 131 | + display: 'flex', |
| 132 | + justifyContent: 'center', |
| 133 | + alignItems: 'center', |
| 134 | + gap: '24px', |
| 135 | +}; |
| 136 | + |
| 137 | +const formControlStyles = { |
| 138 | + display: 'flex', |
| 139 | + padding: '12px', |
| 140 | + alignItems: 'flex-start', |
| 141 | + gap: '8px', |
| 142 | + alignSelf: 'stretch', |
| 143 | + borderRadius: '4px', |
| 144 | + border: '1px solid token(color.border)', |
| 145 | + backgroundColor: 'token(color.background)', |
| 146 | +}; |
| 147 | + |
| 148 | +const radioGroupStyles = { |
| 149 | + display: 'flex', |
| 150 | + gap: '8px', |
| 151 | + alignItems: 'flex-start', |
| 152 | + alignSelf: 'stretch', |
| 153 | +}; |
0 commit comments