-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from New-Syatte/17deliveryTracking
17delivery tracking
- Loading branch information
Showing
23 changed files
with
540 additions
and
3,769 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
76 changes: 76 additions & 0 deletions
76
src/app/(order)/order/order-history/OrderHistoryClient.tsx
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,76 @@ | ||
"use client"; | ||
import StatusProgress from "./StatusProgress"; | ||
import PeriodSelector from "@/layouts/periodSelector/PeriodSelector"; | ||
import OrderList from "./OrderList"; | ||
import { getOrders, updateOrderStatus } from "@/services/sanity/orders"; | ||
import useSWR from "swr"; | ||
import { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { STORE_ORDER, selectOrders } from "@/redux/slice/orderSlice"; | ||
import { Order } from "@/model/order"; | ||
import { TrackingResponseEvent } from "@/model/order"; | ||
|
||
interface OrderHistoryClientProps { | ||
userEmail: string; | ||
} | ||
|
||
const OrderHistoryClient = ({ userEmail }: OrderHistoryClientProps) => { | ||
const { | ||
data: orders, | ||
error, | ||
mutate, | ||
} = useSWR(["orders", userEmail], () => getOrders(userEmail)); | ||
|
||
const dispatch = useDispatch(); | ||
const reduxOrders = useSelector(selectOrders); | ||
useEffect(() => { | ||
if (reduxOrders && orders) { | ||
reduxOrders.forEach(reduxOrder => { | ||
const matchedOrder = orders.find( | ||
(order: Order) => order._id === reduxOrder._id, | ||
); | ||
if (matchedOrder) { | ||
if ( | ||
matchedOrder.status !== reduxOrder.orderStatus && | ||
reduxOrder.shippingInfo.events | ||
) { | ||
(async () => { | ||
await updateOrderStatus( | ||
matchedOrder._id, | ||
reduxOrder.orderStatus, | ||
reduxOrder.shippingInfo.events as TrackingResponseEvent[], | ||
); | ||
console.log(matchedOrder, "updated"); | ||
// update된 orders를 mutate로 캐시에 저장. | ||
mutate(); | ||
})(); | ||
} | ||
} | ||
}); | ||
} | ||
}, [reduxOrders]); | ||
|
||
useEffect(() => { | ||
if (orders) { | ||
dispatch(STORE_ORDER(orders)); | ||
} | ||
}, [orders]); | ||
|
||
if (error) return <div>Failed to load orders</div>; | ||
if (!orders) return <div>Loading...</div>; | ||
|
||
return ( | ||
<div className="w-full flex flex-col gap-y-40"> | ||
<StatusProgress /> | ||
<div> | ||
<div className="flex justify-between mb-[30px]"> | ||
<h2 className="text-xl font-semibold">주문 내용</h2> | ||
<PeriodSelector /> | ||
</div> | ||
<OrderList /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OrderHistoryClient; |
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
Oops, something went wrong.