import { useEffect, useState } from 'react'; import Upload from './Upload'; import Chat from './Chat'; const storedToken = localStorage.getItem('token'); const Opportunities = () => { const [token, setToken] = useState(storedToken); const [isPopupOpen, setIsPopupOpen] = useState(false); //form popup const [opportunities, setOpportunities] = useState([]); 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 => { /*if (!data.success) { handleLogout(); return }*/ console.log('data*******', data, !data.records || data.records.length === 0) if (!data.records || data.records.length === 0) { setIsPopupOpen(true); } else { console.log('data.records*******', data.records) setOpportunities(data.records); } setToken(storedToken); }) console.log('storedToken', storedToken) }, []) const handleLogout = () => { localStorage.removeItem('token'); location = '/' }; return ( <> setIsPopupOpen(false)} token={token} title="No Opportunities">

No opportunities found. Please upload a file to get started.

Opportunities

{Object.keys(opportunities[0] || []).map((e, index) => )} {opportunities.map((opportunity, id) => ( {Object.keys(opportunity).map((key, index) => ( ))} ))}
{e}
{opportunity[key]}
) } const Popup = ({ isOpen, onClose, title, children, token }) => { const validate = () => { //add validation of data window.location.reload(); } if (!isOpen) return null; return (
{/* Overlay */}
{/* Popup Content */}
{/* Header */}

{title}

{/* Body */}
{children}
); }; export default Opportunities;