Update page.tsx
This commit is contained in:
@@ -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",
|
body: JSON.stringify({ status: "shipped" }),
|
||||||
headers: {
|
});
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
},
|
|
||||||
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",
|
body: JSON.stringify({ status: "acknowledged" }),
|
||||||
headers: {
|
});
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
},
|
|
||||||
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",
|
||||||
{
|
body: JSON.stringify({ status: "cancelled" }),
|
||||||
method: "PUT",
|
});
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
},
|
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user