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