@@ -26,6 +26,8 @@ function VoteBlock() {
2626 const inputRef = useRef < HTMLInputElement > ( null ) ;
2727
2828 const onRegister = ( ) => {
29+ if ( ! options . length ) throw new Error ( '투표 항목은 최소 1개에요 ^^' ) ;
30+
2931 if ( ! isUnRegisterd ) return ;
3032
3133 setIsUnRegisterd ( false ) ;
@@ -53,6 +55,12 @@ function VoteBlock() {
5355 setOptions ( filteredOptions ) ;
5456 } ;
5557
58+ const onClose = ( ) => {
59+ alert ( '투표 종료..!' ) ;
60+ /**투표 결과 보여줘야함 */
61+ setIsUnRegisterd ( true ) ;
62+ } ;
63+
5664 return (
5765 < div className = { style [ 'vote-container' ] } >
5866 < h3 className = { style . title } > 투표</ h3 >
@@ -73,25 +81,25 @@ function VoteBlock() {
7381 ) ) }
7482 </ ul >
7583 { isUnRegisterd && (
76- < >
77- < div className = { style [ 'option-item' ] } >
78- < div className = { style [ 'box-fill' ] } > </ div >
79- < input
80- ref = { inputRef }
81- className = { style [ 'option-input' ] }
82- placeholder = "항목을 입력해주세요"
83- > </ input >
84- </ div >
85- < div className = { style [ 'vote-buttons' ] } >
86- < Button className = { style . button } onClick = { onAdd } text = "항목 추가" />
87- < Button
88- className = { style . button }
89- onClick = { onRegister }
90- text = "투표 등록"
91- />
92- </ div >
93- </ >
84+ < div className = { style [ 'option-item' ] } >
85+ < div className = { style [ 'box-fill' ] } > </ div >
86+ < input
87+ ref = { inputRef }
88+ className = { style [ 'option-input' ] }
89+ placeholder = "항목을 입력해주세요"
90+ > </ input >
91+ </ div >
9492 ) }
93+ < div className = { style [ 'vote-buttons' ] } >
94+ { isUnRegisterd ? (
95+ < >
96+ < Button onClick = { onAdd } text = "항목 추가" />
97+ < Button onClick = { onRegister } text = "투표 등록" />
98+ </ >
99+ ) : (
100+ < Button onClick = { onClose } text = "투표 종료" />
101+ ) }
102+ </ div >
95103 </ div >
96104 ) ;
97105}
0 commit comments