refactor: use PasswordInput component in site settings
This commit is contained in:
@@ -7,6 +7,7 @@ import { getRealtime } from '@/lib/api/stats'
|
|||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import LoadingOverlay from '@/components/LoadingOverlay'
|
import LoadingOverlay from '@/components/LoadingOverlay'
|
||||||
import VerificationModal from '@/components/sites/VerificationModal'
|
import VerificationModal from '@/components/sites/VerificationModal'
|
||||||
|
import PasswordInput from '@/components/PasswordInput'
|
||||||
import { APP_URL, API_URL } from '@/lib/api/client'
|
import { APP_URL, API_URL } from '@/lib/api/client'
|
||||||
import { motion, AnimatePresence } from 'framer-motion'
|
import { motion, AnimatePresence } from 'framer-motion'
|
||||||
import {
|
import {
|
||||||
@@ -446,13 +447,11 @@ export default function SiteSettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="password" className="block text-sm font-medium mb-2 text-neutral-900 dark:text-white">
|
<PasswordInput
|
||||||
Password Protection (Optional)
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
id="password"
|
id="password"
|
||||||
|
label="Password Protection (Optional)"
|
||||||
value={isPasswordMasked ? '********' : formData.password}
|
value={isPasswordMasked ? '********' : formData.password}
|
||||||
|
onChange={(value) => setFormData({ ...formData, password: value })}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
if (isPasswordMasked) {
|
if (isPasswordMasked) {
|
||||||
setIsPasswordMasked(false)
|
setIsPasswordMasked(false)
|
||||||
@@ -464,10 +463,7 @@ export default function SiteSettingsPage() {
|
|||||||
setIsPasswordMasked(true)
|
setIsPasswordMasked(true)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onChange={(e) => setFormData({ ...formData, password: e.target.value })}
|
|
||||||
placeholder={site.has_password ? "Change password" : "Leave empty to keep existing password (if any)"}
|
placeholder={site.has_password ? "Change password" : "Leave empty to keep existing password (if any)"}
|
||||||
className="w-full px-4 py-2 border border-neutral-200 dark:border-neutral-800 rounded-xl bg-white dark:bg-neutral-900 text-neutral-900 dark:text-white focus:bg-white dark:focus:bg-neutral-900
|
|
||||||
focus:border-brand-orange focus:ring-4 focus:ring-brand-orange/10 outline-none transition-all duration-200"
|
|
||||||
/>
|
/>
|
||||||
<p className="mt-2 text-xs text-neutral-500">
|
<p className="mt-2 text-xs text-neutral-500">
|
||||||
Set a password to restrict access to the public dashboard.
|
Set a password to restrict access to the public dashboard.
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ interface PasswordInputProps {
|
|||||||
id?: string
|
id?: string
|
||||||
autoComplete?: string
|
autoComplete?: string
|
||||||
minLength?: number
|
minLength?: number
|
||||||
|
onFocus?: () => void
|
||||||
|
onBlur?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function PasswordInput({
|
export default function PasswordInput({
|
||||||
@@ -27,7 +29,9 @@ export default function PasswordInput({
|
|||||||
className = '',
|
className = '',
|
||||||
id,
|
id,
|
||||||
autoComplete,
|
autoComplete,
|
||||||
minLength
|
minLength,
|
||||||
|
onFocus,
|
||||||
|
onBlur
|
||||||
}: PasswordInputProps) {
|
}: PasswordInputProps) {
|
||||||
const [showPassword, setShowPassword] = useState(false)
|
const [showPassword, setShowPassword] = useState(false)
|
||||||
const inputId = id || 'password-input'
|
const inputId = id || 'password-input'
|
||||||
@@ -54,6 +58,8 @@ export default function PasswordInput({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
autoComplete={autoComplete}
|
autoComplete={autoComplete}
|
||||||
minLength={minLength}
|
minLength={minLength}
|
||||||
|
onFocus={onFocus}
|
||||||
|
onBlur={onBlur}
|
||||||
aria-invalid={!!error}
|
aria-invalid={!!error}
|
||||||
aria-describedby={error ? errorId : undefined}
|
aria-describedby={error ? errorId : undefined}
|
||||||
className={`w-full pl-11 pr-12 py-3 border rounded-xl bg-neutral-50/50 dark:bg-neutral-900/50 focus:bg-white dark:focus:bg-neutral-900
|
className={`w-full pl-11 pr-12 py-3 border rounded-xl bg-neutral-50/50 dark:bg-neutral-900/50 focus:bg-white dark:focus:bg-neutral-900
|
||||||
|
|||||||
Reference in New Issue
Block a user