UserEditForm.tsx 1012 B

123456789101112131415161718192021222324252627282930313233
  1. import { useQuery, useMutation } from "react-apollo"
  2. import { useFormHandler, TextInput } from "../form/forms"
  3. import { CURRENT_USER, USER_EDIT } from "./graphql"
  4. import { SyntheticEvent } from "react"
  5. const initialData = {
  6. name: '',
  7. email: '',
  8. password: '',
  9. passwordAgain: ''
  10. }
  11. const UserEditForm = () => {
  12. const currentUser = useQuery(CURRENT_USER)
  13. const [updateUser, userEdit] = useMutation(USER_EDIT)
  14. const { inputProps } = useFormHandler(currentUser.data ? { ...initialData, ...currentUser.data.me } : initialData)
  15. return (
  16. <form onSubmit={(event: SyntheticEvent) => {
  17. event.preventDefault()
  18. }}>
  19. <TextInput label='Name' {...inputProps('name')} />
  20. <TextInput label='Email' {...inputProps('email')} />
  21. <TextInput label='Password' {...inputProps('password')} />
  22. <TextInput label='Repeat password' {...inputProps('passwordAgain')} />
  23. <button type='submit' disabled={userEdit.loading}>Update</button>
  24. </form>
  25. )
  26. }
  27. export default UserEditForm