1
1
'use client' ;
2
2
3
- import type { EventCreateState } from '@/entities/product/model' ;
3
+ import type {
4
+ CreateEventPayload ,
5
+ EventCreateState ,
6
+ } from '@/entities/product/model' ;
4
7
import {
5
8
createEventDefaultValues ,
6
9
createEventSchema ,
7
10
} from '@/entities/product/model' ;
11
+ import { useCreateProductMutation } from '@/features/product/create/api/useCreateQuery' ;
12
+ import type { Payload } from '@/features/product/create/config/type' ;
8
13
import { GenericForm , Header , ProgressBar } from '@/shared/ui' ;
9
14
import {
10
15
DateStep ,
@@ -41,13 +46,31 @@ const EventCreate = () => {
41
46
context : { } ,
42
47
} ,
43
48
} ) ;
44
-
45
49
const EventTotalStepIndex = 5 ;
46
50
47
- // TODO
48
- // 생성 api 연동
49
- const onSubmit = ( data : EventCreateState ) => {
50
- console . log ( 'go : ' , data ) ;
51
+ const { mutateAsync : createProduct , data} = useCreateProductMutation ( ) ;
52
+
53
+ const onSubmit = async ( data : CreateEventPayload ) => {
54
+ const formatRaffleData : Payload = {
55
+ type : 'event' ,
56
+ title : data . title ,
57
+ categoryId : Number ( data . categoryId ) ,
58
+ tagIds : data . tagIds ,
59
+ price : Number ( data . price ) ,
60
+ startDate : String ( data . startDate ) ,
61
+ endDate : String ( data . endDate ) ,
62
+ announceAt : String ( data . announceAt ) ,
63
+ winnerCount : Number ( data . winnerCount ) ,
64
+ images : data . images ,
65
+ etc : data . etc ,
66
+ description : '' , // 사용되지 않음
67
+ products : data . products ,
68
+ } ;
69
+ try {
70
+ await createProduct ( formatRaffleData ) ;
71
+ } catch ( e ) {
72
+ console . error ( e ) ;
73
+ }
51
74
} ;
52
75
53
76
return (
@@ -64,7 +87,7 @@ const EventCreate = () => {
64
87
) }
65
88
66
89
< GenericForm
67
- onSubmit = { ( ) => onSubmit ( funnel . context ) }
90
+ onSubmit = { onSubmit }
68
91
formOptions = { {
69
92
mode : 'onChange' ,
70
93
resolver : ( data , context , options ) => {
@@ -107,13 +130,14 @@ const EventCreate = () => {
107
130
etcStep = { ( { history} ) => (
108
131
< EtcStep onNext = { etc => history . push ( 'successStep' , { etc} ) } />
109
132
) }
110
- successStep = { ( ) => (
111
- < SuccessList type = 'event' productId = { '1' } thumbnail = { '' } /> // productId,thumbnail api 연동후 작업
112
- ) }
133
+ successStep = { ( ) => < SuccessList type = 'event' productData = { data } /> }
113
134
/>
114
135
</ GenericForm >
115
136
</ div >
116
137
) ;
117
138
} ;
118
139
119
140
export default EventCreate ;
141
+
142
+ // success 라우터 따로 빼기
143
+ // -> 이미지 링크를 어떻게 줘야
0 commit comments