'use client';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import Link from 'next/link';
import { format } from 'date-fns';
export default function FilingsPage() {
const { data: session, status } = useSession();
const router = useRouter();
const [filings, setFilings] = useState([]);
const [loading, setLoading] = useState(true);
const [searchTicker, setSearchTicker] = useState('');
useEffect(() => {
if (status === 'unauthenticated') {
router.push('/auth/signin');
return;
}
if (session?.user) {
fetchFilings();
}
}, [session, status, router]);
const fetchFilings = async (ticker?: string) => {
setLoading(true);
try {
const url = ticker
? `${process.env.NEXT_PUBLIC_API_URL}/api/filings/${ticker}`
: `${process.env.NEXT_PUBLIC_API_URL}/api/filings`;
const response = await fetch(url);
const data = await response.json();
setFilings(data);
} catch (error) {
console.error('Error fetching filings:', error);
} finally {
setLoading(false);
}
};
const handleSearch = (e: React.FormEvent) => {
e.preventDefault();
fetchFilings(searchTicker || undefined);
};
const handleRefresh = async (ticker: string) => {
try {
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/filings/refresh/${ticker}`, {
method: 'POST'
});
fetchFilings(ticker);
} catch (error) {
console.error('Error refreshing filings:', error);
}
};
const getFilingTypeColor = (type: string) => {
switch (type) {
case '10-K': return 'bg-blue-500/20 text-blue-400 border-blue-500/30';
case '10-Q': return 'bg-green-500/20 text-green-400 border-green-500/30';
case '8-K': return 'bg-purple-500/20 text-purple-400 border-purple-500/30';
default: return 'bg-slate-500/20 text-slate-400 border-slate-500/30';
}
};
if (loading) {
return
Loading...
;
}
return (
SEC Filings
+ Add to Watchlist
{filings.length > 0 ? (
| Ticker |
Company |
Type |
Filing Date |
Actions |
{filings.map((filing: any) => (
| {filing.ticker} |
{filing.company_name} |
{filing.filing_type}
|
{format(new Date(filing.filing_date), 'MMM dd, yyyy')}
|
|
))}
) : (
No filings found
Add stocks to your watchlist to track their SEC filings
)}
);
}