From 71abc48fd4525b9194df848a6915ab4dfc11c354 Mon Sep 17 00:00:00 2001
From: Masaya Tojo <masaya@tojo.tokyo>
Date: Sun, 1 Sep 2024 22:36:21 +0900
Subject: 確認画面まで作成する
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/SignUpForm2.tsx | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

(limited to 'src/SignUpForm2.tsx')

diff --git a/src/SignUpForm2.tsx b/src/SignUpForm2.tsx
index 1824fd6..f355225 100644
--- a/src/SignUpForm2.tsx
+++ b/src/SignUpForm2.tsx
@@ -1,9 +1,49 @@
 import './SignUp.css'
+import { useForm } from 'react-hook-form'
+import { zodResolver } from "@hookform/resolvers/zod"
+import { useLocation, Navigate, useNavigate } from 'react-router-dom';
+import { Form1, Form2, form2Schema } from './signUpSchema'
 
 export const SignUpForm2 = () => {
+  const { register, handleSubmit, formState: { errors } } = useForm<Form2>({
+    resolver: zodResolver(form2Schema),
+  });
+  const location = useLocation();
+  const form1 = location.state as Form1 | null;
+  const navigate = useNavigate();
+
+  // form1 のデータがない場合は form1 にリダイレクトする
+  if (form1 === null) {
+    return <Navigate replace to="/sign-up/form1" />
+  }
+
+  const onsubmit = (form2: Form2) => {
+    const state = {
+      ...form1,
+      ...form2,
+    }
+    navigate('/sign-up/confirm', { state })
+  }
+  const onerror = (err: any) => console.log(err);
+
   return (
     <>
       <h1>会員登録 フェーズ 2</h1>
+      <form className="SignUpForm" onSubmit={handleSubmit(onsubmit, onerror)}>
+        <div>
+          <label htmlFor="email">メールアドレス: </label>
+          <input id="email" type="email" {...register('email')}></input>
+          <div className="error">{errors.email?.message}</div>
+        </div>
+        <div>
+          <label htmlFor="password">パスワード: </label>
+          <input id="password" type="password" {...register('password')}></input>
+          <div className="error">{errors.password?.message}</div>
+        </div>
+        <div>
+          <button type="submit">確認画面へ</button>
+        </div>
+      </form>
     </>
   );
 }
-- 
cgit v1.2.3

