1- import { useRef } from 'react' ;
21import { twMerge } from 'tailwind-merge' ;
32
3+ import { postLetter } from '@/apis/write' ;
44import BackButton from '@/components/BackButton' ;
55import WritePageButton from '@/pages/Write/components/WritePageButton' ;
66import { FONT_TYPE_OBJ } from '@/pages/Write/constants' ;
@@ -10,25 +10,31 @@ import useWrite from '@/stores/writeStore';
1010export default function LetterEditor ( {
1111 setStep,
1212 prevLetter,
13+ setSend,
14+ searchParams,
1315} : {
1416 setStep : React . Dispatch < React . SetStateAction < Step > > ;
1517 prevLetter : PrevLetter [ ] ;
18+ setSend : React . Dispatch < React . SetStateAction < boolean > > ;
19+ searchParams : URLSearchParams ;
1620} ) {
17- const textareaRef = useRef < HTMLTextAreaElement | null > ( null ) ;
18-
1921 const fontType = useWrite ( ( state ) => state . fontType ) ;
22+ const paperType = useWrite ( ( state ) => state . paperType ) ;
2023
2124 const letterTitle = useWrite ( ( state ) => state . letterTitle ) ;
2225 const setLetterTitle = useWrite ( ( state ) => state . setLetterTitle ) ;
2326
2427 const letterText = useWrite ( ( state ) => state . letterText ) ;
2528 const setLetterText = useWrite ( ( state ) => state . setLetterText ) ;
2629
27- const handleResizeHeight = ( ) => {
28- if ( textareaRef . current !== null ) {
29- textareaRef . current . style . height = 'auto' ; //height 초기화
30- textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ;
31- }
30+ const LETTER_REQUEST : LetterRequest = {
31+ receiverId : prevLetter . length > 0 ? prevLetter [ 0 ] . memberId : null ,
32+ parentLetterId : Number ( searchParams . get ( 'letterId' ) ) ,
33+ title : letterTitle ,
34+ content : letterText ,
35+ category : prevLetter . length > 0 ? prevLetter [ 0 ] . category : 'ETC' ,
36+ paperType : paperType ,
37+ fontType : fontType ,
3238 } ;
3339
3440 return (
@@ -41,7 +47,12 @@ export default function LetterEditor({
4147 text = "답장 전송"
4248 onClick = { ( ) => {
4349 if ( letterTitle . trim ( ) !== '' && letterText . trim ( ) !== '' ) {
44- setStep ( 'category' ) ;
50+ postLetter ( LETTER_REQUEST , ( ) => {
51+ console . log ( LETTER_REQUEST ) ;
52+ console . log ( prevLetter ) ;
53+ setSend ( true ) ;
54+ setStep ( 'category' ) ;
55+ } ) ;
4556 } else {
4657 alert ( '편지 제목, 내용이 작성되었는지 확인해주세요' ) ;
4758 }
@@ -80,7 +91,7 @@ export default function LetterEditor({
8091 ) }
8192 placeholder = "클릭해서 내용을 작성하세요"
8293 onChange = { ( e ) => {
83- handleResizeHeight ( ) ;
94+ // handleResizeHeight();
8495 setLetterText ( e . target . value ) ;
8596 } }
8697 value = { letterText }
0 commit comments