107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
|
|
interface PasswordModalProps {
|
|
isOpen: boolean;
|
|
onSubmit: (password: string) => void;
|
|
onCancel: () => void;
|
|
isLoading?: boolean;
|
|
}
|
|
|
|
const PasswordModal: React.FC<PasswordModalProps> = ({
|
|
isOpen,
|
|
onSubmit,
|
|
onCancel,
|
|
isLoading = false,
|
|
}) => {
|
|
const [password, setPassword] = useState('');
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
const [error, setError] = useState('');
|
|
|
|
const handleSubmit = (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (!password.trim()) {
|
|
setError('Password tidak boleh kosong');
|
|
return;
|
|
}
|
|
setError('');
|
|
onSubmit(password);
|
|
};
|
|
|
|
const handleCancel = () => {
|
|
setPassword('');
|
|
setError('');
|
|
setShowPassword(false);
|
|
onCancel();
|
|
};
|
|
|
|
if (!isOpen) return null;
|
|
|
|
return (
|
|
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
|
|
<div className="bg-white rounded-lg shadow-xl max-w-md w-full p-6">
|
|
<h2 className="text-xl font-bold text-gray-800 mb-4">Masukkan Password Admin</h2>
|
|
<p className="text-sm text-gray-600 mb-6">
|
|
Silakan masukkan password untuk mengakses Admin Sistem
|
|
</p>
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
<div className="mb-4">
|
|
<label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-2">
|
|
Password
|
|
</label>
|
|
<div className="relative">
|
|
<input
|
|
id="password"
|
|
type={showPassword ? 'text' : 'password'}
|
|
value={password}
|
|
onChange={(e) => {
|
|
setPassword(e.target.value);
|
|
setError('');
|
|
}}
|
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-500 focus:border-transparent"
|
|
placeholder="Masukkan password"
|
|
autoFocus
|
|
disabled={isLoading}
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700"
|
|
disabled={isLoading}
|
|
>
|
|
<i className={`fa-solid ${showPassword ? 'fa-eye-slash' : 'fa-eye'}`}></i>
|
|
</button>
|
|
</div>
|
|
{error && (
|
|
<p className="mt-2 text-sm text-red-600">
|
|
<i className="fa-solid fa-circle-exclamation mr-1"></i>
|
|
{error}
|
|
</p>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex gap-3">
|
|
<button
|
|
type="button"
|
|
onClick={handleCancel}
|
|
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"
|
|
disabled={isLoading}
|
|
>
|
|
Batal
|
|
</button>
|
|
<button
|
|
type="submit"
|
|
className="flex-1 px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors disabled:bg-gray-400 disabled:cursor-not-allowed"
|
|
disabled={isLoading}
|
|
>
|
|
{isLoading ? 'Memverifikasi...' : 'Masuk'}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PasswordModal;
|