feat: add password visibility toggle in Admin Settings and Add New Users

This commit is contained in:
Gitead
2026-04-29 22:54:51 -04:00
parent 371dea54f7
commit 441cfcc8e3

View File

@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { Eye, EyeOff } from "lucide-react";
import { useQuery, useMutation } from "@tanstack/react-query"; import { useQuery, useMutation } from "@tanstack/react-query";
import { StaffTable } from "@/components/staffs/staff-table"; import { StaffTable } from "@/components/staffs/staff-table";
import { useToast } from "@/hooks/use-toast"; import { useToast } from "@/hooks/use-toast";
@@ -219,6 +220,8 @@ export default function SettingsPage() {
// MANAGE USERS (admin only) // MANAGE USERS (admin only)
const [newUsername, setNewUsername] = useState(""); const [newUsername, setNewUsername] = useState("");
const [newPassword, setNewPassword] = useState(""); const [newPassword, setNewPassword] = useState("");
const [showNewUserPassword, setShowNewUserPassword] = useState(false);
const [showAdminPassword, setShowAdminPassword] = useState(false);
const { const {
data: allUsers = [], data: allUsers = [],
@@ -410,14 +413,24 @@ export default function SettingsPage() {
</div> </div>
<div> <div>
<label className="block text-sm font-medium">Password</label> <label className="block text-sm font-medium">Password</label>
<input <div className="relative mt-1">
type="password" <input
value={newPassword} type={showNewUserPassword ? "text" : "password"}
onChange={(e) => setNewPassword(e.target.value)} value={newPassword}
className="mt-1 p-2 border rounded w-full" onChange={(e) => setNewPassword(e.target.value)}
placeholder="••••••••" className="p-2 border rounded w-full pr-10"
required placeholder="••••••••"
/> required
/>
<button
type="button"
onClick={() => setShowNewUserPassword((v) => !v)}
className="absolute inset-y-0 right-2 flex items-center text-gray-500 hover:text-gray-700"
tabIndex={-1}
>
{showNewUserPassword ? <EyeOff size={16} /> : <Eye size={16} />}
</button>
</div>
</div> </div>
<button <button
type="submit" type="submit"
@@ -466,12 +479,22 @@ export default function SettingsPage() {
<div> <div>
<label className="block text-sm font-medium">New Password</label> <label className="block text-sm font-medium">New Password</label>
<input <div className="relative mt-1">
type="password" <input
name="password" type={showAdminPassword ? "text" : "password"}
className="mt-1 p-2 border rounded w-full" name="password"
placeholder="••••••••" className="p-2 border rounded w-full pr-10"
/> placeholder="••••••••"
/>
<button
type="button"
onClick={() => setShowAdminPassword((v) => !v)}
className="absolute inset-y-0 right-2 flex items-center text-gray-500 hover:text-gray-700"
tabIndex={-1}
>
{showAdminPassword ? <EyeOff size={16} /> : <Eye size={16} />}
</button>
</div>
<p className="text-xs text-gray-500 mt-1"> <p className="text-xs text-gray-500 mt-1">
Leave blank to keep current password. Leave blank to keep current password.
</p> </p>