This commit is contained in:
g
2025-02-07 21:33:13 +00:00
parent 8900bbcc76
commit 891f57d729
50 changed files with 165 additions and 444 deletions

View File

@@ -1,6 +1,8 @@
import { fetchData } from '@/lib/data-service';
export const fetchShippingMethods = async (authToken: string) => {
try {
const res = await fetch(
const res = await fetchData(
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options`,
{
headers: {
@@ -11,8 +13,10 @@ export const fetchShippingMethods = async (authToken: string) => {
}
);
if (!res.ok) throw new Error("Failed to fetch shipping options");
return await res.json();
console.log("Shipping Methods Response:", res);
if (!res) throw new Error("Failed to fetch shipping options");
return res
} catch (error) {
console.error("Error loading shipping options:", error);
throw error;
@@ -30,7 +34,7 @@ export const addShippingMethod = async (
newShipping: Omit<ShippingMethod, "_id">
): Promise<ShippingMethod[]> => {
try {
const res = await fetch(
const res = await fetchData(
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options`,
{
method: "POST",
@@ -61,7 +65,7 @@ export const addShippingMethod = async (
export const deleteShippingMethod = async (authToken: string, id: string) => {
try {
const res = await fetch(
const res = await fetchData(
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options/${id}`,
{
method: "DELETE",
@@ -71,7 +75,6 @@ export const deleteShippingMethod = async (authToken: string, id: string) => {
);
if (!res.ok) throw new Error("Failed to delete shipping method");
// Since there is no content, just return success status.
return { success: res.status === 204 };
} catch (error) {
console.error("Error deleting shipping method:", error);
@@ -85,7 +88,7 @@ export const updateShippingMethod = async (
updatedShipping: any
) => {
try {
const res = await fetch(
const res = await fetchData(
`${process.env.NEXT_PUBLIC_API_URL}/shipping-options/${id}`,
{
method: "PUT",
@@ -98,10 +101,10 @@ export const updateShippingMethod = async (
}
);
if (!res.ok) throw new Error("Failed to update shipping method");
return await res.json();
if (!res) throw new Error("Failed to update shipping method");
return res
} catch (error) {
console.error("Error updating shipping method:", error);
throw error;
}
};
};