@@ -6,7 +6,8 @@ import Select from 'react-select';
66import useAxios from '@/utils/hooks/useAxios' ;
77import { getPresignedUrl } from '@/utils/apis/getPresignedUrl' ;
88import { uploadImageToS3 } from '@/utils/apis/uploadImageToS3' ;
9- import useCustomFetch from '@/utils/hooks/useAxios' ;
9+ //import useCustomFetch from '@/utils/hooks/useAxios';
10+ import useCustomFetch from '@/utils/hooks/useCustomFetch' ;
1011
1112import ImageUploadBox from '@/components/ImageUploadBox2' ;
1213import TopBar from '@/components/TopBar' ;
@@ -22,6 +23,7 @@ function UploadPic() {
2223 { title : '킬링시저' , date : '25.06.10~25.06.13' } ,
2324 ] ;
2425
26+ const [ file , setFile ] = useState ( null ) ;
2527 const [ selected , setSelected ] = useState ( null ) ;
2628 const [ menuOpen , setMenuOpen ] = useState ( false ) ;
2729 const [ showModal , setShowModal ] = useState ( false ) ;
@@ -31,32 +33,47 @@ function UploadPic() {
3133 const [ textContent , setTextContent ] = useState ( '' ) ;
3234 const isFormValid = Boolean ( selected ?. title && selected ?. date && file ) ;
3335
34- const baseOptions = data . map ( ( item ) => ( {
35- value : `${ item . title } -${ item . date } ` ,
36+ const searchInput = encodeURIComponent ( inputValue ) ;
37+ const {
38+ data : searchData ,
39+ error : searchError ,
40+ loading : searchLoading ,
41+ } = useCustomFetch ( `/search?keyword=${ searchInput } &page=0&size=10` ) ;
42+ //console.log('입력값:', inputValue);
43+ //console.log(searchInput);
44+ //console.log('결과:', searchData);
45+ //console.log(searchLoading);
46+ //console.log('선택된 항목:', selected)
47+
48+ const searchOptions = ( searchData ?. result ?. content || [ ] ) . map ( ( item ) => ( {
49+ value : item . showId ,
3650 title : item . title ,
37- date : item . date ,
51+ date : item . schedule ,
3852 label : (
3953 < LabelWrapper >
40- < Title > { item . title } </ Title >
41- < Date > { item . date } </ Date >
54+ { item . posterImageUrl && (
55+ < img
56+ src = { item . posterImageUrl }
57+ alt = { item . title }
58+ style = { { width : 30 , height : 40 , marginRight : 8 , borderRadius : 4 } }
59+ />
60+ ) }
61+ < div >
62+ < Title > { item . title } </ Title >
63+ < Date > { item . schedule } </ Date >
64+ </ div >
4265 </ LabelWrapper >
4366 ) ,
4467 } ) ) ;
4568
4669 const options = [
47- ...baseOptions ,
48- ...customOptions ,
70+ ...searchOptions ,
4971 {
5072 value : 'custom' ,
5173 label : < Title > 직접 입력</ Title > ,
5274 } ,
5375 ] ;
5476
55- const filteredOptions = baseOptions . filter (
56- ( option ) =>
57- option . title . includes ( inputValue ) || option . date . includes ( inputValue ) ,
58- ) ;
59-
6077 const handleSelectChange = ( option ) => {
6178 if ( option . value === 'custom' ) {
6279 setShowModal ( true ) ;
@@ -124,26 +141,31 @@ function UploadPic() {
124141 const extension = file . name . split ( '.' ) . pop ( ) . toLowerCase ( ) ;
125142
126143 const { uploadUrl, publicUrl, keyName } = await getPresignedUrl (
144+ axiosClient ,
127145 extension ,
128146 'photoAlbum' ,
129147 ) ;
130148
131- console . log ( '✅ S3 응답:' , uploadUrl ) ; // 디버깅용
132- console . log ( '✅ keyName:' , keyName ) ; // 디버깅용
133- console . log ( '✅ publicUrl:' , publicUrl ) ; // 디버깅용
149+ console . log ( 'S3 응답:' , uploadUrl ) ; // 디버깅용
150+ console . log ( 'keyName:' , keyName ) ; // 디버깅용
151+ console . log ( 'publicUrl:' , publicUrl ) ; // 디버깅용
134152
135- const url = `https://ccbucket-0528.s3.ap-northeast-2.amazonaws.com/${ uploadUrl } ` ;
136- await uploadImageToS3 ( axiosClient , extension , url ) ;
153+ // const url = `https://ccbucket-0528.s3.ap-northeast-2.amazonaws.com/${uploadUrl}`;
154+ await uploadImageToS3 ( axiosClient , extension , uploadUrl ) ;
137155
138156 const postBody = {
139- //추후 ID 수정
140- amateurShowId : 4 ,
157+ amateurShowId : selected . value ,
141158 content : textContent ,
142- imageRequestDTOs : [ { keyName, imageUrl : publicUrl } ] ,
159+ imageRequestDTOs : [ { keyName : keyName , imageUrl : publicUrl } ] ,
143160 } ;
161+ console . log ( postBody ) ;
144162
145163 const res = await fetchData ( '/photoAlbums' , 'POST' , postBody ) ;
146- if ( ! res . ok ) throw new Error ( `서버 응답 오류: ${ res . status } ` ) ;
164+ //console.log(postBody)
165+ if ( res . status !== 200 && res . status !== 201 ) {
166+ throw new Error ( `서버 응답 오류: ${ res . status } ` ) ;
167+ }
168+ console . log ( '응답 데이터:' , res . data ) ;
147169 alert ( '등록 완료!' ) ;
148170 } catch ( err ) {
149171 console . error ( err ) ;
@@ -216,7 +238,7 @@ function UploadPic() {
216238 />
217239 { menuOpen && (
218240 < Dropdown >
219- { filteredOptions . map ( ( option , idx ) => (
241+ { options . map ( ( option , idx ) => (
220242 < OptionItem
221243 key = { idx }
222244 onClick = { ( ) => {
0 commit comments