1- import React from "react" ;
21import { useForm , Controller } from "react-hook-form" ;
32import { zodResolver } from "@hookform/resolvers/zod" ;
43import { z } from "zod" ;
@@ -14,11 +13,12 @@ import {
1413 Radio ,
1514 RadioGroup ,
1615} from "@mui/material" ;
17- import type { Survey } from "../types/survey " ;
16+ import type { SubmitHandler } from "react-hook-form " ;
1817
19- // Zodスキーマ
20-
21- const communityAffiliationOptions = [ "VS Code Meetup" , "GitHub dockyard" ] ;
18+ const communityAffiliationOptions = [
19+ "VS Code Meetup" ,
20+ "GitHub dockyard" ,
21+ ] as const ;
2222const jobRoleOptions = [
2323 "フロントエンドエンジニア" ,
2424 "バックエンドエンジニア" ,
@@ -27,13 +27,10 @@ const jobRoleOptions = [
2727 "データエンジニア" ,
2828 "モバイルエンジニア" ,
2929 "その他" ,
30- ] ;
30+ ] as const ;
3131
3232const schema = z . object ( {
33- communityAffiliation : z
34- . array ( z . enum ( [ "VS Code Meetup" , "GitHub dockyard" ] ) )
35- . optional ( )
36- . default ( [ ] ) ,
33+ communityAffiliation : z . array ( z . enum ( [ "VS Code Meetup" , "GitHub dockyard" ] ) ) ,
3734 jobRole : z
3835 . array (
3936 z . enum ( [
@@ -60,10 +57,12 @@ const schema = z.object({
6057
6158type FormValues = z . infer < typeof schema > ;
6259
63- export const SurveyForm : React . FC < {
64- onSubmit : ( data : Survey ) => void ;
60+ type SurveyFormProps = {
61+ onSubmit : SubmitHandler < FormValues > ;
6562 loading ?: boolean ;
66- } > = ( { onSubmit, loading } ) => {
63+ } ;
64+
65+ export function SurveyForm ( { onSubmit, loading } : SurveyFormProps ) {
6766 const {
6867 control,
6968 handleSubmit,
@@ -101,7 +100,7 @@ export const SurveyForm: React.FC<{
101100 field . onChange ( [ ...( field . value || [ ] ) , c ] ) ;
102101 else
103102 field . onChange (
104- ( field . value || [ ] ) . filter ( ( v : string ) => v !== c )
103+ ( field . value || [ ] ) . filter ( ( v ) => v !== c )
105104 ) ;
106105 } }
107106 />
@@ -134,9 +133,7 @@ export const SurveyForm: React.FC<{
134133 if ( e . target . checked )
135134 field . onChange ( [ ...field . value , role ] ) ;
136135 else
137- field . onChange (
138- field . value . filter ( ( v : string ) => v !== role )
139- ) ;
136+ field . onChange ( field . value . filter ( ( v ) => v !== role ) ) ;
140137 } }
141138 />
142139 }
@@ -224,4 +221,4 @@ export const SurveyForm: React.FC<{
224221 </ Button >
225222 </ Box >
226223 ) ;
227- } ;
224+ }
0 commit comments