Skip to content

Commit a00ebf5

Browse files
committed
feat : 편지 작성 페이지 임시저장 버튼 구현
1 parent bcf7853 commit a00ebf5

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

src/apis/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ client.interceptors.response.use(
102102
}
103103
}
104104
}
105-
if (isLoggedIn) logout();
106-
console.error('Failed to refresh token', error);
105+
// if (isLoggedIn) logout();
106+
// console.error('Failed to refresh token', error);
107107
return Promise.reject(error);
108108
},
109109
);

src/apis/write.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,26 @@ const getPrevLetter = async (letterId: string) => {
3333
}
3434
};
3535

36-
const postTemporarySave = async (data: LetterRequest) => {
36+
// 임시저장 최초 생성
37+
const postTemporarySave = async (letterId: string, data: LetterRequest) => {
3738
try {
38-
const res = client.post(`/api/letters/temporary-save`, data);
39+
const res = client.post(`/api/letters/${letterId}/temporary-save`, data);
3940
if (!res) throw new Error('편지 임시저장과정에서 오류가 발생했습니다.');
41+
return res;
42+
} catch (error) {
43+
console.error(error);
44+
}
45+
};
46+
47+
// 임시저장 수정
48+
const PatchTemporarySave = async (letterId: string, data: LetterRequest) => {
49+
try {
50+
const res = client.post(`/api/letters/${letterId}/temporary-save`, data);
51+
if (!res) throw new Error('편지 임시저장과정에서 오류가 발생했습니다.');
52+
return res;
4053
} catch (error) {
4154
console.error(error);
4255
}
4356
};
4457

45-
export { postLetter, postFirstReply, getPrevLetter, postTemporarySave };
58+
export { postLetter, postFirstReply, getPrevLetter, postTemporarySave, PatchTemporarySave };

src/pages/Write/LetterEditor.tsx

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

5-
import { postFirstReply, postLetter } from '@/apis/write';
5+
import { postFirstReply, postLetter, postTemporarySave } from '@/apis/write';
66
import BackButton from '@/components/BackButton';
77
import ConfirmModal from '@/components/ConfirmModal';
88
import WritePageButton from '@/pages/Write/components/WritePageButton';
@@ -12,17 +12,17 @@ import useWrite from '@/stores/writeStore';
1212
import { removeProperty } from '@/utils/removeProperty';
1313

1414
export 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
)}

src/pages/Write/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ const WritePage = () => {
7272
<div className={wrapStyle}>
7373
{step === 'edit' && (
7474
<LetterEditor
75+
letterId={letterId}
7576
setStep={setStep}
7677
prevLetter={prevLetter}
7778
setSend={setSend}
78-
searchParams={searchParams}
7979
isReply={isReply}
8080
/>
8181
)}

0 commit comments

Comments
 (0)