simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 18 | import { GppMaybe, Warning } from '@mui/icons-material'; |
| 19 | import { |
| 20 | IconButtonProps, |
| 21 | List, |
| 22 | ListItem, |
| 23 | ListItemIcon, |
| 24 | Stack, |
| 25 | TextField, |
| 26 | TextFieldProps, |
| 27 | Typography, |
| 28 | } from '@mui/material'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 29 | import { styled } from '@mui/material/styles'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 30 | import { ChangeEvent, ReactElement, useCallback, useEffect, useState } from 'react'; |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 31 | import { useTranslation } from 'react-i18next'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 32 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 33 | import { StrengthValueCode } from '../utils/auth'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 34 | import { InfoButton, ToggleVisibilityButton } from './Button'; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 35 | import RulesDialog from './RulesDialog'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 36 | import { CheckedIcon, LockIcon, PenIcon, PersonIcon, RoundSaltireIcon } from './SvgIcon'; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 37 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 38 | const iconsHeight = '16px'; |
| 39 | const StyledCheckedIconSuccess = styled(CheckedIcon)(({ theme }) => ({ |
| 40 | height: iconsHeight, |
| 41 | color: theme.palette.success.main, |
| 42 | })); |
| 43 | const StyledRoundSaltireIconError = styled(RoundSaltireIcon)(({ theme }) => ({ |
| 44 | height: iconsHeight, |
| 45 | color: theme.palette.error.main, |
| 46 | })); |
| 47 | const StyledPenIconLight = styled(PenIcon)({ height: iconsHeight, color: '#03B9E9' }); |
| 48 | const StyledPenIconDark = styled(PenIcon)(({ theme }) => ({ height: iconsHeight, color: theme.palette.primary.dark })); |
| 49 | const StyledPersonIconLight = styled(PersonIcon)({ height: iconsHeight, color: '#03B9E9' }); |
| 50 | const StyledLockIcon = styled(LockIcon)({ height: iconsHeight, color: '#03B9E9' }); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 51 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 52 | export type NameStatus = 'default' | 'success' | 'taken' | 'invalid' | 'registration_failed'; |
| 53 | export type PasswordStatus = StrengthValueCode | 'registration_failed'; |
| 54 | |
| 55 | export type InputProps<StatusType extends NameStatus | PasswordStatus> = TextFieldProps & { |
| 56 | status: StatusType; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 57 | infoButtonProps?: IconButtonProps; |
| 58 | success?: boolean; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 59 | tooltipTitle: string; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 62 | export const UsernameInput = ({ |
| 63 | infoButtonProps, |
| 64 | onChange: _onChange, |
| 65 | success, |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 66 | status, |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 67 | tooltipTitle, |
| 68 | ...props |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 69 | }: InputProps<NameStatus>) => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 70 | const { t } = useTranslation(); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 71 | const [isSelected, setIsSelected] = useState(false); |
| 72 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 73 | const [startAdornment, setStartAdornment] = useState<ReactElement | undefined>(); |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 74 | const [isDialogOpened, setIsDialogOpened] = useState<boolean>(false); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 75 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 76 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 77 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 78 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 79 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 80 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 81 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 82 | ); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 83 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 84 | useEffect(() => { |
| 85 | /* Handle startAdornment */ |
| 86 | let Icon = StyledPersonIconLight; |
| 87 | let visibility = 'visible'; |
| 88 | if (props.error) { |
| 89 | Icon = StyledRoundSaltireIconError; |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 90 | } else if (success) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 91 | Icon = StyledCheckedIconSuccess; |
| 92 | } else if (!isSelected && !input) { |
| 93 | visibility = 'hidden'; // keep icon's space so text does not move |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 94 | } |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 95 | setStartAdornment(<Icon sx={{ visibility }} />); |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 96 | }, [props.error, success, isSelected, input]); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 97 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 98 | /* |
| 99 | t('username_input_helper_text_success') |
| 100 | t('username_input_helper_text_taken') |
| 101 | t('username_input_helper_text_invalid') |
| 102 | t('username_input_helper_text_registration_failed') |
| 103 | */ |
| 104 | const helperText = t('username_input_helper_text', { context: `${status}` }); |
| 105 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 106 | return ( |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 107 | <> |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 108 | <RulesDialog |
| 109 | openDialog={isDialogOpened} |
| 110 | title={t('username_rules_dialog_title')} |
| 111 | closeDialog={() => setIsDialogOpened(false)} |
| 112 | > |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 113 | <UsernameRules /> |
| 114 | </RulesDialog> |
| 115 | <TextField |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 116 | color={inputColor(props.error, success)} |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 117 | label={t('username_input_label')} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 118 | variant="standard" |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 119 | helperText={status !== 'default' ? helperText : ''} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 120 | onChange={onChange} |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 121 | onFocus={() => setIsSelected(true)} |
| 122 | onBlur={() => setIsSelected(false)} |
| 123 | {...props} |
| 124 | InputLabelProps={{ |
| 125 | shrink: !!(isSelected || input), |
| 126 | ...props.InputLabelProps, |
| 127 | }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 128 | InputProps={{ |
| 129 | startAdornment, |
| 130 | endAdornment: ( |
| 131 | <InfoButton tooltipTitle={tooltipTitle} {...infoButtonProps} onClick={() => setIsDialogOpened(true)} /> |
| 132 | ), |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 133 | ...props.InputProps, |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 134 | }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 135 | /> |
| 136 | </> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 137 | ); |
| 138 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 139 | |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 140 | export const PasswordInput = ({ |
| 141 | infoButtonProps, |
| 142 | onChange: _onChange, |
| 143 | success, |
| 144 | tooltipTitle, |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 145 | status, |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 146 | ...props |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 147 | }: InputProps<PasswordStatus>) => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 148 | const { t } = useTranslation(); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 149 | const [showPassword, setShowPassword] = useState(false); |
| 150 | const [isSelected, setIsSelected] = useState(false); |
| 151 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 152 | const [startAdornment, setStartAdornment] = useState<ReactElement | undefined>(); |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 153 | const [isDialogOpened, setIsDialogOpened] = useState<boolean>(false); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 154 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 155 | const toggleShowPassword = () => { |
| 156 | setShowPassword((showPassword) => !showPassword); |
| 157 | }; |
| 158 | |
| 159 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 160 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 161 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 162 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 163 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 164 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 165 | ); |
| 166 | |
| 167 | useEffect(() => { |
| 168 | /* Handle startAdornment */ |
| 169 | let Icon = StyledLockIcon; |
| 170 | let visibility = 'visible'; |
| 171 | if (props.error) { |
| 172 | Icon = StyledRoundSaltireIconError; |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 173 | } else if (success) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 174 | Icon = StyledCheckedIconSuccess; |
| 175 | } else if (!isSelected && !input) { |
| 176 | visibility = 'hidden'; // keep icon's space so text does not move |
| 177 | } |
| 178 | setStartAdornment(<Icon sx={{ visibility }} />); |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 179 | }, [props.error, success, isSelected, input]); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 180 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 181 | /* |
| 182 | t('password_input_helper_text_too_weak') |
| 183 | t('password_input_helper_text_weak') |
| 184 | t('password_input_helper_text_medium') |
| 185 | t('password_input_helper_text_strong') |
| 186 | t('password_input_helper_text_registration_failed') |
| 187 | */ |
| 188 | const helperText = t('password_input_helper_text', { context: `${status}` }); |
| 189 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 190 | return ( |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 191 | <> |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 192 | <RulesDialog |
| 193 | openDialog={isDialogOpened} |
| 194 | title={t('password_rules_dialog_title')} |
| 195 | closeDialog={() => setIsDialogOpened(false)} |
| 196 | > |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 197 | <PasswordRules /> |
| 198 | </RulesDialog> |
| 199 | <TextField |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 200 | color={inputColor(props.error, success)} |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 201 | label={t('password_input_label')} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 202 | type={showPassword ? 'text' : 'password'} |
| 203 | variant="standard" |
| 204 | autoComplete="current-password" |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 205 | helperText={status !== 'default' ? helperText : ''} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 206 | onChange={onChange} |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 207 | onFocus={() => setIsSelected(true)} |
| 208 | onBlur={() => setIsSelected(false)} |
| 209 | {...props} |
| 210 | InputLabelProps={{ shrink: !!(isSelected || input), ...props.InputLabelProps }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 211 | InputProps={{ |
| 212 | startAdornment, |
| 213 | endAdornment: ( |
| 214 | <Stack direction="row" spacing="14px" alignItems="center"> |
| 215 | <InfoButton tooltipTitle={tooltipTitle} {...infoButtonProps} onClick={() => setIsDialogOpened(true)} /> |
| 216 | <ToggleVisibilityButton visible={showPassword} onClick={toggleShowPassword} /> |
| 217 | </Stack> |
| 218 | ), |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 219 | ...props.InputProps, |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 220 | }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 221 | /> |
| 222 | </> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 223 | ); |
| 224 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 225 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 226 | export const NickNameInput = ({ onChange: _onChange, ...props }: TextFieldProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 227 | const [isSelected, setIsSelected] = useState(false); |
| 228 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 229 | const [startAdornmentVisibility, setStartAdornmentVisibility] = useState<'visible' | 'hidden'>('hidden'); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 230 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 231 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 232 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 233 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 234 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 235 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 236 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 237 | ); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 238 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 239 | useEffect(() => { |
| 240 | setStartAdornmentVisibility(isSelected || input ? 'visible' : 'hidden'); |
| 241 | }, [isSelected, input]); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 242 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 243 | return ( |
| 244 | <TextField |
| 245 | {...props} |
| 246 | label="Nickname, surname..." |
| 247 | variant="standard" |
| 248 | InputLabelProps={{ shrink: !!(isSelected || input) }} |
| 249 | onChange={onChange} |
| 250 | InputProps={{ |
| 251 | startAdornment: <StyledPenIconLight sx={{ visibility: startAdornmentVisibility }} />, |
| 252 | }} |
| 253 | onFocus={() => setIsSelected(true)} |
| 254 | onBlur={() => setIsSelected(false)} |
| 255 | /> |
| 256 | ); |
| 257 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 258 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 259 | export const RegularInput = ({ onChange: _onChange, ...props }: TextFieldProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 260 | const [isSelected, setIsSelected] = useState(false); |
| 261 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 262 | const [startAdornmentVisibility, setStartAdornmentVisibility] = useState<'visible' | 'hidden'>('hidden'); |
| 263 | const [endAdornmentVisibility, setEndAdornmentVisibility] = useState<'visible' | 'hidden'>('visible'); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 264 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 265 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 266 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 267 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 268 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 269 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 270 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 271 | ); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 272 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 273 | useEffect(() => { |
| 274 | setStartAdornmentVisibility(isSelected || input ? 'visible' : 'hidden'); |
| 275 | setEndAdornmentVisibility(isSelected || input ? 'hidden' : 'visible'); |
| 276 | }, [isSelected, input]); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 277 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 278 | return ( |
| 279 | <TextField |
| 280 | {...props} |
| 281 | variant="standard" |
| 282 | InputLabelProps={{ shrink: !!(isSelected || input) }} |
| 283 | onChange={onChange} |
| 284 | InputProps={{ |
| 285 | startAdornment: <StyledPenIconLight sx={{ visibility: startAdornmentVisibility }} />, |
| 286 | endAdornment: <StyledPenIconDark sx={{ visibility: endAdornmentVisibility }} />, |
| 287 | }} |
| 288 | onFocus={() => setIsSelected(true)} |
| 289 | onBlur={() => setIsSelected(false)} |
| 290 | /> |
| 291 | ); |
| 292 | }; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 293 | |
Michelle Sepkap Sime | 51c0045 | 2022-10-31 21:26:38 -0400 | [diff] [blame] | 294 | function inputColor( |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 295 | error?: boolean, |
| 296 | success?: boolean |
| 297 | ): 'success' | 'error' | 'primary' | 'secondary' | 'info' | 'warning' | undefined { |
| 298 | return error ? 'error' : success ? 'success' : 'primary'; |
| 299 | } |
| 300 | |
| 301 | const PasswordRules = () => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 302 | const { t } = useTranslation(); |
| 303 | |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 304 | return ( |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 305 | <List> |
| 306 | <ListItem> |
| 307 | <ListItemIcon> |
| 308 | <GppMaybe /> |
| 309 | </ListItemIcon> |
| 310 | <Typography variant="body1">{t('password_rule_one')}</Typography> |
| 311 | </ListItem> |
| 312 | <ListItem> |
| 313 | <ListItemIcon> |
| 314 | <GppMaybe /> |
| 315 | </ListItemIcon> |
| 316 | <Typography variant="body1">{t('password_rule_two')}</Typography> |
| 317 | </ListItem> |
| 318 | <ListItem> |
| 319 | <ListItemIcon> |
| 320 | <GppMaybe /> |
| 321 | </ListItemIcon> |
| 322 | <Typography variant="body1">{t('password_rule_three')}</Typography> |
| 323 | </ListItem> |
| 324 | <ListItem> |
| 325 | <ListItemIcon> |
| 326 | <GppMaybe /> |
| 327 | </ListItemIcon> |
| 328 | <Typography variant="body1">{t('password_rule_four')}</Typography> |
| 329 | </ListItem> |
| 330 | <ListItem> |
| 331 | <ListItemIcon> |
| 332 | <GppMaybe /> |
| 333 | </ListItemIcon> |
| 334 | <Typography variant="body1">{t('password_rule_five')}</Typography> |
| 335 | </ListItem> |
| 336 | </List> |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 337 | ); |
| 338 | }; |
| 339 | |
| 340 | const UsernameRules = () => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 341 | const { t } = useTranslation(); |
| 342 | |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 343 | return ( |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 344 | <List> |
| 345 | <ListItem> |
| 346 | <ListItemIcon> |
| 347 | <Warning /> |
| 348 | </ListItemIcon> |
| 349 | <Typography variant="body1">{t('username_rule_one')}</Typography> |
| 350 | </ListItem> |
| 351 | <ListItem> |
| 352 | <ListItemIcon> |
| 353 | <Warning /> |
| 354 | </ListItemIcon> |
| 355 | <Typography variant="body1">{t('username_rule_two')}</Typography> |
| 356 | </ListItem> |
| 357 | <ListItem> |
| 358 | <ListItemIcon> |
| 359 | <Warning /> |
| 360 | </ListItemIcon> |
| 361 | <Typography variant="body1">{t('username_rule_three')}</Typography> |
| 362 | </ListItem> |
| 363 | <ListItem> |
| 364 | <ListItemIcon> |
| 365 | <Warning /> |
| 366 | </ListItemIcon> |
| 367 | <Typography variant="body1">{t('username_rule_four')}</Typography> |
| 368 | </ListItem> |
| 369 | </List> |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 370 | ); |
| 371 | }; |