@@ -5,6 +5,7 @@ import ArrowBackIcon from 'assets/svg/Callvan/arrow-back.svg';
55import useCallvanToast from 'components/Callvan/hooks/useCallvanToast' ;
66import useReportCallvan from 'components/Callvan/hooks/useReportCallvan' ;
77import ROUTES from 'static/routes' ;
8+ import useUploadFile from 'utils/hooks/uploadFile/useUploadFile' ;
89import showToast from 'utils/ts/showToast' ;
910import DetailStep from './DetailStep' ;
1011import ReasonStep from './ReasonStep' ;
@@ -18,6 +19,7 @@ interface ReportPageProps {
1819export default function ReportPage ( { postId, reportedUserId } : ReportPageProps ) {
1920 const router = useRouter ( ) ;
2021 const { mutate, isPending } = useReportCallvan ( postId ) ;
22+ const { uploadFile, isPending : isUploading } = useUploadFile ( ) ;
2123
2224 const [ step , setStep ] = useState < 1 | 2 > ( 1 ) ;
2325 const [ selectedReasons , setSelectedReasons ] = useState < Set < CallvanReportReasonCode > > ( new Set ( ) ) ;
@@ -59,18 +61,31 @@ export default function ReportPage({ postId, reportedUserId }: ReportPageProps)
5961 }
6062 } ;
6163
62- const handleSubmit = ( ) => {
64+ const handleSubmit = async ( ) => {
6365 const reasons : CallvanReportReason [ ] = Array . from ( selectedReasons ) . map ( ( code ) => ( {
6466 reason_code : code ,
6567 ...( code === 'OTHER' ? { custom_text : customText } : { } ) ,
6668 } ) ) ;
6769
70+ let attachments : { attachment_type : 'IMAGE' ; url : string } [ ] = [ ] ;
71+ if ( images . length > 0 ) {
72+ try {
73+ const uploadResults = await Promise . all (
74+ images . map ( ( file ) => uploadFile ( { domain : 'CALLVAN_REPORT' , file } ) ) ,
75+ ) ;
76+ attachments = uploadResults . map ( ( result : { file_url : string } ) => ( { attachment_type : 'IMAGE' as const , url : result . file_url } ) ) ;
77+ } catch {
78+ showToast ( 'error' , '이미지 업로드에 실패했습니다.' ) ;
79+ return ;
80+ }
81+ }
82+
6883 mutate (
6984 {
7085 reported_user_id : reportedUserId ,
7186 ...( description . trim ( ) ? { description : description . trim ( ) } : { } ) ,
7287 reasons,
73- // TODO: images를 FormData로 업로드하는 API가 완성되면 여기에 연결
88+ ... ( attachments . length > 0 ? { attachments } : { } ) ,
7489 } ,
7590 {
7691 onSuccess : ( ) => {
@@ -120,7 +135,7 @@ export default function ReportPage({ postId, reportedUserId }: ReportPageProps)
120135 다음
121136 </ button >
122137 ) : (
123- < button type = "button" className = { styles [ 'page__submit-button' ] } onClick = { handleSubmit } disabled = { isPending } >
138+ < button type = "button" className = { styles [ 'page__submit-button' ] } onClick = { handleSubmit } disabled = { isPending || isUploading } >
124139 신고하기
125140 </ button >
126141 ) }
0 commit comments