1
1
import { useEventState } from '@/stores/myEventsStore.ts' ;
2
2
import DialogButton from '@/components/common/DialogButton' ;
3
- import InputForm from '../common/InputForm' ;
4
- import { useState } from 'react' ;
3
+ import { InputRef } from '../common/InputForm.tsx ' ;
4
+ import { useState , useRef } from 'react' ;
5
5
6
6
const CreateEventButton = ( ) => {
7
7
const { addEvents } = useEventState ( ) ;
8
8
const [ eventTitle , setTitle ] = useState ( '' ) ;
9
9
const [ startDate , setStartDate ] = useState ( '' ) ;
10
10
const [ endDate , setEndDate ] = useState ( '' ) ;
11
+ const titleRef = useRef ( null ) ;
12
+ const startRef = useRef ( null ) ;
13
+ const endRef = useRef ( null ) ;
11
14
12
15
const onTitleChanged = ( event : React . ChangeEvent < HTMLInputElement > ) => {
13
16
setTitle ( event . target . value ) ;
@@ -22,17 +25,24 @@ const CreateEventButton = () => {
22
25
} ;
23
26
24
27
const onCreateClicked = ( ) => {
25
- console . log ( 'clicked! ' , eventTitle , startDate , endDate ) ;
26
- if ( eventTitle !== '' && startDate !== '' && endDate !== '' )
27
- addEvents ( { title : eventTitle , start : startDate , end : endDate } ) ;
28
+ if ( eventTitle !== '' && startDate !== '' ) {
29
+ addEvents ( { title : eventTitle , start : startDate , end : endDate === '' ? startDate : endDate } ) ;
30
+ }
31
+ setTitle ( '' ) ;
32
+ setStartDate ( '' ) ;
33
+ setEndDate ( '' ) ;
34
+ titleRef . current . value = null ;
35
+ startRef . current . value = null ;
36
+ endRef . current . value = null ;
28
37
} ;
29
38
30
39
const eventForm = (
31
40
< div >
32
- < InputForm title = "์ผ์ ์ ๋ชฉ" placeholder = "์ ์ผ์ ์ ๋ชฉ" onChange = { onTitleChanged } />
33
- < InputForm title = "์์ ๋ ์ง" placeholder = "YYYY-MM-DD" onChange = { onStartDateChanged } />
34
- < InputForm title = "๋ ๋ ์ง" placeholder = "YYYY-MM-DD" onChange = { onEndDateChanged } />
35
- < hr className = "m-4" />
41
+ < hr className = "mt-1" />
42
+ < InputRef title = "์ผ์ ์ ๋ชฉ" placeholder = "์ ์ผ์ ์ ๋ชฉ" onChange = { onTitleChanged } ref = { titleRef } />
43
+ < InputRef title = "์์ ๋ ์ง" placeholder = "YYYY-MM-DD" onChange = { onStartDateChanged } ref = { startRef } />
44
+ < InputRef title = "๋ ๋ ์ง" placeholder = "YYYY-MM-DD" onChange = { onEndDateChanged } ref = { endRef } />
45
+ < hr className = "mb-2 mt-2" />
36
46
< button className = "btn w-full bg-primary text-base-100" onClick = { onCreateClicked } >
37
47
์ถ๊ฐํ๊ธฐ
38
48
</ button >
@@ -44,7 +54,7 @@ const CreateEventButton = () => {
44
54
classname = "btn bg-primary text-base-100 w-full"
45
55
name = { '์ ์ผ์ ์ถ๊ฐํ๊ธฐ' }
46
56
title = { '์ผ์ ์ถ๊ฐ' }
47
- desc = { ' ' }
57
+ desc = { '' }
48
58
children = { eventForm }
49
59
/>
50
60
</ div >
0 commit comments