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