|
|
@ -2,8 +2,7 @@ import React, { FC, ReactNode } from 'react' |
|
|
|
import { useSelector, useDispatch } from 'react-redux' |
|
|
|
import zxcvbn from 'zxcvbn' |
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' |
|
|
|
import { IconDefinition } from '@fortawesome/fontawesome-common-types' |
|
|
|
import { faKey, faExclamationTriangle, faCheckCircle } from '@fortawesome/free-solid-svg-icons' |
|
|
|
import { faKey } from '@fortawesome/free-solid-svg-icons' |
|
|
|
import { useTheme } from 'src/hooks' |
|
|
|
import { setFieldValue } from 'src/actions/forms' |
|
|
|
import { getFieldValue, getFieldNotification } from 'src/selectors/forms' |
|
|
@ -28,7 +27,6 @@ const PasswordField: FC<Props> = ({ |
|
|
|
const notification = useSelector<AppState, FormNotification | undefined>(state => getFieldNotification(state, 'password')) |
|
|
|
const dispatch = useDispatch() |
|
|
|
|
|
|
|
let icon: IconDefinition | undefined |
|
|
|
let passwordMessage: ReactNode | undefined |
|
|
|
let successState = false |
|
|
|
let errorState = false |
|
|
@ -39,7 +37,6 @@ const PasswordField: FC<Props> = ({ |
|
|
|
switch (score) { |
|
|
|
case 0: |
|
|
|
errorState = true |
|
|
|
icon = faExclamationTriangle |
|
|
|
passwordMessage = <span>Strength: <span style={{ color: theme.red }}>Unusable</span></span> |
|
|
|
break |
|
|
|
case 1: |
|
|
@ -55,7 +52,6 @@ const PasswordField: FC<Props> = ({ |
|
|
|
break |
|
|
|
case 4: |
|
|
|
successState = true |
|
|
|
icon = faCheckCircle |
|
|
|
passwordMessage = <span>Strength: <span style={{ color: theme.green }}>LIT</span></span> |
|
|
|
break |
|
|
|
} |
|
|
@ -72,7 +68,7 @@ const PasswordField: FC<Props> = ({ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const color = successState ? theme.green : errorState ? theme.red : theme.backgroundSecondary |
|
|
|
const color = successState ? theme.green : errorState ? theme.red : theme.primary |
|
|
|
|
|
|
|
const helpText = () => { |
|
|
|
if (notification) return <FormNotificationComponent notification={notification} /> |
|
|
@ -83,22 +79,17 @@ const PasswordField: FC<Props> = ({ |
|
|
|
<div className="field"> |
|
|
|
<FieldLabel>Password</FieldLabel> |
|
|
|
<div className="control-container"> |
|
|
|
<div className="icon"> |
|
|
|
<div className="icon" style={{ backgroundColor: color, color: theme.primaryAlternate }}> |
|
|
|
<FontAwesomeIcon icon={faKey} /> |
|
|
|
</div> |
|
|
|
<div className="control"> |
|
|
|
<input |
|
|
|
style={{ backgroundColor: theme.backgroundPrimary, borderColor: color, color: theme.text }} |
|
|
|
style={{ backgroundColor: theme.backgroundSecondary, borderColor: color, color: theme.text }} |
|
|
|
type="password" |
|
|
|
placeholder={placeholder} |
|
|
|
value={value} |
|
|
|
onChange={e => dispatch(setFieldValue('password', e.target.value))} /> |
|
|
|
</div> |
|
|
|
{icon && |
|
|
|
<div className="icon"> |
|
|
|
<FontAwesomeIcon icon={icon} /> |
|
|
|
</div> |
|
|
|
} |
|
|
|
</div> |
|
|
|
{helpText()} |
|
|
|
</div> |
|
|
|