This commit is contained in:
g
2025-02-07 05:22:21 +00:00
parent f19797e752
commit 3205bb1a6b
11 changed files with 1021 additions and 432 deletions

View File

@@ -21,17 +21,7 @@ import {
updateShippingMethod,
} from "@/lib/shippingHelper";
interface ShippingMethod {
_id?: string; // Required after fetching
name: string;
price: number;
}
interface ShippingData {
_id?: string; // Optional for new entry
name: string;
price: number;
}
import { ShippingMethod, ShippingData } from "@/lib/types";
import { ShippingTable } from "@/components/shipping-table"
@@ -50,10 +40,14 @@ export default function ShippingPage() {
try {
const authToken = document.cookie.split("Authorization=")[1];
const fetchedMethods: ShippingMethod[] = await fetchShippingMethods(authToken);
setShippingMethods(
fetchedMethods.filter((method) => method._id)
);
// Ensure `_id` is always a string
const sanitizedMethods: ShippingMethod[] = fetchedMethods.map((method) => ({
...method,
_id: method._id ?? "", // Default to empty string if undefined
}));
setShippingMethods(sanitizedMethods);
} catch (error) {
console.error("Error loading shipping options:", error);
} finally {
@@ -114,7 +108,10 @@ export default function ShippingPage() {
};
const handleEditShipping = (shipping: ShippingMethod) => {
setNewShipping({ ...shipping, _id: shipping._id ?? "" }); // Ensure _id is always a string
setNewShipping({
...shipping,
_id: shipping._id ?? "", // ✅ Ensure _id is always a string
});
setEditing(true);
setModalOpen(true);
};