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 () => { const handleMarkAsShipped = async () => {
try { try {
setIsMarkingShipped(true); setIsMarkingShipped(true);
const authToken = document.cookie.split("Authorization=")[1];
const response = await fetchData( // Use clientFetch which handles API URL and auth token automatically
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`, const response = await clientFetch(`/orders/${orderId}/status`, {
{
method: "PUT", method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify({ status: "shipped" }), body: JSON.stringify({ status: "shipped" }),
} });
);
if (response && response.message === "Order status updated successfully") { if (response && response.message === "Order status updated successfully") {
setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "shipped" } : null); setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "shipped" } : null);
@@ -232,18 +226,12 @@ export default function OrderDetailsPage() {
const handleMarkAsAcknowledged = async () => { const handleMarkAsAcknowledged = async () => {
try { try {
setIsAcknowledging(true); setIsAcknowledging(true);
const authToken = document.cookie.split("Authorization=")[1];
const response = await fetchData( // Use clientFetch which handles API URL and auth token automatically
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`, const response = await clientFetch(`/orders/${orderId}/status`, {
{
method: "PUT", method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify({ status: "acknowledged" }), body: JSON.stringify({ status: "acknowledged" }),
} });
);
if (response && response.message === "Order status updated successfully") { if (response && response.message === "Order status updated successfully") {
setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "acknowledged" } : null); setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "acknowledged" } : null);
@@ -290,20 +278,12 @@ export default function OrderDetailsPage() {
const handleCancelOrder = async () => { const handleCancelOrder = async () => {
try { try {
setIsCancelling(true); setIsCancelling(true);
const authToken = document.cookie.split("Authorization=")[1];
// Update to match the correct API endpoint structure // Use clientFetch which handles API URL and auth token automatically
const response = await fetchData( const response = await clientFetch(`/orders/${orderId}/status`, {
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`,
{
method: "PUT", method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify({ status: "cancelled" }), body: JSON.stringify({ status: "cancelled" }),
} });
);
if (response && response.message === "Order status updated successfully") { if (response && response.message === "Order status updated successfully") {
setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "cancelled" } : null); setOrder((prevOrder) => prevOrder ? { ...prevOrder, status: "cancelled" } : null);