@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
22import { useLocation , useNavigate } from 'react-router' ;
33import { twMerge } from 'tailwind-merge' ;
44
5- import { postFirstReply , postLetter } from '@/apis/write' ;
5+ import { postFirstReply , postLetter , postTemporarySave } from '@/apis/write' ;
66import BackButton from '@/components/BackButton' ;
77import ConfirmModal from '@/components/ConfirmModal' ;
88import WritePageButton from '@/pages/Write/components/WritePageButton' ;
@@ -12,17 +12,17 @@ import useWrite from '@/stores/writeStore';
1212import { removeProperty } from '@/utils/removeProperty' ;
1313
1414export default function LetterEditor ( {
15+ letterId,
1516 setStep,
1617 prevLetter,
1718 setSend,
18- searchParams,
1919 isReply,
2020} : {
21- setStep : React . Dispatch < React . SetStateAction < Step > > ;
21+ letterId : string | null ;
22+ isReply : boolean ;
2223 prevLetter : PrevLetter [ ] ;
24+ setStep : React . Dispatch < React . SetStateAction < Step > > ;
2325 setSend : React . Dispatch < React . SetStateAction < boolean > > ;
24- searchParams : URLSearchParams ;
25- isReply : boolean ;
2626} ) {
2727 const location = useLocation ( ) ;
2828 const navigate = useNavigate ( ) ;
@@ -66,12 +66,23 @@ export default function LetterEditor({
6666 console . log ( 'prevLetter' , prevLetter ) ;
6767 setLetterRequest ( {
6868 receiverId : prevLetter [ 0 ] . memberId ,
69- parentLetterId : Number ( searchParams . get ( ' letterId' ) ) ,
69+ parentLetterId : Number ( letterId ) ,
7070 category : prevLetter [ 0 ] . category ,
7171 matchingId : prevLetter [ 0 ] . matchingId ,
7272 } ) ;
7373 }
74- } , [ prevLetter , searchParams , setLetterRequest , isReply ] ) ;
74+ } , [ prevLetter , setLetterRequest , isReply ] ) ;
75+
76+ const handlePostTemporarySave = async ( ) => {
77+ if ( ! letterId ) return alert ( '임시저장중 오류 발생' ) ;
78+ const res = await postTemporarySave ( letterId , letterRequest ) ;
79+ if ( res ?. status === 200 ) {
80+ console . log ( res ) ;
81+ navigate ( '/' ) ;
82+ } else {
83+ alert ( '실패' ) ;
84+ }
85+ } ;
7586
7687 return (
7788 < div className = "flex grow flex-col pb-15" >
@@ -83,8 +94,7 @@ export default function LetterEditor({
8394 confirmText = "저장하고 나가기"
8495 onCancel = { ( ) => setIsTemporaryConfirmModal ( false ) }
8596 onConfirm = { ( ) => {
86- // postTemporarySave(letterRequest)
87- navigate ( '/' ) ;
97+ handlePostTemporarySave ( ) ;
8898 } }
8999 />
90100 ) }
0 commit comments