Skip to content

Commit

Permalink
feat: 주문 추적 기능 개선 및 이벤트 처리 추가
Browse files Browse the repository at this point in the history
- useOrderTracking 훅에서 배송 추적 이벤트를 처리하기 위해 TrackingResponseEvent 타입을 추가했습니다.
- 배송 상태 업데이트 로직을 개선하여 새로운 이벤트 구조를 반영하고, 이벤트에 고유 키를 부여하여 데이터 관리의 일관성을 높였습니다.
- DeliveryTrackingResponse 타입에 _key 필드를 추가하여 이벤트의 고유성을 보장했습니다.
  • Loading branch information
ruddnjs3769 committed Jan 11, 2025
1 parent cf49ae2 commit 7c5c3be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/hooks/useOrderTracking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/hooks/useOrderTracking.ts
import useSWR from "swr";
import { Order } from "@/type/order";
import { DeliveryTrackingResponse } from "@/type/order";
import { DeliveryTrackingResponse, TrackingResponseEvent } from "@/type/order";
import { DELIVERY_STATUS } from "@/constants/deliveryStatus";

export function useOrderTracking(order: Order) {
Expand Down Expand Up @@ -42,13 +42,20 @@ export function useOrderTracking(order: Order) {
const orderStatus =
DELIVERY_STATUS[trackingStatus as keyof typeof DELIVERY_STATUS] ||
"unknown";
console.log("orderStatus", orderStatus);
// 현재 상태와 새로운 상태가 같으면 업데이트하지 않음
if (order.orderStatus === orderStatus) {
return;
}

try {
const events: TrackingResponseEvent[] =
data?.data?.track?.events?.edges.map(event => ({
node: {
...event.node,
},
_key: crypto.randomUUID(),
})) || [];

const response = await fetch("/api/orders/update-status", {
method: "POST",
headers: { "Content-Type": "application/json" },
Expand Down
1 change: 1 addition & 0 deletions src/type/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type DeliveryTrackingResponse = {
};

export type TrackingResponseEvent = {
_key: string;
node: {
status: {
code: string;
Expand Down

0 comments on commit 7c5c3be

Please sign in to comment.