import React from 'react'; import { useStore } from '@tanstack/react-form'; import { useAppForm, Form } from '@/components/form'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import { useUpdateAccountPassword } from '@/api/account/queries'; function UpdatePasswordForm() { const updatePassword = useUpdateAccountPassword(); const form = useAppForm({ defaultValues: { current: '', password: '', confirmPassword: '' }, onSubmit: async ({ value }) => { try { await updatePassword.mutateAsync({ body: { current_password: value.current, password: value.password, password_confirmation: value.confirmPassword, }, }); } catch { // Error toast is handled by the mutation. } }, }); const isSubmitting = useStore(form.store, (state) => state.isSubmitting) || updatePassword.isPending; return (
value.length >= 1 ? undefined : 'You must provide your current password.', }} > {(field) => ( )}
value.length >= 8 ? undefined : 'Your new password should be at least 8 characters in length.', }} > {(field) => ( )}
value === fieldApi.form.getFieldValue('password') ? undefined : 'Password confirmation does not match the password you entered.', }} > {(field) => ( )}
Update Password
); } export default UpdatePasswordForm;