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'; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 19 | import { IconButtonProps, Stack, TextField, TextFieldProps } from '@mui/material'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 20 | import { styled } from '@mui/material/styles'; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 21 | import { ChangeEvent, ReactElement, useCallback, useEffect, useMemo, useState } from 'react'; |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 22 | import { useTranslation } from 'react-i18next'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 23 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 24 | import { StrengthValueCode } from '../utils/auth'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 25 | import { InfoButton, ToggleVisibilityButton } from './Button'; |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 26 | import { DialogContentList, InfosDialog, useDialogHandler } from './Dialog'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 27 | import { CheckedIcon, LockIcon, PenIcon, PersonIcon, RoundSaltireIcon } from './SvgIcon'; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 28 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 29 | const iconsHeight = '16px'; |
| 30 | const StyledCheckedIconSuccess = styled(CheckedIcon)(({ theme }) => ({ |
| 31 | height: iconsHeight, |
| 32 | color: theme.palette.success.main, |
| 33 | })); |
| 34 | const StyledRoundSaltireIconError = styled(RoundSaltireIcon)(({ theme }) => ({ |
| 35 | height: iconsHeight, |
| 36 | color: theme.palette.error.main, |
| 37 | })); |
| 38 | const StyledPenIconLight = styled(PenIcon)({ height: iconsHeight, color: '#03B9E9' }); |
| 39 | const StyledPenIconDark = styled(PenIcon)(({ theme }) => ({ height: iconsHeight, color: theme.palette.primary.dark })); |
| 40 | const StyledPersonIconLight = styled(PersonIcon)({ height: iconsHeight, color: '#03B9E9' }); |
| 41 | const StyledLockIcon = styled(LockIcon)({ height: iconsHeight, color: '#03B9E9' }); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 42 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 43 | export type NameStatus = 'default' | 'success' | 'taken' | 'invalid' | 'registration_failed'; |
| 44 | export type PasswordStatus = StrengthValueCode | 'registration_failed'; |
| 45 | |
| 46 | export type InputProps<StatusType extends NameStatus | PasswordStatus> = TextFieldProps & { |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 47 | status?: StatusType; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 48 | infoButtonProps?: IconButtonProps; |
| 49 | success?: boolean; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 50 | tooltipTitle: string; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 51 | }; |
| 52 | |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 53 | export const UsernameInput = ({ |
| 54 | infoButtonProps, |
| 55 | onChange: _onChange, |
| 56 | success, |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 57 | status = 'default', |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 58 | tooltipTitle, |
| 59 | ...props |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 60 | }: InputProps<NameStatus>) => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 61 | const { t } = useTranslation(); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 62 | const [isSelected, setIsSelected] = useState(false); |
| 63 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 64 | const [startAdornment, setStartAdornment] = useState<ReactElement | undefined>(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 65 | const dialogHandler = useDialogHandler(); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 66 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 67 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 68 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 69 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 70 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 71 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 72 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 73 | ); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 74 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 75 | useEffect(() => { |
| 76 | /* Handle startAdornment */ |
| 77 | let Icon = StyledPersonIconLight; |
| 78 | let visibility = 'visible'; |
| 79 | if (props.error) { |
| 80 | Icon = StyledRoundSaltireIconError; |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 81 | } else if (success) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 82 | Icon = StyledCheckedIconSuccess; |
| 83 | } else if (!isSelected && !input) { |
| 84 | visibility = 'hidden'; // keep icon's space so text does not move |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 85 | } |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 86 | setStartAdornment(<Icon sx={{ visibility }} />); |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 87 | }, [props.error, success, isSelected, input]); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 88 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 89 | /* |
| 90 | t('username_input_helper_text_success') |
| 91 | t('username_input_helper_text_taken') |
| 92 | t('username_input_helper_text_invalid') |
| 93 | t('username_input_helper_text_registration_failed') |
| 94 | */ |
| 95 | const helperText = t('username_input_helper_text', { context: `${status}` }); |
| 96 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 97 | return ( |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 98 | <> |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 99 | <InfosDialog {...dialogHandler.props} title={t('username_rules_dialog_title')} content={<UsernameRules />} /> |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 100 | <TextField |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 101 | color={inputColor(props.error, success)} |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 102 | label={t('username_input_label')} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 103 | variant="standard" |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 104 | helperText={status !== 'default' ? helperText : ''} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 105 | onChange={onChange} |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 106 | onFocus={() => setIsSelected(true)} |
| 107 | onBlur={() => setIsSelected(false)} |
| 108 | {...props} |
| 109 | InputLabelProps={{ |
| 110 | shrink: !!(isSelected || input), |
| 111 | ...props.InputLabelProps, |
| 112 | }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 113 | InputProps={{ |
| 114 | startAdornment, |
| 115 | endAdornment: ( |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 116 | <InfoButton tooltipTitle={tooltipTitle} {...infoButtonProps} onClick={dialogHandler.openDialog} /> |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 117 | ), |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 118 | ...props.InputProps, |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 119 | }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 120 | /> |
| 121 | </> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 122 | ); |
| 123 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 124 | |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 125 | export const PasswordInput = ({ |
| 126 | infoButtonProps, |
| 127 | onChange: _onChange, |
| 128 | success, |
| 129 | tooltipTitle, |
simon | 4e7445c | 2022-11-16 21:18:46 -0500 | [diff] [blame] | 130 | status = 'default', |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 131 | ...props |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 132 | }: InputProps<PasswordStatus>) => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 133 | const { t } = useTranslation(); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 134 | const [showPassword, setShowPassword] = useState(false); |
| 135 | const [isSelected, setIsSelected] = useState(false); |
| 136 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 137 | const [startAdornment, setStartAdornment] = useState<ReactElement | undefined>(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 138 | const dialogHandler = useDialogHandler(); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 139 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 140 | const toggleShowPassword = () => { |
| 141 | setShowPassword((showPassword) => !showPassword); |
| 142 | }; |
| 143 | |
| 144 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 145 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 146 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 147 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 148 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 149 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 150 | ); |
| 151 | |
| 152 | useEffect(() => { |
| 153 | /* Handle startAdornment */ |
| 154 | let Icon = StyledLockIcon; |
| 155 | let visibility = 'visible'; |
| 156 | if (props.error) { |
| 157 | Icon = StyledRoundSaltireIconError; |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 158 | } else if (success) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 159 | Icon = StyledCheckedIconSuccess; |
| 160 | } else if (!isSelected && !input) { |
| 161 | visibility = 'hidden'; // keep icon's space so text does not move |
| 162 | } |
| 163 | setStartAdornment(<Icon sx={{ visibility }} />); |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 164 | }, [props.error, success, isSelected, input]); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 165 | |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 166 | /* |
| 167 | t('password_input_helper_text_too_weak') |
| 168 | t('password_input_helper_text_weak') |
| 169 | t('password_input_helper_text_medium') |
| 170 | t('password_input_helper_text_strong') |
| 171 | t('password_input_helper_text_registration_failed') |
| 172 | */ |
| 173 | const helperText = t('password_input_helper_text', { context: `${status}` }); |
| 174 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 175 | return ( |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 176 | <> |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 177 | <InfosDialog {...dialogHandler.props} title={t('password_rules_dialog_title')} content={<PasswordRules />} /> |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 178 | <TextField |
Michelle Sepkap Sime | e580f42 | 2022-10-31 23:27:04 -0400 | [diff] [blame] | 179 | color={inputColor(props.error, success)} |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 180 | label={t('password_input_label')} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 181 | type={showPassword ? 'text' : 'password'} |
| 182 | variant="standard" |
| 183 | autoComplete="current-password" |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 184 | helperText={status !== 'default' ? helperText : ''} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 185 | onChange={onChange} |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 186 | onFocus={() => setIsSelected(true)} |
| 187 | onBlur={() => setIsSelected(false)} |
| 188 | {...props} |
| 189 | InputLabelProps={{ shrink: !!(isSelected || input), ...props.InputLabelProps }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 190 | InputProps={{ |
| 191 | startAdornment, |
| 192 | endAdornment: ( |
| 193 | <Stack direction="row" spacing="14px" alignItems="center"> |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 194 | <InfoButton tooltipTitle={tooltipTitle} {...infoButtonProps} onClick={dialogHandler.openDialog} /> |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 195 | <ToggleVisibilityButton visible={showPassword} onClick={toggleShowPassword} /> |
| 196 | </Stack> |
| 197 | ), |
simon | ab4eec8 | 2022-11-08 20:32:43 -0500 | [diff] [blame] | 198 | ...props.InputProps, |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 199 | }} |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 200 | /> |
| 201 | </> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 202 | ); |
| 203 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 204 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 205 | export const NickNameInput = ({ onChange: _onChange, ...props }: TextFieldProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 206 | const [isSelected, setIsSelected] = useState(false); |
| 207 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 208 | const [startAdornmentVisibility, setStartAdornmentVisibility] = useState<'visible' | 'hidden'>('hidden'); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 209 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 210 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 211 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 212 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 213 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 214 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 215 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 216 | ); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 217 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 218 | useEffect(() => { |
| 219 | setStartAdornmentVisibility(isSelected || input ? 'visible' : 'hidden'); |
| 220 | }, [isSelected, input]); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 221 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 222 | return ( |
| 223 | <TextField |
| 224 | {...props} |
| 225 | label="Nickname, surname..." |
| 226 | variant="standard" |
| 227 | InputLabelProps={{ shrink: !!(isSelected || input) }} |
| 228 | onChange={onChange} |
| 229 | InputProps={{ |
| 230 | startAdornment: <StyledPenIconLight sx={{ visibility: startAdornmentVisibility }} />, |
| 231 | }} |
| 232 | onFocus={() => setIsSelected(true)} |
| 233 | onBlur={() => setIsSelected(false)} |
| 234 | /> |
| 235 | ); |
| 236 | }; |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 237 | |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 238 | export const RegularInput = ({ onChange: _onChange, ...props }: TextFieldProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 239 | const [isSelected, setIsSelected] = useState(false); |
| 240 | const [input, setInput] = useState(props.defaultValue); |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 241 | const [startAdornmentVisibility, setStartAdornmentVisibility] = useState<'visible' | 'hidden'>('hidden'); |
| 242 | const [endAdornmentVisibility, setEndAdornmentVisibility] = useState<'visible' | 'hidden'>('visible'); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 243 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 244 | const onChange = useCallback( |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 245 | (event: ChangeEvent<HTMLInputElement>) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 246 | setInput(event.target.value); |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 247 | _onChange?.(event); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 248 | }, |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 249 | [_onChange] |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 250 | ); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 251 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 252 | useEffect(() => { |
| 253 | setStartAdornmentVisibility(isSelected || input ? 'visible' : 'hidden'); |
| 254 | setEndAdornmentVisibility(isSelected || input ? 'hidden' : 'visible'); |
| 255 | }, [isSelected, input]); |
idillon-sfl | 37c18df | 2022-08-26 18:44:27 -0400 | [diff] [blame] | 256 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 257 | return ( |
| 258 | <TextField |
| 259 | {...props} |
| 260 | variant="standard" |
| 261 | InputLabelProps={{ shrink: !!(isSelected || input) }} |
| 262 | onChange={onChange} |
| 263 | InputProps={{ |
| 264 | startAdornment: <StyledPenIconLight sx={{ visibility: startAdornmentVisibility }} />, |
| 265 | endAdornment: <StyledPenIconDark sx={{ visibility: endAdornmentVisibility }} />, |
| 266 | }} |
| 267 | onFocus={() => setIsSelected(true)} |
| 268 | onBlur={() => setIsSelected(false)} |
| 269 | /> |
| 270 | ); |
| 271 | }; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 272 | |
Michelle Sepkap Sime | 51c0045 | 2022-10-31 21:26:38 -0400 | [diff] [blame] | 273 | function inputColor( |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 274 | error?: boolean, |
| 275 | success?: boolean |
| 276 | ): 'success' | 'error' | 'primary' | 'secondary' | 'info' | 'warning' | undefined { |
| 277 | return error ? 'error' : success ? 'success' : 'primary'; |
| 278 | } |
| 279 | |
| 280 | const PasswordRules = () => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 281 | const { t } = useTranslation(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 282 | const items = useMemo( |
| 283 | () => [ |
| 284 | { |
| 285 | Icon: GppMaybe, |
| 286 | value: t('password_rule_one'), |
| 287 | }, |
| 288 | { |
| 289 | Icon: GppMaybe, |
| 290 | value: t('password_rule_two'), |
| 291 | }, |
| 292 | { |
| 293 | Icon: GppMaybe, |
| 294 | value: t('password_rule_three'), |
| 295 | }, |
| 296 | { |
| 297 | Icon: GppMaybe, |
| 298 | value: t('password_rule_four'), |
| 299 | }, |
| 300 | { |
| 301 | Icon: GppMaybe, |
| 302 | value: t('password_rule_five'), |
| 303 | }, |
| 304 | ], |
| 305 | [t] |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 306 | ); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 307 | return <DialogContentList items={items} />; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | const UsernameRules = () => { |
Michelle Sepkap Sime | 559cc80 | 2022-11-05 12:06:40 -0400 | [diff] [blame] | 311 | const { t } = useTranslation(); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 312 | const items = useMemo( |
| 313 | () => [ |
| 314 | { |
| 315 | Icon: Warning, |
| 316 | value: t('username_rule_one'), |
| 317 | }, |
| 318 | { |
| 319 | Icon: Warning, |
| 320 | value: t('username_rule_two'), |
| 321 | }, |
| 322 | { |
| 323 | Icon: Warning, |
| 324 | value: t('username_rule_three'), |
| 325 | }, |
| 326 | { |
| 327 | Icon: Warning, |
| 328 | value: t('username_rule_four'), |
| 329 | }, |
| 330 | ], |
| 331 | [t] |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 332 | ); |
idillon | ef9ab81 | 2022-11-18 13:46:24 -0500 | [diff] [blame] | 333 | return <DialogContentList items={items} />; |
Michelle Sepkap Sime | f5ebc2e | 2022-10-27 18:30:53 -0400 | [diff] [blame] | 334 | }; |