Skip to content

Commit bcf7853

Browse files
committed
feat : 임시저장 api 생성(연결 테스트 아직 안함)
1 parent bfc0be3 commit bcf7853

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

src/apis/write.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const postLetter = async (data: LetterRequest) => {
55
console.log('request', data);
66
try {
77
const res = await client.post('/api/letters', data);
8-
if (!res) throw new Error('편지 전송과정중에서 오류가 발생했습니다.');
8+
if (!res) throw new Error('편지 전송과정에서 오류가 발생했습니다.');
99
return res;
1010
} catch (error) {
1111
console.error(error);
@@ -16,7 +16,7 @@ const postFirstReply = async (data: FirstReplyRequest) => {
1616
console.log('Firstrequest', data);
1717
try {
1818
const res = await client.post('/api/random-letters/matching', data);
19-
if (!res) throw new Error('최초 답장 전송과정중에서 오류가 발생했습니다.');
19+
if (!res) throw new Error('최초 답장 전송과정에서 오류가 발생했습니다.');
2020
return res;
2121
} catch (error) {
2222
console.error(error);
@@ -26,10 +26,20 @@ const postFirstReply = async (data: FirstReplyRequest) => {
2626
const getPrevLetter = async (letterId: string) => {
2727
try {
2828
const res = await client.get(`/api/letters/${letterId}/previous`);
29+
if (!res) throw new Error('이전편지를 불러오는중 오류가 발생했습니다.');
2930
return res;
3031
} catch (error) {
3132
console.error(error);
3233
}
3334
};
3435

35-
export { postLetter, postFirstReply, getPrevLetter };
36+
const postTemporarySave = async (data: LetterRequest) => {
37+
try {
38+
const res = client.post(`/api/letters/temporary-save`, data);
39+
if (!res) throw new Error('편지 임시저장과정에서 오류가 발생했습니다.');
40+
} catch (error) {
41+
console.error(error);
42+
}
43+
};
44+
45+
export { postLetter, postFirstReply, getPrevLetter, postTemporarySave };

src/pages/Write/LetterEditor.tsx

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useEffect, useState } from 'react';
2-
import { useLocation } from 'react-router';
2+
import { useLocation, useNavigate } from 'react-router';
33
import { twMerge } from 'tailwind-merge';
44

55
import { postFirstReply, postLetter } from '@/apis/write';
66
import BackButton from '@/components/BackButton';
7+
import ConfirmModal from '@/components/ConfirmModal';
78
import WritePageButton from '@/pages/Write/components/WritePageButton';
89
import { FONT_TYPE_OBJ } from '@/pages/Write/constants';
910
import OptionSlide from '@/pages/Write/OptionSlide';
@@ -24,7 +25,9 @@ export default function LetterEditor({
2425
isReply: boolean;
2526
}) {
2627
const location = useLocation();
28+
const navigate = useNavigate();
2729
const [randomMatched, setRandomMatched] = useState<boolean>(false);
30+
const [isTemporaryConfirmModal, setIsTemporaryConfirmModal] = useState<boolean>(false);
2831

2932
const letterRequest = useWrite((state) => state.letterRequest);
3033
const setLetterRequest = useWrite((state) => state.setLetterRequest);
@@ -72,26 +75,47 @@ export default function LetterEditor({
7275

7376
return (
7477
<div className="flex grow flex-col pb-15">
78+
{isTemporaryConfirmModal && (
79+
<ConfirmModal
80+
title="편지를 임시저장 하시겠어요?"
81+
description="임시저장된 편지는 홈 화면 공유 버튼에서 확인 가능합니다."
82+
cancelText="계속 작성하기"
83+
confirmText="저장하고 나가기"
84+
onCancel={() => setIsTemporaryConfirmModal(false)}
85+
onConfirm={() => {
86+
// postTemporarySave(letterRequest)
87+
navigate('/');
88+
}}
89+
/>
90+
)}
7591
<OptionSlide prevLetter={prevLetter} />
7692
<div className="absolute left-0 flex w-full items-center justify-between px-5">
7793
<BackButton />
7894
{isReply ? (
79-
<WritePageButton
80-
text="답장 전송"
81-
onClick={() => {
82-
if (letterRequest.title.trim() !== '' && letterRequest.content.trim() !== '') {
83-
if (randomMatched) {
84-
const firstReplyRequest = removeProperty(letterRequest, ['matchingId']);
85-
console.log(firstReplyRequest);
86-
handlePostFirstReply(firstReplyRequest);
95+
<div className="flex gap-1">
96+
<WritePageButton
97+
text="임시저장"
98+
onClick={() => {
99+
setIsTemporaryConfirmModal(true);
100+
}}
101+
/>
102+
<WritePageButton
103+
text="답장 전송"
104+
onClick={() => {
105+
if (letterRequest.title.trim() !== '' && letterRequest.content.trim() !== '') {
106+
if (randomMatched) {
107+
const firstReplyRequest = removeProperty(letterRequest, ['matchingId']);
108+
console.log(firstReplyRequest);
109+
handlePostFirstReply(firstReplyRequest);
110+
} else {
111+
handlePostReply(letterRequest);
112+
}
87113
} else {
88-
handlePostReply(letterRequest);
114+
alert('편지 제목, 내용이 작성되었는지 확인해주세요');
89115
}
90-
} else {
91-
alert('편지 제목, 내용이 작성되었는지 확인해주세요');
92-
}
93-
}}
94-
/>
116+
}}
117+
/>
118+
</div>
95119
) : (
96120
<WritePageButton
97121
text="다음 단계"

0 commit comments

Comments
 (0)