Skip to content

Commit ae5d936

Browse files
committed
refactor: 오고 있는 편지 파일 구조 수정
1 parent 3538dfc commit ae5d936

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/apis/incomingLetters.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { client } from '@/apis/client';
2+
3+
export const fetchIncomingLettersApi = async (token: string) => {
4+
try {
5+
const { data } = await client.get('/api/letters?status=delivery', {
6+
headers: {
7+
Authorization: `Bearer ${token}`,
8+
},
9+
});
10+
return data;
11+
} catch (error) {
12+
console.error('❌오고 있는 편지 목록을 불러오던 중 에러 발생', error);
13+
throw error;
14+
}
15+
};

src/stores/incomingLettersStore.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand';
22

3-
import { client } from '@/apis/client';
3+
import { fetchIncomingLettersApi } from '@/apis/incomingLetters';
44

55
interface IncomingLetters {
66
letterId: number;
@@ -23,9 +23,7 @@ function formatTime(time: number): string {
2323

2424
function calculatingRemainingTime(deliveryCompletedAt: string): string {
2525
const completedAt = new Date(deliveryCompletedAt).getTime();
26-
2726
const now = new Date().getTime();
28-
2927
const diff = completedAt - now;
3028

3129
if (diff <= 0) return '00:00:00';
@@ -43,13 +41,8 @@ export const useIncomingLettersStore = create<IncomingLettersStore>((set) => ({
4341
timestamp: '',
4442
fetchIncomingLetters: async () => {
4543
try {
46-
const { data } = await client.get('/api/letters?status=delivery', {
47-
headers: {
48-
Authorization: `Bearer ${localStorage.getItem('token')}`,
49-
},
50-
});
51-
console.log('API 응답 데이터:', data);
52-
console.log(data.message);
44+
const token = localStorage.getItem('token') || '';
45+
const data = await fetchIncomingLettersApi(token);
5346

5447
const updatedLetters = data.data
5548
.map((letter: IncomingLetters) => ({

0 commit comments

Comments
 (0)