UserEditForm.tsx 983 B

12345678910111213141516171819202122232425262728293031
  1. import { useFormHandler, TextInput } from "../../form"
  2. import { UserProps } from "../props"
  3. import { userValidation } from "../validation"
  4. const initialData = {
  5. name: '',
  6. email: '',
  7. password: '',
  8. passwordAgain: ''
  9. }
  10. const UserEditForm = ({ user }: UserProps) => {
  11. const [updateUser, userEdit] = useMutation(USER_EDIT)
  12. const { inputProps, values } = useFormHandler({ ...initialData, ...user })
  13. return (
  14. <form onSubmit={async (event: React.SyntheticEvent) => {
  15. event.preventDefault()
  16. await updateUser({ variables: values, refetchQueries: [{ query: CURRENT_USER }] })
  17. }}>
  18. <TextInput label='Name' {...inputProps('name')} />
  19. <TextInput label='Email' {...inputProps('email')} />
  20. <TextInput label='Password' {...inputProps('password')} />
  21. <TextInput label='Repeat password' {...inputProps('passwordAgain')} />
  22. <button type='submit' disabled={userEdit.loading}>Update</button>
  23. </form>
  24. )
  25. }
  26. export default UserEditForm