import { useRef, FormEventHandler } from "react"; import { useForm } from "@inertiajs/react"; import { Transition } from "@headlessui/react"; import { Label } from "@/Components/ui/label"; import { Input } from "@/Components/ui/input"; import { InputError } from "@/Components/ui/InputError"; import { Button } from "@/Components/ui/button"; export default function UpdatePasswordForm({ className = "", }: { className?: string; }) { 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("password.update"), { 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 (
setData("current_password", e.target.value) } type="password" className="mt-1 block w-full" autoComplete="current-password" />
setData("password", e.target.value)} type="password" className="mt-1 block w-full" autoComplete="new-password" />
setData("password_confirmation", e.target.value) } type="password" className="mt-1 block w-full" autoComplete="new-password" />

Saved.

); }