feat(closes #274): add private room password visibility toggle
This commit is contained in:
parent
3b24c5275d
commit
677b13f47c
@ -1,12 +1,18 @@
|
|||||||
import { ChangeEvent, useState, SyntheticEvent, useMemo } from 'react'
|
import { ChangeEvent, useState, SyntheticEvent, useMemo } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import Button from '@mui/material/Button'
|
import Button from '@mui/material/Button'
|
||||||
|
import InputAdornment from '@mui/material/InputAdornment'
|
||||||
|
import IconButton from '@mui/material/IconButton'
|
||||||
import TextField from '@mui/material/TextField'
|
import TextField from '@mui/material/TextField'
|
||||||
import Dialog from '@mui/material/Dialog'
|
import Dialog from '@mui/material/Dialog'
|
||||||
import DialogActions from '@mui/material/DialogActions'
|
import DialogActions from '@mui/material/DialogActions'
|
||||||
import DialogContent from '@mui/material/DialogContent'
|
import DialogContent from '@mui/material/DialogContent'
|
||||||
import DialogContentText from '@mui/material/DialogContentText'
|
import DialogContentText from '@mui/material/DialogContentText'
|
||||||
import DialogTitle from '@mui/material/DialogTitle'
|
import DialogTitle from '@mui/material/DialogTitle'
|
||||||
|
import Tooltip from '@mui/material/Tooltip'
|
||||||
|
import Visibility from '@mui/icons-material/Visibility'
|
||||||
|
import VisibilityOff from '@mui/icons-material/VisibilityOff'
|
||||||
|
|
||||||
import { QueryParamKeys } from 'models/shell'
|
import { QueryParamKeys } from 'models/shell'
|
||||||
|
|
||||||
interface PasswordPromptProps {
|
interface PasswordPromptProps {
|
||||||
@ -19,6 +25,7 @@ export const PasswordPrompt = ({
|
|||||||
onPasswordEntered,
|
onPasswordEntered,
|
||||||
}: PasswordPromptProps) => {
|
}: PasswordPromptProps) => {
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
|
const [showPassword, setShowPassword] = useState(false)
|
||||||
|
|
||||||
const queryParams = useMemo(
|
const queryParams = useMemo(
|
||||||
() => new URLSearchParams(window.location.search),
|
() => new URLSearchParams(window.location.search),
|
||||||
@ -34,6 +41,10 @@ export const PasswordPrompt = ({
|
|||||||
onPasswordEntered(password)
|
onPasswordEntered(password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleClickShowPassword = () => {
|
||||||
|
setShowPassword(!showPassword)
|
||||||
|
}
|
||||||
|
|
||||||
const handlePasswordChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const handlePasswordChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
setPassword(e.target.value)
|
setPassword(e.target.value)
|
||||||
}
|
}
|
||||||
@ -42,6 +53,8 @@ export const PasswordPrompt = ({
|
|||||||
navigate(-1)
|
navigate(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const passwordToggleLabel = showPassword ? 'Hide password' : 'Show password'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen}>
|
<Dialog open={isOpen}>
|
||||||
<form onSubmit={handleFormSubmit}>
|
<form onSubmit={handleFormSubmit}>
|
||||||
@ -53,7 +66,7 @@ export const PasswordPrompt = ({
|
|||||||
impossible to know if the password you enter will match the password
|
impossible to know if the password you enter will match the password
|
||||||
entered by other peers.
|
entered by other peers.
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
<DialogContentText>
|
<DialogContentText sx={{ mb: 2 }}>
|
||||||
If there is a mismatch, you will be in the room but be unable to
|
If there is a mismatch, you will be in the room but be unable to
|
||||||
connect to others. An error will not be shown.
|
connect to others. An error will not be shown.
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
@ -62,11 +75,25 @@ export const PasswordPrompt = ({
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
id="password"
|
id="password"
|
||||||
label="Password"
|
label="Password"
|
||||||
type="password"
|
type={showPassword ? 'text' : 'password'}
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="standard"
|
variant="outlined"
|
||||||
value={password}
|
value={password}
|
||||||
onChange={handlePasswordChange}
|
onChange={handlePasswordChange}
|
||||||
|
InputProps={{
|
||||||
|
endAdornment: (
|
||||||
|
<InputAdornment position="end">
|
||||||
|
<Tooltip title={passwordToggleLabel}>
|
||||||
|
<IconButton
|
||||||
|
aria-label={passwordToggleLabel}
|
||||||
|
onClick={handleClickShowPassword}
|
||||||
|
>
|
||||||
|
{showPassword ? <Visibility /> : <VisibilityOff />}
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
</InputAdornment>
|
||||||
|
),
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
Loading…
Reference in New Issue
Block a user