1+ import { useEffect , useState } from 'react' ;
2+ import { useLocation } from 'react-router' ;
13import { twMerge } from 'tailwind-merge' ;
24
35import { postLetter } from '@/apis/write' ;
@@ -18,6 +20,9 @@ export default function LetterEditor({
1820 setSend : React . Dispatch < React . SetStateAction < boolean > > ;
1921 searchParams : URLSearchParams ;
2022} ) {
23+ const location = useLocation ( ) ;
24+ const [ randomMatched , setRandomMatched ] = useState < boolean > ( false ) ;
25+
2126 const fontType = useWrite ( ( state ) => state . fontType ) ;
2227 const paperType = useWrite ( ( state ) => state . paperType ) ;
2328
@@ -37,6 +42,12 @@ export default function LetterEditor({
3742 fontType : fontType ,
3843 } ;
3944
45+ useEffect ( ( ) => {
46+ if ( location . state ?. randomMatched ) {
47+ setRandomMatched ( true ) ;
48+ }
49+ } , [ location . state ?. randomMatched ] ) ;
50+
4051 return (
4152 < div className = "flex grow flex-col pb-15" >
4253 < OptionSlide prevLetter = { prevLetter } />
@@ -47,12 +58,16 @@ export default function LetterEditor({
4758 text = "답장 전송"
4859 onClick = { ( ) => {
4960 if ( letterTitle . trim ( ) !== '' && letterText . trim ( ) !== '' ) {
50- postLetter ( LETTER_REQUEST , ( ) => {
51- console . log ( LETTER_REQUEST ) ;
52- console . log ( prevLetter ) ;
53- setSend ( true ) ;
54- setStep ( 'category' ) ;
55- } ) ;
61+ if ( randomMatched ) {
62+ console . log ( '랜덤편지 답장 전송용API' ) ;
63+ } else {
64+ postLetter ( LETTER_REQUEST , ( ) => {
65+ console . log ( LETTER_REQUEST ) ;
66+ console . log ( prevLetter ) ;
67+ setSend ( true ) ;
68+ setStep ( 'category' ) ;
69+ } ) ;
70+ }
5671 } else {
5772 alert ( '편지 제목, 내용이 작성되었는지 확인해주세요' ) ;
5873 }
0 commit comments