-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import instance from '@apis/instance'; | ||
|
||
import fetchOrders from './orderQueries'; | ||
interface OrderResponse { | ||
productId: number; | ||
productImage: string; | ||
detail: string; | ||
price: number; | ||
quantity: number; | ||
} | ||
|
||
const useOrders = (productId: number) => | ||
useQuery({ | ||
queryKey: ['orders', productId], | ||
queryFn: () => fetchOrders(), | ||
}); | ||
interface OrderHistoryResponse { | ||
success: boolean; | ||
data: OrderResponse; | ||
error: string | null; | ||
} | ||
|
||
export default useOrders; | ||
const fetchOrders = async (): Promise<OrderHistoryResponse> => { | ||
const response = await instance.get<OrderHistoryResponse>(`/api/orders`); | ||
return response.data; | ||
}; | ||
|
||
export default fetchOrders; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,13 @@ | ||
import instance from '@apis/instance'; | ||
import { AxiosError } from 'axios'; | ||
import dummpyOrderHistory from '@constants/dummyOrderHistory'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
interface OrderResponse { | ||
productId: number; | ||
productImage: string; | ||
detail: string; | ||
price: number; | ||
quantity: number; | ||
} | ||
import fetchOrders from './getOrders'; | ||
|
||
interface OrderHistoryResponse { | ||
success: boolean; | ||
data: OrderResponse[]; | ||
error: string | null; | ||
} | ||
const useOrders = () => | ||
useQuery({ | ||
queryKey: ['orders'], | ||
queryFn: () => fetchOrders(), | ||
initialData: dummpyOrderHistory, | ||
}); | ||
|
||
const fetchOrders = async (): Promise<OrderResponse[]> => { | ||
try { | ||
const response = await instance.get<OrderHistoryResponse>(`/api/orders`); | ||
return response.data.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
throw error.response?.data || new Error('An error occurred'); | ||
} | ||
throw error; | ||
} | ||
}; | ||
|
||
export default fetchOrders; | ||
export default useOrders; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const dummpyOrderHistory = { | ||
success: true, | ||
data: { | ||
productId: 1, | ||
productImage: 'https://ae01.alicdn.com/kf/S709d4d4778ea430c87c0bf0a6574fa8dz.jpg_220x220q75.jpg_.webp', | ||
detail: | ||
'Toocki C타입 to C타입 케이블, 100W PD 고속 충전 충전기, USB C to USB C 디스플레이 케이블, 샤오미 POCO F3 리얼미 맥북 아이패드용', | ||
price: 2700, | ||
quantity: 2, | ||
}, | ||
error: null, | ||
}; | ||
|
||
export default dummpyOrderHistory; |
This file was deleted.
Oops, something went wrong.