Parallelize vendor and store fetch in NewChatForm

Updated the data fetching logic to retrieve vendor profile and store information concurrently using Promise.all, improving performance and reducing wait time in the NewChatForm component.
This commit is contained in:
g
2026-01-07 13:02:12 +00:00
parent f17d623570
commit ed229c5dd6

View File

@@ -136,8 +136,11 @@ export default function NewChatForm() {
} }
try { try {
// Get vendor profile first // Fetch vendor profile and store in parallel
const vendorResponse = await authAxios.get("/auth/me"); const [vendorResponse, storeResponse] = await Promise.all([
authAxios.get("/auth/me"),
authAxios.get("/storefront"),
]);
// Extract vendor ID properly // Extract vendor ID properly
const vendorId = vendorResponse.data.vendor?._id; const vendorId = vendorResponse.data.vendor?._id;
@@ -151,9 +154,6 @@ export default function NewChatForm() {
return; return;
} }
// Fetch store
const storeResponse = await authAxios.get(`/storefront`);
// Handle both array and single object responses // Handle both array and single object responses
if (Array.isArray(storeResponse.data)) { if (Array.isArray(storeResponse.data)) {
setVendorStores(storeResponse.data); setVendorStores(storeResponse.data);