import { useMutation } from '@tanstack/react-query'; import { getAuthToken } from 'lib/client'; import { useApi } from 'next-basics'; import { useRef } from 'react'; import { SubmitButton, Form, FormButtons, FormInput, PasswordField } from 'react-basics'; import styles from './UserForm.module.css'; import useUser from 'hooks/useUser'; export default function UserPasswordForm({ onSave }) { const { user: { id }, } = useUser(); const { post } = useApi(getAuthToken()); const { mutate, error } = useMutation(data => post(`/users/${id}/password`, data)); const ref = useRef(null); const handleSubmit = async data => { mutate(data, { onSuccess: async () => { onSave(); }, }); }; const samePassword = value => { if (value !== ref?.current?.getValues('new_password')) { return "Passwords don't match"; } return true; }; return ( <>
Save
); }