From a56bb7891e6577307f5507427da3d2ed68905118 Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Fri, 7 Mar 2025 01:44:03 +0000 Subject: [PATCH] Update page.tsx --- app/dashboard/orders/[id]/page.tsx | 54 ++++++++++-------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/app/dashboard/orders/[id]/page.tsx b/app/dashboard/orders/[id]/page.tsx index 77ad130..c6d090a 100644 --- a/app/dashboard/orders/[id]/page.tsx +++ b/app/dashboard/orders/[id]/page.tsx @@ -202,18 +202,12 @@ export default function OrderDetailsPage() { const handleMarkAsShipped = async () => { try { setIsMarkingShipped(true); - const authToken = document.cookie.split("Authorization=")[1]; - const response = await fetchData( - `${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`, - { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${authToken}`, - }, - body: JSON.stringify({ status: "shipped" }), - } - ); + + // Use clientFetch which handles API URL and auth token automatically + const response = await clientFetch(`/orders/${orderId}/status`, { + method: "PUT", + body: JSON.stringify({ status: "shipped" }), + }); if (response && response.message === "Order status updated successfully") { setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "shipped" } : null); @@ -232,18 +226,12 @@ export default function OrderDetailsPage() { const handleMarkAsAcknowledged = async () => { try { setIsAcknowledging(true); - const authToken = document.cookie.split("Authorization=")[1]; - const response = await fetchData( - `${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`, - { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${authToken}`, - }, - body: JSON.stringify({ status: "acknowledged" }), - } - ); + + // Use clientFetch which handles API URL and auth token automatically + const response = await clientFetch(`/orders/${orderId}/status`, { + method: "PUT", + body: JSON.stringify({ status: "acknowledged" }), + }); if (response && response.message === "Order status updated successfully") { setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "acknowledged" } : null); @@ -290,20 +278,12 @@ export default function OrderDetailsPage() { const handleCancelOrder = async () => { try { setIsCancelling(true); - const authToken = document.cookie.split("Authorization=")[1]; - // Update to match the correct API endpoint structure - const response = await fetchData( - `${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`, - { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${authToken}`, - }, - body: JSON.stringify({ status: "cancelled" }), - } - ); + // Use clientFetch which handles API URL and auth token automatically + const response = await clientFetch(`/orders/${orderId}/status`, { + method: "PUT", + body: JSON.stringify({ status: "cancelled" }), + }); if (response && response.message === "Order status updated successfully") { setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "cancelled" } : null);