import { useEffect, useState } from 'react'; import Upload from './Upload'; import ChatApi from './ChatApi'; import TwoColumnLayout from './layout/TwoColumn'; import OpportunityForm from './OpportunityForm'; import { Button } from './ui/button'; const Opportunities = () => { const [opportunities, setOpportunities] = useState([]); const [selectedOpportunity, setSelectedOpportunity] = useState(null); const [token, setToken] = useState(null); const [research, setResearch] = useState(null); useEffect(() => { const storedToken = localStorage.getItem('token'); console.log('storedToken*******', storedToken) fetch('/api/opportunities', { method: 'GET', headers: { 'Authorization': `Bearer ${storedToken}`, 'Content-Type': 'application/json' } }).then(response => response.json()) .then(data => { console.log('data.records*******', data.success && data.data.records?.length > 0) if (data.success && data.data.records?.length > 0) { setOpportunities(data.data.records); } setToken(storedToken); }) console.log('storedToken', storedToken) }, []) const handleLogout = () => { localStorage.removeItem('token'); location = '/' }; const customerResearch = (opportunity) => { fetch('/api/customer_insights', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ message: opportunity['opportunityName'] }) }).then(response => response.json()) .then(data => { console.log('data*******', data) }) } return ( <>
{opportunities.map((opportunity, id) => ( ))}
{Object.keys(selectedOpportunity || {}).map((key, index) => (
{key}: {selectedOpportunity[key]}
))} {research &&
{research}
}
{/*

Opportunities

{Object.keys(opportunities[0] || []).map((e, index) => )} {opportunities.map((opportunity, id) => ( {Object.keys(opportunity).map((key, index) => ( ))} ))}
{e}
{opportunity[key]}
*/} ) } export default Opportunities;