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