fix
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { getCookie } from "@/lib/client-utils";
|
||||
import { clientFetch } from "@/lib/client-utils";
|
||||
import axios from "axios";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
interface Order {
|
||||
@@ -62,13 +62,27 @@ export default function BuyerOrderInfo({ buyerId, chatId }: BuyerOrderInfoProps)
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
// Use clientFetch instead of direct axios calls
|
||||
// This ensures the request goes through Next.js API rewrites
|
||||
const response = await clientFetch(`/chats/${chatId}/orders?limit=10`);
|
||||
const authToken = getCookie("Authorization");
|
||||
|
||||
if (response && response.orders) {
|
||||
setOrders(response.orders);
|
||||
setHasOrders(response.orders.length > 0);
|
||||
if (!authToken) {
|
||||
isFetchingRef.current = false;
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const authAxios = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`
|
||||
}
|
||||
});
|
||||
|
||||
// Use the new endpoint that works with sub-users
|
||||
const response = await authAxios.get(`/chats/${chatId}/orders?limit=10`); // Limit to fewer orders for faster response
|
||||
|
||||
if (response.data && response.data.orders) {
|
||||
setOrders(response.data.orders);
|
||||
setHasOrders(response.data.orders.length > 0);
|
||||
} else {
|
||||
setHasOrders(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user