fix(auth): prevent register modal inputs from losing focus on typing
Build and publish Docker image / build-and-publish (push) Successful in 40s
Build and publish Docker image / build-and-publish (push) Successful in 40s
This commit is contained in:
1 parent
008a3a4233
commit
ad5bf1d015
1 file changed
+100
-23
+100
-23
@@ -982,6 +982,40 @@ function ForgotPasswordModal({ onClose, colors }) {
|
||||
);
|
||||
}
|
||||
|
||||
// Top-level input field to prevent unmounting and focus loss on re-renders
|
||||
function RegisterInputField({
|
||||
label,
|
||||
name,
|
||||
type = "text",
|
||||
placeholder,
|
||||
required = false,
|
||||
value = '',
|
||||
onChange,
|
||||
disabled = false,
|
||||
colors,
|
||||
...props
|
||||
}) {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label className="block text-[10px] font-black uppercase tracking-[0.2em] opacity-40 ml-1">
|
||||
{label} {required && '*'}
|
||||
</label>
|
||||
<input
|
||||
type={type}
|
||||
name={name}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
className="w-full rounded-2xl px-5 py-3.5 text-sm font-bold focus:outline-none transition-all duration-300 border bg-black/40 focus:border-primary/50 focus:ring-4 focus:ring-primary/10"
|
||||
style={{ borderColor: colors.brightBlack, color: colors.brightWhite }}
|
||||
placeholder={placeholder}
|
||||
required={required}
|
||||
disabled={disabled}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Register Modal Component - UPDATED to match Dashboard style
|
||||
function RegisterModal({
|
||||
onClose,
|
||||
@@ -1010,6 +1044,11 @@ function RegisterModal({
|
||||
[countryOptions],
|
||||
);
|
||||
|
||||
const handleInputChange = useCallback((e) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({ ...prev, [name]: value }));
|
||||
}, []);
|
||||
|
||||
const detectUserLocation = useCallback(async () => {
|
||||
setDetectingLocation(true);
|
||||
try {
|
||||
@@ -1058,23 +1097,6 @@ function RegisterModal({
|
||||
});
|
||||
};
|
||||
|
||||
const InputField = ({ label, name, type = "text", placeholder, required = false, ...props }) => (
|
||||
<div className="space-y-2">
|
||||
<label className="block text-[10px] font-black uppercase tracking-[0.2em] opacity-40 ml-1">{label} {required && '*'}</label>
|
||||
<input
|
||||
type={type}
|
||||
value={formData[name]}
|
||||
onChange={(e) => setFormData(prev => ({ ...prev, [name]: e.target.value }))}
|
||||
className="w-full rounded-2xl px-5 py-3.5 text-sm font-bold focus:outline-none transition-all duration-300 border bg-black/40 focus:border-primary/50 focus:ring-4 focus:ring-primary/10"
|
||||
style={{ borderColor: colors.brightBlack, color: colors.brightWhite }}
|
||||
placeholder={placeholder}
|
||||
required={required}
|
||||
disabled={isLoading}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-black/80 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-in fade-in duration-300">
|
||||
<div className="rounded-[2.5rem] w-full max-w-2xl border shadow-2xl overflow-hidden bg-dash-surfaceElevated/95 backdrop-blur-2xl animate-in zoom-in-95 duration-300 max-h-[90vh] flex flex-col"
|
||||
@@ -1094,10 +1116,45 @@ function RegisterModal({
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-8">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<InputField label="Username" name="username" required placeholder="User_123" />
|
||||
<InputField label="Email" name="email" type="email" required placeholder="you@example.com" />
|
||||
<InputField label="First Name" name="firstName" placeholder="Andrzej" />
|
||||
<InputField label="Last Name" name="lastName" placeholder="Nowak" />
|
||||
<RegisterInputField
|
||||
label="Username"
|
||||
name="username"
|
||||
required
|
||||
placeholder="User_123"
|
||||
value={formData.username}
|
||||
onChange={handleInputChange}
|
||||
disabled={isLoading}
|
||||
colors={colors}
|
||||
/>
|
||||
<RegisterInputField
|
||||
label="Email"
|
||||
name="email"
|
||||
type="email"
|
||||
required
|
||||
placeholder="you@example.com"
|
||||
value={formData.email}
|
||||
onChange={handleInputChange}
|
||||
disabled={isLoading}
|
||||
colors={colors}
|
||||
/>
|
||||
<RegisterInputField
|
||||
label="First Name"
|
||||
name="firstName"
|
||||
placeholder="Andrzej"
|
||||
value={formData.firstName}
|
||||
onChange={handleInputChange}
|
||||
disabled={isLoading}
|
||||
colors={colors}
|
||||
/>
|
||||
<RegisterInputField
|
||||
label="Last Name"
|
||||
name="lastName"
|
||||
placeholder="Nowak"
|
||||
value={formData.lastName}
|
||||
onChange={handleInputChange}
|
||||
disabled={isLoading}
|
||||
colors={colors}
|
||||
/>
|
||||
|
||||
<div className="space-y-2">
|
||||
<label className="block text-[10px] font-black uppercase tracking-[0.2em] opacity-40 ml-1">Country</label>
|
||||
@@ -1135,8 +1192,28 @@ function RegisterModal({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<InputField label="Password" name="password" type="password" required placeholder="••••••••" />
|
||||
<InputField label="Confirm" name="confirmPassword" type="password" required placeholder="••••••••" />
|
||||
<RegisterInputField
|
||||
label="Password"
|
||||
name="password"
|
||||
type="password"
|
||||
required
|
||||
placeholder="••••••••"
|
||||
value={formData.password}
|
||||
onChange={handleInputChange}
|
||||
disabled={isLoading}
|
||||
colors={colors}
|
||||
/>
|
||||
<RegisterInputField
|
||||
label="Confirm"
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
required
|
||||
placeholder="••••••••"
|
||||
value={formData.confirmPassword}
|
||||
onChange={handleInputChange}
|
||||
disabled={isLoading}
|
||||
colors={colors}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
|
||||
Reference in new issue
Block a user