File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 11import { create } from 'zustand' ;
22
3- import { client } from '@/apis/client ' ;
3+ import { fetchIncomingLettersApi } from '@/apis/incomingLetters ' ;
44
55interface IncomingLetters {
66 letterId : number ;
@@ -23,9 +23,7 @@ function formatTime(time: number): string {
2323
2424function 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 ) => ( {
You can’t perform that action at this time.
0 commit comments