uwu
This commit is contained in:
@@ -24,16 +24,14 @@ export default function NewChatForm() {
|
||||
useEffect(() => {
|
||||
const fetchVendorStores = async () => {
|
||||
try {
|
||||
// Get auth token from cookies
|
||||
const authToken = getCookie("Authorization");
|
||||
|
||||
if (!authToken) {
|
||||
toast.error("You need to be logged in");
|
||||
toast.error("You must be logged in to start a chat");
|
||||
router.push("/auth/login");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up axios with the auth token
|
||||
const authAxios = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL,
|
||||
headers: {
|
||||
@@ -41,16 +39,24 @@ export default function NewChatForm() {
|
||||
}
|
||||
});
|
||||
|
||||
// Get vendor ID from profile
|
||||
const vendorResponse = await authAxios.get('/api/auth/me');
|
||||
const vendorId = vendorResponse.data._id;
|
||||
// Get vendor profile first
|
||||
const vendorResponse = await authAxios.get('/auth/me');
|
||||
|
||||
// Fetch vendor's stores using storefront endpoint
|
||||
const response = await authAxios.get(`/api/storefront`);
|
||||
setVendorStores(response.data);
|
||||
// Extract vendor ID properly
|
||||
const vendorId = vendorResponse.data.vendor?._id;
|
||||
|
||||
if (response.data.length > 0) {
|
||||
setSelectedStore(response.data[0]._id);
|
||||
if (!vendorId) {
|
||||
console.error("Vendor ID not found in profile response:", vendorResponse.data);
|
||||
toast.error("Could not retrieve vendor information");
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch stores
|
||||
const storesResponse = await authAxios.get(`/storefront`);
|
||||
setVendorStores(storesResponse.data);
|
||||
|
||||
if (storesResponse.data.length > 0) {
|
||||
setSelectedStore(storesResponse.data[0]._id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching stores:", error);
|
||||
@@ -59,7 +65,7 @@ export default function NewChatForm() {
|
||||
};
|
||||
|
||||
fetchVendorStores();
|
||||
}, [router]);
|
||||
}, []);
|
||||
|
||||
const handleBackClick = () => {
|
||||
router.push("/dashboard/chats");
|
||||
|
||||
Reference in New Issue
Block a user