import InputError from '@/components/ui/input-error'; import { useForm } from '@inertiajs/react'; import { FormEventHandler, useRef } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { Form, FormField, FormFields } from '@/components/ui/form'; import { LoaderCircleIcon } from 'lucide-react'; import FormSuccessful from '@/components/form-successful'; export default function UpdatePassword() { const passwordInput = useRef(null); const currentPasswordInput = useRef(null); const { data, setData, errors, put, reset, processing, recentlySuccessful } = useForm({ current_password: '', password: '', password_confirmation: '', }); const updatePassword: FormEventHandler = (e) => { e.preventDefault(); put(route('profile.password'), { preserveScroll: true, onSuccess: () => reset(), onError: (errors) => { if (errors.password) { reset('password', 'password_confirmation'); passwordInput.current?.focus(); } if (errors.current_password) { reset('current_password'); currentPasswordInput.current?.focus(); } }, }); }; return ( Update password Ensure your account is using a long, random password to stay secure.
setData('current_password', e.target.value)} type="password" className="mt-1 block w-full" autoComplete="current-password" placeholder="Current password" /> setData('password', e.target.value)} type="password" className="mt-1 block w-full" autoComplete="new-password" placeholder="New password" /> setData('password_confirmation', e.target.value)} type="password" className="mt-1 block w-full" autoComplete="new-password" placeholder="Confirm password" />
); }