1
- import { useState } from 'react' ;
2
- import { FormProvider , useForm } from 'react-hook-form' ;
3
- import { useNavigate } from 'react-router-dom' ;
1
+ import { FormProvider } from 'react-hook-form' ;
2
+
3
+ import {
4
+ CREATE_GAME_STRINGS ,
5
+ MAX_MEMBER_COUNT_LIST ,
6
+ PLAY_TIME_LIST ,
7
+ START_TIME_HOUR_LIST ,
8
+ START_TIME_MINUTES_LIST ,
9
+ } from '@pages/CreateGamePage/consts/createGameOptions' ;
4
10
5
11
import { CalendarComponent } from '@components/Calendar' ;
6
12
import { ConditionalFormInput } from '@components/ConditionalFormInput' ;
@@ -11,24 +17,10 @@ import { Button } from '@components/shared/Button';
11
17
import { Text } from '@components/shared/Text' ;
12
18
import { VirtualScroll } from '@components/shared/VirtualScroll' ;
13
19
14
- import { useGameMutation } from '@hooks/mutations/useGameMutation' ;
15
20
import { useHeaderTitle } from '@hooks/useHeaderTitle' ;
16
21
17
22
import { theme } from '@styles/theme' ;
18
23
19
- import { useLoginInfoStore } from '@stores/loginInfo.store' ;
20
-
21
- import { PostGameRequest } from '@type/api/games' ;
22
- import { Position } from '@type/models/Position' ;
23
-
24
- import {
25
- MAX_MEMBER_COUNT_LIST ,
26
- PLAY_TIME_LIST ,
27
- START_TIME_HOUR_LIST ,
28
- START_TIME_MINUTES_LIST ,
29
- } from '@consts/createGameOptions' ;
30
- import { PATH_NAME } from '@consts/pathName' ;
31
-
32
24
import {
33
25
PageLayout ,
34
26
PageWrapper ,
@@ -39,103 +31,61 @@ import {
39
31
StyledTimeSelector ,
40
32
StyledTitle ,
41
33
} from './CreateGamePage.styles' ;
34
+ import { useCreateGamePage } from './useCreateGamePage' ;
42
35
43
36
export const CreateGamePage = ( ) => {
44
- const navigate = useNavigate ( ) ;
45
-
46
- const loginInfo = useLoginInfoStore ( ( state ) => state . loginInfo ) ;
47
- if ( ! loginInfo ?. id ) {
48
- throw new Error ( '로그인이 필요한 서비스입니다.' ) ;
49
- }
50
-
51
- const { mutate } = useGameMutation ( ) ;
52
- const methods = useForm ( ) ;
37
+ const {
38
+ state,
39
+ methods,
40
+ onSubmit,
41
+ handleAddressSelect,
42
+ handleCost,
43
+ toggleGuestCountModal,
44
+ toggleMatchDateModal,
45
+ toggleStartTimeModal,
46
+ togglePlayTimeModal,
47
+ setMaxMemberCount,
48
+ setPlayDate,
49
+ setPlayStartTimeHours,
50
+ setPlayStartTimeMinutes,
51
+ setPlayTimeMinutes,
52
+ setPositions,
53
+ setDetailAddress,
54
+ setContent,
55
+ } = useCreateGamePage ( ) ;
53
56
54
57
const { entryRef, showHeaderTitle } = useHeaderTitle < HTMLDivElement > ( ) ;
55
58
56
- const [ maxMemberCount , setMaxMemberCount ] = useState < string > ( '' ) ;
57
- const [ playDate , setPlayDate ] = useState < string > ( '' ) ;
58
- const [ playStartTimeHours , setStartTimeHours ] = useState < string > ( '' ) ;
59
- const [ playStartTimeMinutes , setStartTimeMinutes ] = useState < string > ( '' ) ;
60
- const [ playTimeMinutes , setPlayTimeMinutes ] = useState < string > ( '' ) ;
61
- const [ positions , setPositions ] = useState < Position [ ] > ( [ ] ) ;
62
- const [ mainAddress , setMainAddress ] = useState < string > ( '' ) ;
63
- const [ detailAddress , setDetailAddress ] = useState < string > ( '' ) ;
64
- const [ cost , setCost ] = useState < string > ( '0' ) ;
65
- const [ content , setContent ] = useState < string > ( '' ) ;
66
-
67
- const [ isGuestCountModalOpen , setIsGuestCountModalOpen ] = useState ( false ) ;
68
- const [ isMatchDateModalOpen , setIsMatchDateModalOpen ] = useState ( false ) ;
69
- const [ isStartTimeModalOpen , setIsStartTimeModalOpen ] = useState ( false ) ;
70
- const [ isPlayTimeModalOpen , setIsPlayTimeModalOpen ] = useState ( false ) ;
71
-
72
- const onSubmit = ( ) => {
73
- const gameData : PostGameRequest = {
74
- maxMemberCount : parseInt ( maxMemberCount ) ,
75
- playDate,
76
- playStartTime : `${ playStartTimeHours } :${ playStartTimeMinutes } ` ,
77
- playTimeMinutes : parseInt ( playTimeMinutes ) ,
78
- positions,
79
- mainAddress,
80
- detailAddress,
81
- cost : parseInt ( cost ) ,
82
- content,
83
- } ;
84
-
85
- mutate ( gameData , {
86
- onSuccess : ( { gameId } ) => {
87
- navigate ( PATH_NAME . GET_GAMES_PATH ( String ( gameId ) ) ) ;
88
- } ,
89
- } ) ;
90
- } ;
91
-
92
- const handleAddressSelect = ( ) => {
93
- new daum . Postcode ( {
94
- oncomplete : ( { address } : { address : string } ) => {
95
- setMainAddress ( address ) ;
96
- } ,
97
- } ) . open ( ) ;
98
- } ;
99
-
100
- const handleCost = ( item : string ) => {
101
- if ( parseInt ( item ) < 0 ) {
102
- setCost ( '0' ) ;
103
- } else if ( parseInt ( item ) > 100000 ) {
104
- setCost ( '100000' ) ;
105
- } else setCost ( item ) ;
106
- } ;
107
-
108
- const toggleGuestCountModal = ( ) => {
109
- setIsGuestCountModalOpen ( ( prev ) => ! prev ) ;
110
- } ;
111
-
112
- const toggleMatchDateModal = ( ) => {
113
- setIsMatchDateModalOpen ( ( prev ) => ! prev ) ;
114
- } ;
115
-
116
- const toggleStartTimeModal = ( ) => {
117
- setIsStartTimeModalOpen ( ( prev ) => ! prev ) ;
118
- } ;
119
-
120
- const togglePlayTimeModal = ( ) => {
121
- setIsPlayTimeModalOpen ( ( prev ) => ! prev ) ;
122
- } ;
59
+ const {
60
+ maxMemberCount,
61
+ playDate,
62
+ playStartTimeHours,
63
+ playStartTimeMinutes,
64
+ playTimeMinutes,
65
+ mainAddress,
66
+ detailAddress,
67
+ cost,
68
+ isGuestCountModalOpen,
69
+ isMatchDateModalOpen,
70
+ isStartTimeModalOpen,
71
+ isPlayTimeModalOpen,
72
+ } = state ;
123
73
124
74
return (
125
75
< PageLayout >
126
76
< PageWrapper >
127
- < Header title = { showHeaderTitle ? '게스트 모집하기' : '' } />
77
+ < Header title = { showHeaderTitle ? CREATE_GAME_STRINGS . TITLE : '' } />
128
78
< FormProvider { ...methods } >
129
79
< StyledCreateForm onSubmit = { methods . handleSubmit ( onSubmit ) } >
130
80
< StyledTitle >
131
81
< div ref = { entryRef } >
132
82
< Text size = { 20 } weight = { 700 } >
133
- 게스트 모집하기
83
+ { CREATE_GAME_STRINGS . TITLE }
134
84
</ Text >
135
85
</ div >
136
86
</ StyledTitle >
137
87
< ConditionalFormInput
138
- title = "게스트 인원을 선택해 주세요!"
88
+ title = { CREATE_GAME_STRINGS . GUEST_COUNT }
139
89
readOnly = { true }
140
90
isContainModal = { true }
141
91
inputLabel = "guest-count"
@@ -151,7 +101,7 @@ export const CreateGamePage = () => {
151
101
/>
152
102
</ ConditionalFormInput >
153
103
< ConditionalFormInput
154
- title = "경기 날짜를 선택해 주세요!"
104
+ title = { CREATE_GAME_STRINGS . MATCH_DATE }
155
105
readOnly = { true }
156
106
isContainModal = { true }
157
107
inputLabel = "match-date"
@@ -163,7 +113,7 @@ export const CreateGamePage = () => {
163
113
< CalendarComponent setDate = { setPlayDate } />
164
114
</ ConditionalFormInput >
165
115
< ConditionalFormInput
166
- title = "경기 시작 시간을 선택해 주세요!"
116
+ title = { CREATE_GAME_STRINGS . START_TIME }
167
117
readOnly = { true }
168
118
isContainModal = { true }
169
119
inputLabel = "start-time"
@@ -176,18 +126,18 @@ export const CreateGamePage = () => {
176
126
< VirtualScroll
177
127
width = "20%"
178
128
list = { [ ...START_TIME_HOUR_LIST ] }
179
- onItemSelected = { setStartTimeHours }
129
+ onItemSelected = { setPlayStartTimeHours }
180
130
/>
181
131
< StyledTimeColon > { ':' } </ StyledTimeColon >
182
132
< VirtualScroll
183
133
width = "20%"
184
134
list = { [ ...START_TIME_MINUTES_LIST ] }
185
- onItemSelected = { setStartTimeMinutes }
135
+ onItemSelected = { setPlayStartTimeMinutes }
186
136
/>
187
137
</ StyledTimeSelector >
188
138
</ ConditionalFormInput >
189
139
< ConditionalFormInput
190
- title = "경기 플레이타임을 선택해 주세요!"
140
+ title = { CREATE_GAME_STRINGS . PLAY_TIME }
191
141
readOnly = { true }
192
142
isContainModal = { true }
193
143
inputLabel = "play-time"
@@ -203,13 +153,13 @@ export const CreateGamePage = () => {
203
153
/>
204
154
</ ConditionalFormInput >
205
155
< Text size = { 16 } weight = { 300 } >
206
- 선호하는 포지션을 선택해 주세요!
156
+ { CREATE_GAME_STRINGS . POSITION }
207
157
</ Text >
208
158
< StyledPositionsWrapper >
209
159
< SelectPosition setPositions = { setPositions } />
210
160
</ StyledPositionsWrapper >
211
161
< ConditionalFormInput
212
- title = "주소를 입력해 주세요!"
162
+ title = { CREATE_GAME_STRINGS . MAIN_ADDRESS }
213
163
isRequired = { true }
214
164
readOnly = { true }
215
165
isContainModal = { false }
@@ -219,14 +169,14 @@ export const CreateGamePage = () => {
219
169
/>
220
170
< ConditionalFormInput
221
171
isRequired = { true }
222
- title = "상세장소를 입력해 주세요!"
172
+ title = { CREATE_GAME_STRINGS . DETAIL_ADDRESS }
223
173
isContainModal = { false }
224
174
inputLabel = "address-detail"
225
175
inputOnChange = { setDetailAddress }
226
176
value = { detailAddress }
227
177
/>
228
178
< ConditionalFormInput
229
- title = "참가비용을 입력해 주세요!"
179
+ title = { CREATE_GAME_STRINGS . COST }
230
180
isContainModal = { false }
231
181
inputLabel = "cost"
232
182
inputOnChange = { handleCost }
@@ -238,7 +188,7 @@ export const CreateGamePage = () => {
238
188
max = { '100000' }
239
189
/>
240
190
< TextArea
241
- title = "상세설명을 입력해 주세요!"
191
+ title = { CREATE_GAME_STRINGS . CONTENT }
242
192
inputLabel = "content"
243
193
inputOnChange = { setContent }
244
194
/>
@@ -251,7 +201,7 @@ export const CreateGamePage = () => {
251
201
backgroundColor = { theme . PALETTE . RED_600 }
252
202
type = "submit"
253
203
>
254
- 모집하기
204
+ { CREATE_GAME_STRINGS . CREATE }
255
205
</ Button >
256
206
< StyledEmptyContainer />
257
207
</ StyledCreateForm >
0 commit comments