Update page.tsx

This commit is contained in:
NotII
2025-03-07 01:44:03 +00:00
parent cde061c5df
commit a56bb7891e

View File

@@ -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`,
{
// Use clientFetch which handles API URL and auth token automatically
const response = await clientFetch(`/orders/${orderId}/status`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
},
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`,
{
// Use clientFetch which handles API URL and auth token automatically
const response = await clientFetch(`/orders/${orderId}/status`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
},
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`,
{
// Use clientFetch which handles API URL and auth token automatically
const response = await clientFetch(`/orders/${orderId}/status`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify({ status: "cancelled" }),
}
);
});
if (response && response.message === "Order status updated successfully") {
setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "cancelled" } : null);