aboutsummaryrefslogtreecommitdiff
import './SignUp.css'
import { useForm } from 'react-hook-form'
import { zodResolver } from "@hookform/resolvers/zod"
import { useNavigate } from 'react-router-dom';
import { Form1Data, form1Schema } from './signUpSchema'

export const SignUpForm1 = () => {
  const { register, handleSubmit, formState: { errors }, trigger } = useForm<Form1Data>({
    resolver: zodResolver(form1Schema),
  });
  const navigate = useNavigate();

  const onsubmit = (state: Form1Data) => {
    navigate('/sign-up/form2', { state })
  }
  const onerror = (err: any) => console.log(err);

  return (
    <>
      <h1>会員登録 フェーズ 1</h1>
      <form className="SignUpForm" onSubmit={handleSubmit(onsubmit, onerror)}>
        <div>
          <label htmlFor="name">名前: </label>
          <input id="name" type="text" {...register('name')}></input>
          <div className="error">{errors.name?.message}</div>
        </div>
        <div>
          <label htmlFor="kana">名前カナ: </label>
          <input id="kana" type="text" {...register('kana')}></input>
          <div className="error">{errors.kana?.message}</div>
        </div>
        <div>
          <label>電話番号</label>
          <input id="tel1" type="text" {...register('tel1', { onChange: () => trigger('tel3') })}></input>-
          <input id="tel2" type="text" {...register('tel2', { onChange: () => trigger('tel3') })}></input>-
          <input id="tel3" type="text" {...register('tel3')}></input>
          <div className="error">{errors.tel3?.message}</div>
        </div>
        <div>
          <button type="submit">次へ</button>
        </div>
      </form>
    </>
  );
}