'use client' import { useState } from 'react' import { Button } from '../ui/button' import { Input } from '../ui/input' import { Label } from '../ui/label' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card' import { Loader2 } from 'lucide-react' export interface ChangePasswordFormProps { onSubmit: (values: { old_password: string new_password: string }) => Promise /** Called after a successful password change (e.g. to sign out) */ onSuccess?: () => void disabled?: boolean } export function ChangePasswordForm({ onSubmit, onSuccess, disabled }: ChangePasswordFormProps) { const [oldPassword, setOldPassword] = useState('') const [newPassword, setNewPassword] = useState('') const [saving, setSaving] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(false) const isValid = oldPassword.length > 0 && newPassword.length >= 8 const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) setSuccess(false) setSaving(true) try { await onSubmit({ old_password: oldPassword, new_password: newPassword, }) setSuccess(true) setOldPassword('') setNewPassword('') onSuccess?.() } catch (err) { setError(err instanceof Error ? err.message : 'Failed to change password') } finally { setSaving(false) } } return ( Change password Update your password. You will need to sign in again after changing it.
setOldPassword(e.target.value)} disabled={disabled || saving} autoComplete="current-password" />
setNewPassword(e.target.value)} disabled={disabled || saving} autoComplete="new-password" /> {newPassword.length > 0 && newPassword.length < 8 && (

Must be at least 8 characters.

)}
{error && (

{error}

)} {success && (

Password changed successfully.

)}
) }