1
- import { Dispatch , SetStateAction , useEffect , useState } from 'react'
1
+ import React , { useEffect , useState } from 'react'
2
2
import { ZXCVBNResult } from 'zxcvbn'
3
3
import { FaCheck , FaEye , FaEyeSlash , FaInfo , FaShieldAlt } from 'react-icons/fa'
4
4
import clsx from 'clsx'
@@ -23,10 +23,10 @@ export const AccountPassword = (props: AccountPasswordProps) => {
23
23
const zxcvbn = require ( 'zxcvbn' )
24
24
const strength = zxcvbn ( pw )
25
25
setPwStrength ( strength )
26
- } , [ pw , setPwStrength ] )
26
+ } , [ pw ] )
27
27
28
28
/**
29
- * Returns a color name based on the current password stength score
29
+ * Returns a color name based on the current password strength score
30
30
*
31
31
* @returns {string }
32
32
*/
@@ -50,17 +50,14 @@ export const AccountPassword = (props: AccountPasswordProps) => {
50
50
color = 'bg-red-500'
51
51
break
52
52
}
53
-
54
53
return color
55
54
}
56
55
57
56
const pwStrengthPercent = ( ) : string => {
58
- let score = '0%'
59
- if ( pw ) score = `${ ( pwStrength . score / 4 ) * 100 } %`
60
- return score
57
+ return pw ? `${ ( pwStrength . score / 4 ) * 100 } %` : '0%'
61
58
}
62
59
63
- const passwordIsStrong = pwStrength ?. feedback ?. suggestions ?. length == 0 || false
60
+ const passwordIsStrong = pwStrength ?. feedback ?. suggestions ?. length === 0
64
61
65
62
return (
66
63
< div className = "space-y-4 max-w-md mx-auto" >
@@ -124,17 +121,28 @@ export const AccountPassword = (props: AccountPasswordProps) => {
124
121
} }
125
122
> </ div >
126
123
</ div >
127
- < div className = "flex w-full items-center gap-4 p-3 bg-zinc-200 dark:bg-zinc-800 dark:bg-opacity-60 rounded-b-md text-black/50 dark:text-white/50" >
128
- { passwordIsStrong ? < FaCheck /> : < FaInfo /> }
129
- { passwordIsStrong ? 'Strong password' : pwStrength ?. feedback ?. suggestions }
124
+ < div className = "flex w-full items-start gap-6 p-3 bg-zinc-200 dark:bg-zinc-800 dark:bg-opacity-60 rounded-b-md text-black/50 dark:text-white/50 text-sm" >
125
+ < div className = "mt-1" >
126
+ { passwordIsStrong ? < FaCheck /> : < FaInfo /> }
127
+ </ div >
128
+ < div className = "flex-grow" >
129
+ { passwordIsStrong ? (
130
+ 'Strong password'
131
+ ) : (
132
+ < ul className = "list-disc pl-4" >
133
+ { pwStrength ?. feedback ?. suggestions ?. map ( ( suggestion , index ) => (
134
+ < li key = { index } > { suggestion } </ li >
135
+ ) ) }
136
+ </ ul >
137
+ ) }
138
+ </ div >
130
139
</ div >
131
140
</ div >
132
141
133
142
< div className = "flex items-center justify-between gap-2 py-2" >
134
143
< div className = "flex items-center gap-2" >
135
- { ' ' }
136
144
< FaShieldAlt className = "text-emerald-500" />
137
- < span className = "text-neutral-500 text-sm" > Remember password on this device </ span >
145
+ < span className = "text-neutral-500 text-sm" > Remember password on this device</ span >
138
146
</ div >
139
147
< ToggleSwitch value = { savePassword } onToggle = { ( ) => setSavePassword ( ! savePassword ) } />
140
148
</ div >
0 commit comments