@@ -28,8 +28,8 @@ interface Column {
28
28
}
29
29
30
30
const columns : readonly Column [ ] = [
31
- { id : 'waiting_id' , label : '순번' , minWidth : 30 } ,
32
- { id : 'name' , label : '예약자' , minWidth : 30 } ,
31
+ { id : 'waiting_id' , label : '순번' , minWidth : 30 , align : 'center' , } ,
32
+ { id : 'name' , label : '예약자' , minWidth : 30 , align : 'center' } ,
33
33
{
34
34
id : 'people' ,
35
35
label : '인원 수' ,
@@ -54,36 +54,28 @@ export default function ListTable({waiting}:{waiting:waitings[]|undefined}) {
54
54
console . log ( waiting )
55
55
} ;
56
56
57
-
58
-
59
- useEffect ( ( ) => {
60
- console . log ( waiting ) ;
61
- } , [ ] )
62
-
63
-
64
57
const handleChangeRowsPerPage = ( event : React . ChangeEvent < HTMLInputElement > ) => {
65
58
setRowsPerPage ( + event . target . value ) ;
66
59
setPage ( 0 ) ;
67
60
} ;
68
-
61
+
69
62
//대기목록 MUI 안에 있는 호출 버튼
70
- // const Call =()=>{
71
- // axios.post('http://15.164.28.246:8000/api/v1/stores/notifications/',{
72
- // token : 'token'
73
- // })
74
- // .then((response) => {
75
- // localStorage.getItem('store_id')
76
- // //" "
77
- // localStorage.getItem('chapter_id')
78
- // })
79
- // .catch((error) => {
80
- // console.log('호출 실패');
81
- // });
82
- // }
63
+ const Call = ( ) => {
64
+ axios . post ( 'http://15.164.28.246:8000/api/v1/stores/notifications/' , {
65
+ token : localStorage . getItem ( 'accessToken' )
66
+ } )
67
+ . then ( ( response ) => {
68
+ console . log ( response . data )
69
+ } )
70
+ . catch ( ( error ) => {
71
+ console . log ( '호출 실패' ) ;
72
+ } ) ;
73
+ }
83
74
84
75
//대기목록 MUI 안에 있는 입장완료 버튼
85
76
const Start = ( index : number ) => {
86
- if ( waiting != undefined )
77
+ if ( waiting !== undefined ) {
78
+ console . log ( waiting [ index ] . waiting_id ) ;
87
79
axios . patch ( 'http://15.164.28.246:8000/api/v1/stores/waitings/' , {
88
80
waiting_id : waiting [ index ] . waiting_id
89
81
} ,
@@ -97,13 +89,15 @@ export default function ListTable({waiting}:{waiting:waitings[]|undefined}) {
97
89
. catch ( ( error ) => {
98
90
console . log ( 'Error!' ) ;
99
91
} ) ;
100
- }
92
+ } }
101
93
102
94
//대기목록 MUI 안에 있는 대기취소 버튼
103
95
const waitingCancel = ( index : number ) => {
104
- if ( waiting != undefined )
105
- axios . patch < res > ( 'http://15.164.28.246:8000/api/v1//stores/cancellations/' , {
106
- waiting_id : waiting [ index ] . waiting_id
96
+ if ( waiting != undefined ) {
97
+ //console.log(index); //배열(?) 확인용
98
+ //console.log(waiting[index].waiting_id);
99
+ axios . patch < res > ( 'http://15.164.28.246:8000/api/v1/stores/cancellations/' , {
100
+ waiting_id : waiting [ index ] . waiting_id
107
101
} ,
108
102
{
109
103
headers : { Authorization : localStorage . getItem ( 'accessToken' ) }
@@ -115,7 +109,7 @@ export default function ListTable({waiting}:{waiting:waitings[]|undefined}) {
115
109
. catch ( ( error ) => {
116
110
console . log ( 'Error!' ) ;
117
111
} ) ;
118
- }
112
+ } }
119
113
120
114
return (
121
115
< Paper className = 'tableStyle' >
@@ -140,7 +134,7 @@ export default function ListTable({waiting}:{waiting:waitings[]|undefined}) {
140
134
< TableBody >
141
135
142
136
{ waiting ?. slice ( page * rowsPerPage , page * rowsPerPage + rowsPerPage )
143
- . map ( ( row :any ) => {
137
+ . map ( ( row :any , index : number ) => {
144
138
if ( waiting != undefined ) {
145
139
abc = waiting . length
146
140
}
@@ -158,9 +152,10 @@ export default function ListTable({waiting}:{waiting:waitings[]|undefined}) {
158
152
</ TableCell >
159
153
) ;
160
154
} ) }
161
- < TableCell align = "center" > < IconButton > < NotificationsActiveIcon color = "warning" /> </ IconButton > </ TableCell >
162
- < TableCell onClick = { ( ) => Start ( row . waiting_id ) } align = "center" > < IconButton > < CheckCircleIcon color = "success" /> </ IconButton > </ TableCell >
163
- < TableCell onClick = { ( ) => waitingCancel ( row . waiting_id ) } align = "center" > < IconButton > < CancelIcon color = "error" /> </ IconButton > </ TableCell >
155
+ < TableCell onClick = { ( ) => Call ( ) } align = "center" > < IconButton > < NotificationsActiveIcon color = "warning" /> </ IconButton > </ TableCell >
156
+ { /* waiting_id 대신 index를 넣어줘야 waiting_id가 6, 7 일 때 배열 값과 달라서 발생하는 에러를 해결할 수 있음 */ }
157
+ < TableCell onClick = { ( ) => Start ( index ) } align = "center" > < IconButton > < CheckCircleIcon color = "success" /> </ IconButton > </ TableCell >
158
+ < TableCell onClick = { ( ) => waitingCancel ( index ) } align = "center" > < IconButton > < CancelIcon color = "error" /> </ IconButton > </ TableCell >
164
159
</ TableRow >
165
160
) ;
166
161
} ) }
@@ -179,4 +174,15 @@ export default function ListTable({waiting}:{waiting:waitings[]|undefined}) {
179
174
/>
180
175
</ Paper >
181
176
) ;
182
- }
177
+ }
178
+ // 파일에서 command+shift+f로 검색
179
+ // TablePagination의 count가 undefined,count에서 waiting을 못 읽었어!,
180
+ // 왜냐면 useEffect가 실행되기 전 컴포넌트(waiting={temp?.data})가 먼저 실행됐기 때문에 undefined 상태,
181
+ // undefined상태에서 waiting을 slice 등을 해주라고 하니까 오류가 발생한 거야
182
+ // 오류를 해결하기 위해서 undefined일 때 waiting을 빈 배열로 만들어 줘서 초기값을 만들어준겨
183
+
184
+ ListTable . defaultProps = {
185
+ waiting :[ ]
186
+ }
187
+
188
+ //
0 commit comments