@@ -4,10 +4,12 @@ import { zodResolver } from "@hookform/resolvers/zod";
44import { useRouter } from "next/navigation" ;
55import { FormProvider , useForm } from "react-hook-form" ;
66
7+ import { getPresignedUrl , uploadImageToS3 } from "@/app/_api/image/image.api" ;
78import CancelIcon from "@/assets/cancel.svg" ;
89import { GNB } from "@/components/ui/GNB" ;
910import { Spacer } from "@/components/ui/Spacer" ;
1011import { VStack } from "@/components/ui/Stack" ;
12+ import { type ImageRequest } from "@/types/image.types" ;
1113
1214import { usePostStoryMutation } from "./_api" ;
1315import { StoryDescription } from "./_components/StoryDescription" ;
@@ -39,25 +41,51 @@ export default function StoryRegisterPage() {
3941 } ) ;
4042
4143 const onSubmit = async ( data : StoryRegisterFormData ) => {
42- postStory (
43- {
44- storyRequest : {
44+ try {
45+ let imageData : ImageRequest [ ] = [ ] ;
46+
47+ if ( data . image ) {
48+ const { urls : presignedUrls } = await getPresignedUrl ( [
49+ {
50+ order : 0 ,
51+ contentType : data . image . type ,
52+ fileSize : data . image . size ,
53+ } ,
54+ ] ) ;
55+
56+ const { url, key, order, contentType } = presignedUrls [ 0 ] ! ;
57+ await uploadImageToS3 ( url , data . image ) ;
58+
59+ imageData = [
60+ {
61+ imageKey : key ,
62+ orderIndex : order ,
63+ contentType,
64+ fileSize : data . image . size ,
65+ } ,
66+ ] ;
67+ }
68+
69+ postStory (
70+ {
4571 storeKakaoId : data . storeKakaoId ,
4672 storeName : data . storeName ,
4773 description : data . description || null ,
74+ images : imageData ,
4875 } ,
49- imageFile : data . image ,
50- } ,
51- {
52- onSuccess : response => {
53- clearUpload ( ) ;
54- router . push ( `/story/${ response . storyId } ` ) ;
55- } ,
56- onError : error => {
57- console . error ( "스토리 등록 실패:" , error ) ;
58- } ,
59- }
60- ) ;
76+ {
77+ onSuccess : response => {
78+ clearUpload ( ) ;
79+ router . push ( `/story/${ response . storyId } ` ) ;
80+ } ,
81+ onError : error => {
82+ console . error ( "스토리 등록 실패:" , error ) ;
83+ } ,
84+ }
85+ ) ;
86+ } catch ( error ) {
87+ console . error ( "이미지 업로드 실패:" , error ) ;
88+ }
6189 } ;
6290
6391 return (
0 commit comments