import React, { useState, useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { fetchAccounts } from '../store/reducers/accountsSlice'; import { fetchLinkedInAccounts, deleteLinkedInAccount, setPrimaryLinkedInAccount, clearLinkedInError } from '../store/reducers/linkedinAccountsSlice'; import LinkedInAccountsManager from '../components/LinkedInAccount/LinkedInAccountsManager'; import { testApiStructure, testServiceBehavior } from '../debug/testApi'; const Accounts = () => { const dispatch = useDispatch(); const { items: accounts, loading, error } = useSelector(state => state.accounts); const { linkedinAccounts, loading: linkedinLoading, error: linkedinError } = useSelector(state => state.linkedinAccounts); useEffect(() => { // Fetch accounts from the main accounts slice dispatch(fetchAccounts()); // Also fetch LinkedIn accounts for compatibility dispatch(fetchLinkedInAccounts()); dispatch(clearLinkedInError()); // Run API tests testApiStructure(); testServiceBehavior(); }, [dispatch]); return (
{/* Header Section */}

Account Management

Manage your social media accounts and connections for seamless content distribution

{/* Stats Cards */}

Total Accounts

{accounts.length}

Active

{accounts.filter(account => account.token).length}

Primary

{accounts.filter(account => account.is_primary).length}

Connected

{accounts.length > 0 ? Math.round((accounts.filter(account => account.token).length / accounts.length) * 100) : 0}%

{/* Error Display */} {(error || linkedinError) && (

{error || linkedinError}

)}
0 ? accounts : linkedinAccounts} loading={loading || linkedinLoading} />
); }; export default Accounts;