changed order
This commit is contained in:
@@ -5,45 +5,23 @@ export const cartApi = baseApi.injectEndpoints({
|
||||
getCart: builder.query({
|
||||
query: () => `/carts`,
|
||||
providesTags: ["cartItems"],
|
||||
pollingInterval: 5000,
|
||||
refetchOnMountOrArgChange: true,
|
||||
pollingInterval: 0,
|
||||
refetchOnMountOrArgChange: 30,
|
||||
refetchOnFocus: false,
|
||||
refetchOnReconnect: true,
|
||||
refetchOnReconnect: false,
|
||||
transformResponse: (response) => {
|
||||
if (
|
||||
typeof response === "string" &&
|
||||
(response.trim().startsWith("<!DOCTYPE") ||
|
||||
response.trim().startsWith("<html"))
|
||||
) {
|
||||
console.error(
|
||||
"Received HTML response instead of JSON:",
|
||||
response.substring(0, 100)
|
||||
);
|
||||
return {
|
||||
message: "error",
|
||||
data: [],
|
||||
errorDetails:
|
||||
"Server returned HTML instead of JSON. The server might be down or experiencing issues.",
|
||||
};
|
||||
}
|
||||
if (typeof response === "object") {
|
||||
if (response.data) {
|
||||
return response;
|
||||
}
|
||||
return { message: "success", data: [] };
|
||||
if (typeof response === "string" &&
|
||||
(response.trim().startsWith("<!DOCTYPE") ||
|
||||
response.trim().startsWith("<html"))) {
|
||||
return { message: "error", data: {} };
|
||||
}
|
||||
|
||||
if (typeof response === "string") {
|
||||
try {
|
||||
const parsed = JSON.parse(response);
|
||||
return parsed;
|
||||
} catch (error) {
|
||||
console.error("Failed to parse response:", error);
|
||||
return { message: "error", data: [] };
|
||||
}
|
||||
if (typeof response === "object" && response.data) {
|
||||
// DON'T CONVERT - Keep the grouped object structure
|
||||
return response;
|
||||
}
|
||||
|
||||
return { message: "unknown", data: [] };
|
||||
return { message: "success", data: {} };
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -199,4 +177,4 @@ export const {
|
||||
useRemoveFromCartMutation,
|
||||
useUpdateCartItemMutation,
|
||||
useCleanCartMutation,
|
||||
} = cartApi;
|
||||
} = cartApi;
|
||||
@@ -12,17 +12,31 @@ export const orderApi = baseApi.injectEndpoints({
|
||||
transformResponse: (response) => response.data || null,
|
||||
}),
|
||||
|
||||
placeOrder: builder.mutation({
|
||||
query: (orderDetails) => {
|
||||
orderDetails.shipping_method = 'standart';
|
||||
orderDetails.delivery_time = '13:00 - 18:00';
|
||||
orderDetails.region = 'ag';
|
||||
orderDetails.payment_type_id = 3;
|
||||
placeOrder: builder.mutation({
|
||||
query: (orderDetails) => {
|
||||
orderDetails.shipping_method = 'standart';
|
||||
orderDetails.delivery_time = '13:00 - 18:00';
|
||||
orderDetails.region = 'ag';
|
||||
// orderDetails.payment_type_id = 3;
|
||||
|
||||
const formData = new URLSearchParams();
|
||||
|
||||
Object.keys(orderDetails).forEach(key => {
|
||||
if (key === 'product_ids' && Array.isArray(orderDetails[key])) {
|
||||
|
||||
orderDetails[key].forEach(id => {
|
||||
formData.append('product_ids[]', id);
|
||||
});
|
||||
} else {
|
||||
formData.append(key, orderDetails[key]);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
url: "/orders",
|
||||
method: "POST",
|
||||
body: new URLSearchParams(orderDetails),
|
||||
body: formData,
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
|
||||
Reference in New Issue
Block a user