Update page.tsx
This commit is contained in:
@@ -144,7 +144,7 @@ export default function OrderDetailsPage() {
|
||||
try {
|
||||
const authToken = document.cookie.split("Authorization=")[1];
|
||||
const response = await fetchData(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}`,
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
@@ -158,15 +158,13 @@ export default function OrderDetailsPage() {
|
||||
if (response && response.message === "Order status updated successfully") {
|
||||
setIsPaid(true); // Update isPaid state
|
||||
setOrder((prevOrder) => (prevOrder ? { ...prevOrder, status: "paid" } : null)); // Update order status
|
||||
console.log("Order marked as paid successfully.");
|
||||
toast.success("Order marked as paid successfully"); // Use toast for consistency
|
||||
} else {
|
||||
const errorData = await response.json();
|
||||
console.error("Failed to mark order as paid:", errorData.message);
|
||||
alert(`Error: ${errorData.message}`);
|
||||
throw new Error(response.error || "Failed to mark order as paid");
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error("An error occurred while marking the order as paid:", error.message);
|
||||
alert("An unexpected error occurred. Please try again.");
|
||||
console.error("Failed to mark order as paid:", error);
|
||||
toast.error(error.message || "Failed to mark order as paid");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -175,7 +173,7 @@ export default function OrderDetailsPage() {
|
||||
setIsMarkingShipped(true);
|
||||
const authToken = document.cookie.split("Authorization=")[1];
|
||||
const response = await fetchData(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}`,
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
@@ -205,7 +203,7 @@ export default function OrderDetailsPage() {
|
||||
setIsAcknowledging(true);
|
||||
const authToken = document.cookie.split("Authorization=")[1];
|
||||
const response = await fetchData(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}`,
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/orders/${orderId}/status`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user