Commit 475165d 1 parent c39be6e commit 475165d Copy full SHA for 475165d
File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,7 @@ export default function Home() {
157
157
newEvent : Event ,
158
158
notification : { date : Date | null ; type : "call" | "push" } ,
159
159
) => {
160
+ console . log ( "addEvent" , newEvent ) ;
160
161
setEvents ( [ ...events , newEvent ] ) ;
161
162
setIsEventModalOpen ( false ) ;
162
163
setRemovedStickyNote ( null ) ;
Original file line number Diff line number Diff line change 1
1
"use client" ;
2
2
3
+ import { z } from "zod" ;
3
4
import { DateTimeInput } from "@/components/date-time-input" ;
4
5
import { Button } from "@/components/ui/button" ;
5
6
import { Checkbox } from "@/components/ui/checkbox" ;
@@ -64,6 +65,20 @@ export function EventCreator({
64
65
const [ notificationType , setNotificationType ] = useState < "call" | "push" > (
65
66
"call" ,
66
67
) ;
68
+ // Zod スキーマの定義
69
+ const eventSchema = z . object ( {
70
+ title : z . string ( ) . nonempty ( "タイトルは空白にできません。" ) ,
71
+ start : z . date ( ) ,
72
+ end : z . date ( ) ,
73
+ description : z . string ( ) . optional ( ) ,
74
+ category : z . string ( ) . optional ( ) ,
75
+ priority : z . string ( ) . optional ( ) ,
76
+ location : z . string ( ) . optional ( ) ,
77
+ invitees : z . array ( z . string ( ) ) . optional ( ) ,
78
+ isTask : z . boolean ( ) ,
79
+ isLocked : z . boolean ( ) ,
80
+ } ) ;
81
+
67
82
68
83
const handleSave = ( ) => {
69
84
if ( targetDate ) {
@@ -80,6 +95,12 @@ export function EventCreator({
80
95
isTask,
81
96
isLocked,
82
97
} ;
98
+ // バリデーションの実行
99
+ const result = eventSchema . safeParse ( newEvent ) ;
100
+ if ( ! result . success ) {
101
+ alert ( result . error . errors . map ( ( err ) => err . message ) . join ( "\n" ) ) ;
102
+ return ;
103
+ }
83
104
onSave ( newEvent , { date : notificationDate , type : notificationType } ) ;
84
105
}
85
106
} ;
You can’t perform that action at this time.
0 commit comments