@@ -26,6 +26,7 @@ import {
2626 useCreateSharedPost ,
2727 usePostMateCardInputSection ,
2828 useSharedPostProps ,
29+ useUpdateSharedPost ,
2930 type ImageFile ,
3031} from '@/features/shared' ;
3132import { useToast } from '@/features/toast' ;
@@ -421,7 +422,7 @@ export function WritingPostPage() {
421422 useState < boolean > ( false ) ;
422423
423424 const {
424- mode ,
425+ postId ,
425426 title,
426427 content,
427428 images,
@@ -453,7 +454,9 @@ export function WritingPostPage() {
453454 handleOptionalFeatureChange,
454455 } = usePostMateCardInputSection ( ) ;
455456
456- const { mutate } = useCreateSharedPost ( ) ;
457+ const { mutate : createSharedPost } = useCreateSharedPost ( ) ;
458+ const { mutate : updateSharedPost } = useUpdateSharedPost ( ) ;
459+
457460 const { createToast } = useToast ( ) ;
458461
459462 const auth = useAuthValue ( ) ;
@@ -586,7 +589,7 @@ export function WritingPostPage() {
586589
587590 const putResults = await Promise . allSettled (
588591 urls . map ( async ( { url, fileName, file, uploaded } ) => {
589- if ( uploaded ) return { fileName } ;
592+ if ( uploaded ) return { fileName : url } ;
590593
591594 if ( file != null ) await putImage ( url , file ) ;
592595 return { fileName } ;
@@ -605,70 +608,128 @@ export function WritingPostPage() {
605608 } ) ;
606609 } , [ ] ) ;
607610
608- console . log ( selectedExtraOptions , {
609- canPark : selectedExtraOptions . canPark ?? false ,
610- hasAirConditioner : selectedExtraOptions . hasAirConditioner ?? false ,
611- hasRefrigerator : selectedExtraOptions . hasRefrigerator ?? false ,
612- hasWasher : selectedExtraOptions . hasWasher ?? false ,
613- hasTerrace : selectedExtraOptions . hasTerrace ?? false ,
614- } ) ;
611+ console . log ( uploadedImages ) ;
615612
616- mutate (
617- {
618- imageFilesData : uploadedImages ,
619- postData : { title, content } ,
620- transactionData : {
621- rentalType : dealTypeValue ,
622- expectedPayment : expectedMonthlyFee ,
623- } ,
624- roomDetailData : {
625- roomType : roomTypeValue ,
626- floorType : floorTypeValue ,
627- size : houseSize ,
628- numberOfRoom,
629- numberOfBathRoom,
630- hasLivingRoom : selectedOptions . livingRoom === '유' ,
631- recruitmentCapacity : mateLimit ,
632- extraOption : {
633- canPark : selectedExtraOptions . canPark ?? false ,
634- hasAirConditioner :
635- selectedExtraOptions . hasAirConditioner ?? false ,
636- hasRefrigerator : selectedExtraOptions . hasRefrigerator ?? false ,
637- hasWasher : selectedExtraOptions . hasWasher ?? false ,
638- hasTerrace : selectedExtraOptions . hasTerrace ?? false ,
613+ if ( postId == null ) {
614+ createSharedPost (
615+ {
616+ imageFilesData : uploadedImages ,
617+ postData : { title, content } ,
618+ transactionData : {
619+ rentalType : dealTypeValue ,
620+ expectedPayment : expectedMonthlyFee ,
639621 } ,
622+ roomDetailData : {
623+ roomType : roomTypeValue ,
624+ floorType : floorTypeValue ,
625+ size : houseSize ,
626+ numberOfRoom,
627+ numberOfBathRoom,
628+ hasLivingRoom : selectedOptions . livingRoom === '유' ,
629+ recruitmentCapacity : mateLimit ,
630+ extraOption : {
631+ canPark : selectedExtraOptions . canPark ?? false ,
632+ hasAirConditioner :
633+ selectedExtraOptions . hasAirConditioner ?? false ,
634+ hasRefrigerator :
635+ selectedExtraOptions . hasRefrigerator ?? false ,
636+ hasWasher : selectedExtraOptions . hasWasher ?? false ,
637+ hasTerrace : selectedExtraOptions . hasTerrace ?? false ,
638+ } ,
639+ } ,
640+ locationData : {
641+ oldAddress : address ?. jibunAddress ,
642+ roadAddress : address ?. roadAddress ,
643+ } ,
644+ roomMateCardData : {
645+ location : address ?. roadAddress ,
646+ features : derivedFeatures ,
647+ } ,
648+ participationMemberIds :
649+ auth ?. user != null ? [ auth . user . memberId ] : [ ] ,
640650 } ,
641- locationData : {
642- oldAddress : address ?. jibunAddress ,
643- roadAddress : address ?. roadAddress ,
644- } ,
645- roomMateCardData : {
646- location : address ?. roadAddress ,
647- features : derivedFeatures ,
651+ {
652+ onSuccess : ( ) => {
653+ createToast ( {
654+ message : '게시글이 정상적으로 업로드되었습니다.' ,
655+ option : {
656+ duration : 3000 ,
657+ } ,
658+ } ) ;
659+ router . back ( ) ;
660+ } ,
661+ onError : ( ) => {
662+ createToast ( {
663+ message : '게시글 업로드에 실패했습니다.' ,
664+ option : {
665+ duration : 3000 ,
666+ } ,
667+ } ) ;
668+ } ,
648669 } ,
649- participationMemberIds :
650- auth ?. user != null ? [ auth . user . memberId ] : [ ] ,
651- } ,
652- {
653- onSuccess : ( ) => {
654- createToast ( {
655- message : '게시글이 정상적으로 업로드되었습니다.' ,
656- option : {
657- duration : 3000 ,
670+ ) ;
671+ } else if ( postId != null ) {
672+ updateSharedPost (
673+ {
674+ postId,
675+ postData : {
676+ imageFilesData : uploadedImages ,
677+ postData : { title, content } ,
678+ transactionData : {
679+ rentalType : dealTypeValue ,
680+ expectedPayment : expectedMonthlyFee ,
658681 } ,
659- } ) ;
660- router . back ( ) ;
661- } ,
662- onError : ( ) => {
663- createToast ( {
664- message : '게시글 업로드에 실패했습니다.' ,
665- option : {
666- duration : 3000 ,
682+ roomDetailData : {
683+ roomType : roomTypeValue ,
684+ floorType : floorTypeValue ,
685+ size : houseSize ,
686+ numberOfRoom,
687+ numberOfBathRoom,
688+ hasLivingRoom : selectedOptions . livingRoom === '유' ,
689+ recruitmentCapacity : mateLimit ,
690+ extraOption : {
691+ canPark : selectedExtraOptions . canPark ?? false ,
692+ hasAirConditioner :
693+ selectedExtraOptions . hasAirConditioner ?? false ,
694+ hasRefrigerator :
695+ selectedExtraOptions . hasRefrigerator ?? false ,
696+ hasWasher : selectedExtraOptions . hasWasher ?? false ,
697+ hasTerrace : selectedExtraOptions . hasTerrace ?? false ,
698+ } ,
699+ } ,
700+ locationData : {
701+ oldAddress : address ?. jibunAddress ,
702+ roadAddress : address ?. roadAddress ,
667703 } ,
668- } ) ;
704+ roomMateCardData : {
705+ location : address ?. roadAddress ,
706+ features : derivedFeatures ,
707+ } ,
708+ participationMemberIds :
709+ auth ?. user != null ? [ auth . user . memberId ] : [ ] ,
710+ } ,
669711 } ,
670- } ,
671- ) ;
712+ {
713+ onSuccess : ( ) => {
714+ createToast ( {
715+ message : '게시글이 정상적으로 수정되었습니다.' ,
716+ option : {
717+ duration : 3000 ,
718+ } ,
719+ } ) ;
720+ router . back ( ) ;
721+ } ,
722+ onError : ( ) => {
723+ createToast ( {
724+ message : '게시글 수정에 실패했습니다.' ,
725+ option : {
726+ duration : 3000 ,
727+ } ,
728+ } ) ;
729+ } ,
730+ } ,
731+ ) ;
732+ }
672733 } catch ( error ) {
673734 createToast ( {
674735 message : '게시글 업로드에 실패했습니다.' ,
@@ -696,7 +757,7 @@ export function WritingPostPage() {
696757 < styles . row >
697758 < styles . optionCategory > 기본 정보</ styles . optionCategory >
698759 < styles . createButton onClick = { handleCreatePost } >
699- { mode === 'create' ? '작성하기' : '수정하기' }
760+ { postId == null ? '작성하기' : '수정하기' }
700761 </ styles . createButton >
701762 </ styles . row >
702763 < styles . optionCategory > 제목</ styles . optionCategory >
0 commit comments