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