fixed order and cart req
This commit is contained in:
@@ -128,6 +128,8 @@ export default function CartPage() {
|
||||
);
|
||||
if (!selectedProvinceData) return;
|
||||
|
||||
const product_ids = cartItems.map((item) => item.product.id);
|
||||
|
||||
createOrder(
|
||||
{
|
||||
customer_name: `${name} ${lastName}`.trim(),
|
||||
@@ -137,6 +139,7 @@ export default function CartPage() {
|
||||
payment_type_id: paymentType.id,
|
||||
region: selectedRegion,
|
||||
notes: note || undefined,
|
||||
product_ids,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -40,21 +40,34 @@ function transformCartResponse(response: any): CartResponse {
|
||||
(response.trim().startsWith("<!DOCTYPE") ||
|
||||
response.trim().startsWith("<html"))
|
||||
) {
|
||||
return {
|
||||
message: "error",
|
||||
data: [],
|
||||
errorDetails: "Server returned HTML instead of JSON.",
|
||||
};
|
||||
return { message: "error", data: [], errorDetails: "Server returned HTML instead of JSON." };
|
||||
}
|
||||
|
||||
if (typeof response === "object") {
|
||||
if (response.data) return response;
|
||||
return { message: "success", data: [] };
|
||||
const normalize = (raw: any): CartItem[] => {
|
||||
if (Array.isArray(raw)) return raw;
|
||||
|
||||
// GET response: data = { tmpost: [...], ... } — merge all channel arrays
|
||||
if (typeof raw === "object" && raw !== null) {
|
||||
return Object.values(raw).flat() as CartItem[];
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
if (typeof response === "object" && response !== null) {
|
||||
return {
|
||||
message: response.message || "success",
|
||||
data: normalize(response.data),
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof response === "string") {
|
||||
try {
|
||||
return JSON.parse(response);
|
||||
const parsed = JSON.parse(response);
|
||||
return {
|
||||
message: parsed.message || "success",
|
||||
data: normalize(parsed.data),
|
||||
};
|
||||
} catch {
|
||||
return { message: "error", data: [] };
|
||||
}
|
||||
@@ -471,6 +484,7 @@ export function useCreateOrder() {
|
||||
delivery_at?: string;
|
||||
region: string;
|
||||
notes?: string;
|
||||
product_ids: number[];
|
||||
}) => {
|
||||
const response = await apiClient.post("/orders", payload);
|
||||
return response.data;
|
||||
|
||||
@@ -12,7 +12,7 @@ const nextConfig: NextConfig = {
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: "https",
|
||||
hostname: "hyzmat.app",
|
||||
hostname: "smartelektronika.com",
|
||||
// port: "8080",
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user