@@ -46,29 +46,32 @@ const CreateEventDialog = ({ id, title, start_date, end_date }: eventProps) => {
46
46
} ;
47
47
48
48
const onCreateClicked = ( ) => {
49
- if ( eventTitle !== '' && startDate !== '' ) {
50
- const newEvent : Events = {
51
- title : eventTitle ,
52
- start : startDate ,
53
- end : endDate === '' ? startDate : endDate ,
54
- } ;
55
- if ( id ) {
56
- updatePersonalSchedule ( id , newEvent )
57
- . then ( ( ) => {
58
- location . href = '/' ;
59
- } )
60
- . catch ( ( err ) => {
61
- console . log ( err ) ;
62
- } ) ;
63
- } else {
64
- addPersonalSchedule ( newEvent )
65
- . then ( ( ) => {
66
- location . href = '/' ;
67
- } )
68
- . catch ( ( err ) => {
69
- console . log ( err ) ;
70
- } ) ;
71
- }
49
+ if ( eventTitle === '' || startDate === '' || startDate > endDate ) {
50
+ console . log ( 'please check input value:' , eventTitle , startDate , endDate ) ;
51
+ return ;
52
+ }
53
+
54
+ const newEvent : Events = {
55
+ title : eventTitle ,
56
+ start : startDate ,
57
+ end : endDate === '' ? startDate : endDate ,
58
+ } ;
59
+ if ( id ) {
60
+ updatePersonalSchedule ( id , newEvent )
61
+ . then ( ( ) => {
62
+ location . href = '/' ;
63
+ } )
64
+ . catch ( ( err ) => {
65
+ console . log ( err ) ;
66
+ } ) ;
67
+ } else {
68
+ addPersonalSchedule ( newEvent )
69
+ . then ( ( ) => {
70
+ location . href = '/' ;
71
+ } )
72
+ . catch ( ( err ) => {
73
+ console . log ( err ) ;
74
+ } ) ;
72
75
}
73
76
74
77
setTitle ( '' ) ;
@@ -88,9 +91,32 @@ const CreateEventDialog = ({ id, title, start_date, end_date }: eventProps) => {
88
91
return (
89
92
< div >
90
93
< hr className = "mt-1" />
91
- < InputRef title = "일정 제목" placeholder = "새 일정 제목" onChange = { onTitleChanged } ref = { titleRef } />
92
- < InputRef type = "date" title = "시작 날짜" placeholder = "YYYY-MM-DD" onChange = { onStartDateChanged } ref = { startRef } />
93
- < InputRef type = "date" title = "끝 날짜" placeholder = "YYYY-MM-DD" onChange = { onEndDateChanged } ref = { endRef } />
94
+ < InputRef
95
+ title = "일정 제목"
96
+ placeholder = "새 일정 제목"
97
+ onChange = { onTitleChanged }
98
+ ref = { titleRef }
99
+ error = { eventTitle === '' }
100
+ errorText = "일정 제목을 입력해주세요."
101
+ />
102
+ < InputRef
103
+ type = "date"
104
+ title = "시작 날짜"
105
+ placeholder = "YYYY-MM-DD"
106
+ onChange = { onStartDateChanged }
107
+ ref = { startRef }
108
+ error = { startDate === '' }
109
+ errorText = "시작 날짜를 입력해주세요."
110
+ />
111
+ < InputRef
112
+ type = "date"
113
+ title = "끝 날짜"
114
+ placeholder = "YYYY-MM-DD"
115
+ onChange = { onEndDateChanged }
116
+ ref = { endRef }
117
+ error = { startDate > endDate }
118
+ errorText = "끝 날짜는 시작날짜보다 늦게 해주세요."
119
+ />
94
120
< hr className = "mb-2 mt-2" />
95
121
< button className = "btn w-full bg-primary text-base-100" onClick = { onCreateClicked } >
96
122
{ id ? '수정하기' : '추가하기' }
0 commit comments