summaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authorMichael Hunteman <michael@huntm.net>2024-10-15 17:44:29 -0700
committerMichael Hunteman <michael@huntm.net>2024-10-15 19:30:07 -0700
commit63f6003e658c87e9a803b8591abfcb322d6a87ed (patch)
treea4149952af970648c51c38ce7139dfde44d5d886 /client/src
parentaacf26f374f48b88d532d1528d9d07aabf537610 (diff)
Toggle password visibility
Diffstat (limited to 'client/src')
-rw-r--r--client/src/components/AdminLogin.tsx26
1 files changed, 23 insertions, 3 deletions
diff --git a/client/src/components/AdminLogin.tsx b/client/src/components/AdminLogin.tsx
index bfc96d2..f1f676f 100644
--- a/client/src/components/AdminLogin.tsx
+++ b/client/src/components/AdminLogin.tsx
@@ -1,6 +1,14 @@
-import React from 'react';
+import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
-import { Button, Paper, TextField, Typography } from '@mui/material';
+import {
+ Button,
+ Paper,
+ TextField,
+ Typography,
+ IconButton,
+ InputAdornment,
+} from '@mui/material';
+import { Visibility, VisibilityOff } from '@mui/icons-material';
import { useForm } from 'react-hook-form';
import { useAppDispatch } from '../hooks';
import { setAdmin } from '../slices/auth/adminSlice';
@@ -14,6 +22,7 @@ function GuestLogin() {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const [login] = useLoginAdminMutation();
+ const [showPassword, setShowPassword] = useState(false);
const {
register,
@@ -49,6 +58,8 @@ function GuestLogin() {
}
};
+ const handleClickShowPassword = () => setShowPassword((show) => !show);
+
return (
<form
style={{
@@ -89,9 +100,18 @@ function GuestLogin() {
<TextField
label="Password"
variant="outlined"
- type="password"
+ type={showPassword ? 'text' : 'password'}
margin="normal"
fullWidth
+ InputProps={{
+ endAdornment: (
+ <InputAdornment position="end">
+ <IconButton onClick={handleClickShowPassword}>
+ {showPassword ? <VisibilityOff /> : <Visibility />}
+ </IconButton>
+ </InputAdornment>
+ ),
+ }}
error={!!errors.password}
helperText={errors.password?.message}
required