hmm
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user