Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

fix: restore Instagram labels incorrectly replaced with Camera text in AccountManager

valzorc8d201ddf162
diff --git a/frontend/src/features/accounts/AccountManager.jsx b/frontend/src/features/accounts/AccountManager.jsx
index 423a389..daeb692 100644
--- a/frontend/src/features/accounts/AccountManager.jsx
+++ b/frontend/src/features/accounts/AccountManager.jsx
@@ -1,352 +1,385 @@
import React, { useState } from 'react';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+import { Badge } from '@/components/ui/badge';
+import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
+import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
+import { Alert, AlertDescription } from '@/components/ui/alert';
+import { Separator } from '@/components/ui/separator';
+import { Skeleton } from '@/components/ui/skeleton';
+import { Textarea } from '@/components/ui/textarea';
import {
- Box, Typography, Grid, Button, TextField, Dialog,
- DialogTitle, DialogContent, DialogActions, IconButton, Avatar, Chip,
- LinearProgress, CircularProgress, InputAdornment, Tabs, Tab, Alert,
-} from '@mui/material';
+ Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter,
+} from '@/components/ui/dialog';
import {
- Add, Delete, Refresh, Search, YouTube, People, Visibility, VideoLibrary,
- Link as LinkIcon, CheckCircle, Instagram, Key,
-} from '@mui/icons-material';
+ Plus, Trash2, RefreshCw, Search, Users, CheckCircle2,
+ Tv, Camera, KeyRound, Link2, Info,
+} from 'lucide-react';
import MainCard from '../../components/MainCard';
import { useAppContext } from '../../context/AppContext';
import { api } from '../../services/api';
import { fmtNum, timeAgo } from '../../utils/formatters';
-import { PRIMARY, GREY } from '../../themes/index';
+import { cn } from '@/lib/utils';
export default function AccountManager() {
- const { accounts, showToast, loadAccounts } = useAppContext();
- const [dialogOpen, setDialogOpen] = useState(false);
- const [dialogTab, setDialogTab] = useState(0);
- const [input, setInput] = useState('');
- const [igToken, setIgToken] = useState('');
- const [resolving, setResolving] = useState(false);
- const [resolved, setResolved] = useState(null);
- const [adding, setAdding] = useState(false);
- const [refreshingId, setRefreshingId] = useState(null);
+ const { accounts, showToast, loadAccounts } = useAppContext();
+ const [dialogOpen, setDialogOpen] = useState(false);
+ const [dialogTab, setDialogTab] = useState('youtube');
+ const [input, setInput] = useState('');
+ const [igToken, setIgToken] = useState('');
+ const [resolving, setResolving] = useState(false);
+ const [resolved, setResolved] = useState(null);
+ const [adding, setAdding] = useState(false);
+ const [refreshingId, setRefreshingId] = useState(null);
- const handleResolve = async () => {
- if (!input.trim()) return;
- setResolving(true);
- setResolved(null);
- try {
- const res = await api.resolveChannel(input.trim());
- setResolved(res.data || res);
- } catch (err) {
- showToast('Could not resolve channel: ' + err.message, 'error');
- } finally {
- setResolving(false);
- }
- };
+ const handleResolve = async () => {
+ if (!input.trim()) return;
+ setResolving(true);
+ setResolved(null);
+ try {
+ const res = await api.resolveChannel(input.trim());
+ setResolved(res.data || res);
+ } catch (err) {
+ showToast('Could not resolve channel: ' + err.message, 'error');
+ } finally {
+ setResolving(false);
+ }
+ };
- const handleAdd = async () => {
- if (!input.trim()) return;
- setAdding(true);
- try {
- await api.addAccount(input.trim());
- showToast('Channel added successfully!');
- closeDialog();
- loadAccounts();
- } catch (err) {
- showToast('Failed to add account: ' + err.message, 'error');
- } finally {
- setAdding(false);
- }
- };
+ const handleAdd = async () => {
+ if (!input.trim()) return;
+ setAdding(true);
+ try {
+ await api.addAccount(input.trim());
+ showToast('Channel added successfully!');
+ closeDialog();
+ loadAccounts();
+ } catch (err) {
+ showToast('Failed to add account: ' + err.message, 'error');
+ } finally {
+ setAdding(false);
+ }
+ };
- const handleAddInstagram = async () => {
- if (!igToken.trim()) return;
- setAdding(true);
- try {
- await api.addInstagramAccount(igToken.trim());
- showToast('Instagram account added successfully!');
- closeDialog();
- loadAccounts();
- } catch (err) {
- showToast('Failed to add Instagram account: ' + err.message, 'error');
- } finally {
- setAdding(false);
- }
- };
+ const handleAddInstagram = async () => {
+ if (!igToken.trim()) return;
+ setAdding(true);
+ try {
+ await api.addInstagramAccount(igToken.trim());
+ showToast('Instagram account added successfully!');
+ closeDialog();
+ loadAccounts();
+ } catch (err) {
+ showToast('Failed to add Instagram account: ' + err.message, 'error');
+ } finally {
+ setAdding(false);
+ }
+ };
- const handleDelete = async (id) => {
- try {
- await api.deleteAccount(id);
- showToast('Account removed');
- loadAccounts();
- } catch (err) {
- showToast('Failed to delete: ' + err.message, 'error');
- }
- };
+ const handleDelete = async (id) => {
+ try {
+ await api.deleteAccount(id);
+ showToast('Account removed');
+ loadAccounts();
+ } catch (err) {
+ showToast('Failed to delete: ' + err.message, 'error');
+ }
+ };
- const handleRefreshOne = async (id) => {
- setRefreshingId(id);
- try {
- await api.refreshAccount(id);
- showToast('Account refreshed');
- loadAccounts();
- } catch (err) {
- showToast('Refresh failed: ' + err.message, 'error');
- } finally {
- setRefreshingId(null);
- }
- };
+ const handleRefreshOne = async (id) => {
+ setRefreshingId(id);
+ try {
+ await api.refreshAccount(id);
+ showToast('Account refreshed');
+ loadAccounts();
+ } catch (err) {
+ showToast('Refresh failed: ' + err.message, 'error');
+ } finally {
+ setRefreshingId(null);
+ }
+ };
- const handleRefreshAll = async () => {
- setRefreshingId('all');
- try {
- await api.refreshAll();
- showToast('All accounts refreshed');
- loadAccounts();
- } catch (err) {
- showToast('Refresh all failed: ' + err.message, 'error');
- } finally {
- setRefreshingId(null);
- }
- };
+ const handleRefreshAll = async () => {
+ setRefreshingId('all');
+ try {
+ await api.refreshAll();
+ showToast('All accounts refreshed');
+ loadAccounts();
+ } catch (err) {
+ showToast('Refresh all failed: ' + err.message, 'error');
+ } finally {
+ setRefreshingId(null);
+ }
+ };
- const closeDialog = () => {
- setDialogOpen(false);
- setResolved(null);
- setInput('');
- setIgToken('');
- };
+ const closeDialog = () => {
+ setDialogOpen(false);
+ setResolved(null);
+ setInput('');
+ setIgToken('');
+ };
- const ytAccounts = accounts.filter(a => a.platform !== 'instagram');
- const igAccounts = accounts.filter(a => a.platform === 'instagram');
+ const ytAccounts = accounts.filter(a => a.platform !== 'instagram');
+ const igAccounts = accounts.filter(a => a.platform === 'instagram');
- return (
- <Box>
- {/* Header */}
- <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 3, flexWrap: 'wrap', gap: 2 }}>
- <Box>
- <Typography variant="h4">Manage Accounts</Typography>
- <Typography variant="body2" color="text.secondary" sx={{ mt: 0.25 }}>
- {ytAccounts.length} YouTube channels · {igAccounts.length} Instagram accounts
- </Typography>
- </Box>
- <Box sx={{ display: 'flex', gap: 1 }}>
- <Button
- variant="outlined"
- startIcon={<Refresh />}
- onClick={handleRefreshAll}
- disabled={refreshingId === 'all'}
- size="small"
- >
- {refreshingId === 'all' ? 'Refreshing…' : 'Refresh All'}
- </Button>
- <Button variant="contained" startIcon={<Add />} onClick={() => setDialogOpen(true)} size="small">
- Add Account
- </Button>
- </Box>
- </Box>
+ return (
+ <div className="space-y-6">
+ {/* Header */}
+ <div className="flex items-center justify-between gap-4 flex-wrap">
+ <div>
+ <h1 className="text-2xl font-bold tracking-tight">Manage Accounts</h1>
+ <p className="text-sm text-muted-foreground mt-0.5">
+ {ytAccounts.length} YouTube channels · {igAccounts.length} Instagram accounts
+ </p>
+ </div>
+ <div className="flex gap-2">
+ <Button variant="outline" size="sm" onClick={handleRefreshAll} disabled={refreshingId === 'all'} className="gap-2">
+ <RefreshCw className={cn('h-3.5 w-3.5', refreshingId === 'all' && 'animate-spin')} />
+ {refreshingId === 'all' ? 'Refreshing…' : 'Refresh All'}
+ </Button>
+ <Button size="sm" onClick={() => setDialogOpen(true)} className="gap-2">
+ <Plus className="h-3.5 w-3.5" />
+ Add Account
+ </Button>
+ </div>
+ </div>
- {accounts.length === 0 ? (
- <MainCard>
- <Box sx={{ textAlign: 'center', py: 6 }}>
- <Box sx={{ width: 64, height: 64, borderRadius: '50%', bgcolor: PRIMARY.lighter, display: 'flex', alignItems: 'center', justifyContent: 'center', mx: 'auto', mb: 2 }}>
- <People sx={{ fontSize: 32, color: PRIMARY.main }} />
- </Box>
- <Typography variant="h5" sx={{ mb: 1 }}>No Accounts Added</Typography>
- <Typography variant="body2" color="text.secondary" sx={{ mb: 3, maxWidth: 360, mx: 'auto' }}>
- Add a YouTube channel or Instagram account to start tracking analytics.
- </Typography>
- <Button variant="contained" startIcon={<Add />} onClick={() => setDialogOpen(true)}>
- Add Your First Account
- </Button>
- </Box>
- </MainCard>
- ) : (
- <>
- {/* YouTube */}
- {ytAccounts.length > 0 && (
- <Box sx={{ mb: 4 }}>
- <Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5, mb: 2 }}>
- <YouTube sx={{ color: '#ff4d4f', fontSize: 22 }} />
- <Typography variant="h5">YouTube Channels</Typography>
- <Chip label={ytAccounts.length} size="small" sx={{ bgcolor: '#fff1f0', color: '#ff4d4f', fontWeight: 600, fontSize: '0.72rem', height: 20 }} />
- </Box>
- <Grid container spacing={2.5}>
- {ytAccounts.map(acct => (
- <Grid size={{ xs: 12, sm: 6, md: 4 }} key={acct.id}>
- <MainCard sx={{ transition: 'box-shadow 0.2s', '&:hover': { boxShadow: '0 4px 16px rgba(0,0,0,0.1)' } }}>
- <Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5, mb: 2 }}>
- <Avatar src={acct.thumbnail || acct.thumbnails?.default || acct.thumbnailUrl} sx={{ width: 48, height: 48, bgcolor: '#fff1f0' }}>
- <YouTube sx={{ color: '#ff4d4f' }} />
- </Avatar>
- <Box sx={{ flex: 1, minWidth: 0 }}>
- <Typography variant="subtitle1" noWrap sx={{ fontWeight: 600 }}>{acct.title || acct.channelId}</Typography>
- {acct.customUrl && <Typography variant="caption" color="text.secondary">{acct.customUrl}</Typography>}
- </Box>
- </Box>
- <Grid container spacing={1} sx={{ mb: 2 }}>
- {[
- { label: 'Subscribers', value: fmtNum(acct.subscriberCount), bg: '#fff1f0' },
- { label: 'Views', value: fmtNum(acct.viewCount), bg: '#e6f4ff' },
- { label: 'Videos', value: fmtNum(acct.videoCount), bg: '#f6ffed' },
- ].map(m => (
- <Grid size={4} key={m.label}>
- <Box sx={{ textAlign: 'center', p: 1, borderRadius: 1.5, bgcolor: m.bg }}>
- <Typography variant="caption" color="text.secondary" sx={{ display: 'block', fontSize: '0.65rem' }}>{m.label}</Typography>
- <Typography variant="body2" sx={{ fontWeight: 700 }}>{m.value}</Typography>
- </Box>
- </Grid>
- ))}
- </Grid>
- {acct.lastUpdated && (
- <Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1.5 }}>
- Updated {timeAgo(acct.lastUpdated)}
- </Typography>
- )}
- <Box sx={{ display: 'flex', gap: 1 }}>
- <Button size="small" variant="outlined" startIcon={<Refresh />} fullWidth
- onClick={() => handleRefreshOne(acct.id)} disabled={refreshingId === acct.id}>
- {refreshingId === acct.id ? 'Refreshing…' : 'Refresh'}
- </Button>
- <IconButton size="small" onClick={() => handleDelete(acct.id)}
- sx={{ color: 'error.main', border: `1px solid`, borderColor: 'error.light', borderRadius: 1.5, px: 1 }}>
- <Delete sx={{ fontSize: 16 }} />
- </IconButton>
- </Box>
- </MainCard>
- </Grid>
- ))}
- </Grid>
- </Box>
- )}
+ {accounts.length === 0 ? (
+ <MainCard>
+ <div className="flex flex-col items-center text-center py-12 gap-4">
+ <div className="h-14 w-14 rounded-full bg-primary/10 flex items-center justify-center">
+ <Users className="h-7 w-7 text-primary" />
+ </div>
+ <div>
+ <h3 className="text-lg font-semibold">No Accounts Added</h3>
+ <p className="text-sm text-muted-foreground mt-1 max-w-sm">
+ Add a YouTube channel or Instagram account to start tracking analytics.
+ </p>
+ </div>
+ <Button onClick={() => setDialogOpen(true)} className="gap-2">
+ <Plus className="h-4 w-4" /> Add Your First Account
+ </Button>
+ </div>
+ </MainCard>
+ ) : (
+ <div className="space-y-8">
+ {/* YouTube */}
+ {ytAccounts.length > 0 && (
+ <div>
+ <div className="flex items-center gap-2 mb-3">
+ <Tv className="h-5 w-5 text-red-500" />
+ <h2 className="text-base font-semibold">YouTube Channels</h2>
+ <Badge variant="outline" className="border-red-200 bg-red-50 text-red-600 text-xs">{ytAccounts.length}</Badge>
+ </div>
+ <div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4">
+ {ytAccounts.map(acct => (
+ <AccountCard
+ key={acct.id}
+ acct={acct}
+ isIG={false}
+ metrics={[
+ { label: 'Subscribers', value: fmtNum(acct.subscriberCount), className: 'bg-red-50 text-red-700' },
+ { label: 'Views', value: fmtNum(acct.viewCount), className: 'bg-blue-50 text-blue-700' },
+ { label: 'Videos', value: fmtNum(acct.videoCount), className: 'bg-green-50 text-green-700' },
+ ]}
+ refreshingId={refreshingId}
+ onRefresh={handleRefreshOne}
+ onDelete={handleDelete}
+ />
+ ))}
+ </div>
+ </div>
+ )}
+
+ {/* Instagram */}
+ {igAccounts.length > 0 && (
+ <div>
+ <div className="flex items-center gap-2 mb-3">
+ <Camera className="h-5 w-5 text-pink-500" />
+ <h2 className="text-base font-semibold">Instagram Accounts</h2>
+ <Badge variant="outline" className="border-pink-200 bg-pink-50 text-pink-600 text-xs">{igAccounts.length}</Badge>
+ </div>
+ <div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4">
+ {igAccounts.map(acct => (
+ <AccountCard
+ key={acct.id}
+ acct={acct}
+ isIG={true}
+ metrics={[
+ { label: 'Followers', value: fmtNum(acct.followersCount), className: 'bg-pink-50 text-pink-700' },
+ { label: 'Following', value: fmtNum(acct.followsCount), className: 'bg-purple-50 text-purple-700' },
+ { label: 'Posts', value: fmtNum(acct.mediaCount), className: 'bg-green-50 text-green-700' },
+ ]}
+ refreshingId={refreshingId}
+ onRefresh={handleRefreshOne}
+ onDelete={handleDelete}
+ />
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+ )}
+
+ {/* Add Account Dialog */}
+ <Dialog open={dialogOpen} onOpenChange={(open) => { if (!open) closeDialog(); }}>
+ <DialogContent className="sm:max-w-md">
+ <DialogHeader>
+ <DialogTitle>Add Account</DialogTitle>
+ <DialogDescription>Connect a YouTube channel or Instagram account.</DialogDescription>
+ </DialogHeader>
- {/* Instagram */}
- {igAccounts.length > 0 && (
- <Box>
- <Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5, mb: 2 }}>
- <Instagram sx={{ color: '#E1306C', fontSize: 22 }} />
- <Typography variant="h5">Instagram Accounts</Typography>
- <Chip label={igAccounts.length} size="small" sx={{ bgcolor: '#fff0f6', color: '#c41d7f', fontWeight: 600, fontSize: '0.72rem', height: 20 }} />
- </Box>
- <Grid container spacing={2.5}>
- {igAccounts.map(acct => (
- <Grid size={{ xs: 12, sm: 6, md: 4 }} key={acct.id}>
- <MainCard sx={{ transition: 'box-shadow 0.2s', '&:hover': { boxShadow: '0 4px 16px rgba(0,0,0,0.1)' } }}>
- <Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5, mb: 2 }}>
- <Avatar src={acct.profilePictureUrl || acct.thumbnail} sx={{ width: 48, height: 48, bgcolor: '#fff0f6' }}>
- <Instagram sx={{ color: '#E1306C' }} />
- </Avatar>
- <Box sx={{ flex: 1, minWidth: 0 }}>
- <Typography variant="subtitle1" noWrap sx={{ fontWeight: 600 }}>{acct.title || acct.username}</Typography>
- {(acct.username || acct.igUsername) && (
- <Typography variant="caption" color="text.secondary">@{acct.username || acct.igUsername}</Typography>
- )}
- </Box>
- </Box>
- <Grid container spacing={1} sx={{ mb: 2 }}>
- {[
- { label: 'Followers', value: fmtNum(acct.followersCount), bg: '#fff0f6' },
- { label: 'Following', value: fmtNum(acct.followsCount), bg: '#f9f0ff' },
- { label: 'Posts', value: fmtNum(acct.mediaCount), bg: '#f6ffed' },
- ].map(m => (
- <Grid size={4} key={m.label}>
- <Box sx={{ textAlign: 'center', p: 1, borderRadius: 1.5, bgcolor: m.bg }}>
- <Typography variant="caption" color="text.secondary" sx={{ display: 'block', fontSize: '0.65rem' }}>{m.label}</Typography>
- <Typography variant="body2" sx={{ fontWeight: 700 }}>{m.value}</Typography>
- </Box>
- </Grid>
- ))}
- </Grid>
- {acct.lastUpdated && (
- <Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1.5 }}>
- Updated {timeAgo(acct.lastUpdated)}
- </Typography>
- )}
- <Box sx={{ display: 'flex', gap: 1 }}>
- <Button size="small" variant="outlined" startIcon={<Refresh />} fullWidth
- onClick={() => handleRefreshOne(acct.id)} disabled={refreshingId === acct.id}>
- {refreshingId === acct.id ? 'Refreshing…' : 'Refresh'}
- </Button>
- <IconButton size="small" onClick={() => handleDelete(acct.id)}
- sx={{ color: 'error.main', border: '1px solid', borderColor: 'error.light', borderRadius: 1.5, px: 1 }}>
- <Delete sx={{ fontSize: 16 }} />
- </IconButton>
- </Box>
- </MainCard>
- </Grid>
- ))}
- </Grid>
- </Box>
+ <Tabs value={dialogTab} onValueChange={setDialogTab}>
+ <TabsList className="w-full">
+ <TabsTrigger value="youtube" className="flex-1 gap-1.5">
+ <Tv className="h-3.5 w-3.5" /> YouTube
+ </TabsTrigger>
+ <TabsTrigger value="instagram" className="flex-1 gap-1.5">
+ <Camera className="h-3.5 w-3.5" /> Instagram
+ </TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="youtube" className="space-y-4 mt-4">
+ <p className="text-sm text-muted-foreground">
+ Enter a YouTube channel URL, @handle, or channel ID.
+ </p>
+ <div className="flex gap-2">
+ <div className="relative flex-1">
+ <Link2 className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
+ <Input
+ className="pl-9"
+ value={input}
+ onChange={e => setInput(e.target.value)}
+ placeholder="@MrBeast, https://youtube.com/@MrBeast, UCX6…"
+ onKeyDown={e => e.key === 'Enter' && handleResolve()}
+ />
+ </div>
+ <Button onClick={handleResolve} disabled={resolving || !input.trim()} className="gap-1.5">
+ {resolving ? <RefreshCw className="h-4 w-4 animate-spin" /> : <Search className="h-4 w-4" />}
+ </Button>
+ </div>
+
+ {resolved && (
+ <div className="flex items-center gap-3 p-3 rounded-lg bg-green-50 border border-green-200">
+ <Avatar className="h-10 w-10">
+ <AvatarImage src={resolved.thumbnails?.medium || resolved.thumbnails?.default} />
+ <AvatarFallback className="bg-green-200 text-green-700 text-xs font-bold">
+ {(resolved.title || 'YT').slice(0, 2).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center gap-1.5">
+ <p className="text-sm font-semibold truncate">{resolved.title}</p>
+ <CheckCircle2 className="h-4 w-4 text-green-600 flex-shrink-0" />
+ </div>
+ <p className="text-xs text-muted-foreground">{resolved.customUrl}</p>
+ {resolved.subscriberCount != null && (
+ <div className="flex gap-1.5 mt-1">
+ <Badge variant="secondary" className="text-xs h-5">{fmtNum(resolved.subscriberCount)} subs</Badge>
+ <Badge variant="secondary" className="text-xs h-5">{fmtNum(resolved.videoCount)} videos</Badge>
+ </div>
)}
- </>
+ </div>
+ </div>
+ )}
+ </TabsContent>
+
+ <TabsContent value="instagram" className="space-y-4 mt-4">
+ <Alert>
+ <Info className="h-4 w-4" />
+ <AlertDescription className="text-xs">
+ Paste your <strong>Instagram Access Token</strong> from the App Dashboard. Your account must be a <strong>Business</strong> or <strong>Creator</strong> account.
+ </AlertDescription>
+ </Alert>
+ <div className="relative">
+ <KeyRound className="absolute left-3 top-3 h-4 w-4 text-muted-foreground" />
+ <Textarea
+ className="pl-9 resize-none"
+ rows={3}
+ value={igToken}
+ onChange={e => setIgToken(e.target.value)}
+ placeholder="Paste your Instagram access token here…"
+ />
+ </div>
+ </TabsContent>
+ </Tabs>
+
+ <DialogFooter>
+ <Button variant="ghost" onClick={closeDialog}>Cancel</Button>
+ {dialogTab === 'youtube' ? (
+ <Button onClick={handleAdd} disabled={!input.trim() || adding} className="gap-1.5">
+ {adding && <RefreshCw className="h-3.5 w-3.5 animate-spin" />}
+ Add Channel
+ </Button>
+ ) : (
+ <Button
+ onClick={handleAddInstagram}
+ disabled={!igToken.trim() || adding}
+ className="gap-1.5 bg-pink-600 hover:bg-pink-700 text-white"
+ >
+ {adding && <RefreshCw className="h-3.5 w-3.5 animate-spin" />}
+ Add Instagram
+ </Button>
)}
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ </div>
+ );
+}
- {/* Add Account Dialog */}
- <Dialog open={dialogOpen} onClose={closeDialog} maxWidth="sm" fullWidth>
- <DialogTitle>Add Account</DialogTitle>
- <DialogContent>
- <Tabs value={dialogTab} onChange={(_, v) => setDialogTab(v)} sx={{ mb: 2, mt: 0.5 }}>
- <Tab icon={<YouTube sx={{ fontSize: 18 }} />} label="YouTube" iconPosition="start" />
- <Tab icon={<Instagram sx={{ fontSize: 18 }} />} label="Instagram" iconPosition="start" />
- </Tabs>
+function AccountCard({ acct, isIG, metrics, refreshingId, onRefresh, onDelete }) {
+ const initials = (acct.title || '?').slice(0, 2).toUpperCase();
+ return (
+ <div className="border border-border rounded-xl p-4 bg-card hover:shadow-sm transition-shadow space-y-3">
+ <div className="flex items-center gap-3">
+ <Avatar className="h-11 w-11">
+ <AvatarImage src={acct.thumbnail || acct.profilePictureUrl || acct.thumbnails?.default} />
+ <AvatarFallback className={`text-xs font-bold text-white ${isIG ? 'bg-pink-500' : 'bg-red-500'}`}>
+ {initials}
+ </AvatarFallback>
+ </Avatar>
+ <div className="flex-1 min-w-0">
+ <p className="text-sm font-semibold truncate">{acct.title || acct.channelId}</p>
+ <p className="text-xs text-muted-foreground truncate">
+ {isIG ? `@${acct.username || acct.igUsername || ''}` : (acct.customUrl || '')}
+ </p>
+ </div>
+ </div>
- {dialogTab === 0 ? (
- <>
- <Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}>
- Enter a YouTube channel URL, @handle, or channel ID.
- </Typography>
- <Box sx={{ display: 'flex', gap: 1, mb: 2 }}>
- <TextField fullWidth value={input} onChange={e => setInput(e.target.value)}
- placeholder="e.g. @MrBeast, https://youtube.com/@MrBeast, UCX6…"
- size="small" onKeyDown={e => e.key === 'Enter' && handleResolve()}
- slotProps={{ input: { startAdornment: <InputAdornment position="start"><LinkIcon sx={{ color: 'text.secondary', fontSize: 18 }} /></InputAdornment> } }} />
- <Button variant="contained" onClick={handleResolve} disabled={resolving || !input.trim()} sx={{ minWidth: 90 }}>
- {resolving ? <CircularProgress size={18} color="inherit" /> : <Search />}
- </Button>
- </Box>
- {resolving && <LinearProgress sx={{ mb: 2, borderRadius: 1 }} />}
- {resolved && (
- <Box sx={{ p: 2, borderRadius: 2, bgcolor: '#f6ffed', border: '1px solid #b7eb8f', display: 'flex', alignItems: 'center', gap: 2 }}>
- <Avatar src={resolved.thumbnails?.medium || resolved.thumbnails?.default} sx={{ width: 48, height: 48, bgcolor: '#d9f7be' }}>
- <YouTube sx={{ color: '#52c41a' }} />
- </Avatar>
- <Box sx={{ flex: 1 }}>
- <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
- <Typography variant="subtitle1" sx={{ fontWeight: 600 }}>{resolved.title}</Typography>
- <CheckCircle sx={{ fontSize: 16, color: '#52c41a' }} />
- </Box>
- <Typography variant="caption" color="text.secondary">{resolved.customUrl}</Typography>
- {resolved.subscriberCount != null && (
- <Box sx={{ display: 'flex', gap: 1, mt: 0.5 }}>
- <Chip label={`${fmtNum(resolved.subscriberCount)} subs`} size="small" sx={{ fontSize: '0.7rem', height: 20 }} />
- <Chip label={`${fmtNum(resolved.videoCount)} videos`} size="small" sx={{ fontSize: '0.7rem', height: 20 }} />
- </Box>
- )}
- </Box>
- </Box>
- )}
- </>
- ) : (
- <>
- <Alert severity="info" sx={{ mb: 2 }}>
- Paste your <b>Instagram Access Token</b> from the App Dashboard. Your account must be a <b>Business</b> or <b>Creator</b> account.
- </Alert>
- <TextField fullWidth value={igToken} onChange={e => setIgToken(e.target.value)}
- placeholder="Paste your Instagram access token here…"
- size="small" multiline rows={3}
- slotProps={{ input: { startAdornment: <InputAdornment position="start" sx={{ alignSelf: 'flex-start', mt: 1 }}><Key sx={{ color: 'text.secondary', fontSize: 18 }} /></InputAdornment> } }} />
- </>
- )}
- </DialogContent>
- <DialogActions sx={{ px: 3, pb: 2 }}>
- <Button onClick={closeDialog} color="inherit">Cancel</Button>
- {dialogTab === 0 ? (
- <Button variant="contained" onClick={handleAdd} disabled={!input.trim() || adding}>
- {adding ? <CircularProgress size={18} color="inherit" /> : 'Add Channel'}
- </Button>
- ) : (
- <Button variant="contained" onClick={handleAddInstagram} disabled={!igToken.trim() || adding}
- sx={{ bgcolor: '#c41d7f', '&:hover': { bgcolor: '#9e1068' } }}>
- {adding ? <CircularProgress size={18} color="inherit" /> : 'Add Instagram'}
- </Button>
- )}
- </DialogActions>
- </Dialog>
- </Box>
- );
+ <div className="grid grid-cols-3 gap-1.5">
+ {metrics.map(m => (
+ <div key={m.label} className={cn('text-center p-2 rounded-lg', m.className, 'bg-opacity-60')}>
+ <p className="text-[0.6rem] uppercase tracking-wide font-medium opacity-70">{m.label}</p>
+ <p className="text-sm font-bold">{m.value}</p>
+ </div>
+ ))}
+ </div>
+
+ {acct.lastUpdated && (
+ <p className="text-xs text-muted-foreground">Updated {timeAgo(acct.lastUpdated)}</p>
+ )}
+
+ <div className="flex gap-2">
+ <Button
+ variant="outline"
+ size="sm"
+ className="flex-1 gap-1.5"
+ onClick={() => onRefresh(acct.id)}
+ disabled={refreshingId === acct.id}
+ >
+ <RefreshCw className={cn('h-3.5 w-3.5', refreshingId === acct.id && 'animate-spin')} />
+ {refreshingId === acct.id ? 'Refreshing…' : 'Refresh'}
+ </Button>
+ <Button
+ variant="outline"
+ size="sm"
+ className="text-destructive hover:text-destructive hover:bg-destructive/10 border-destructive/30"
+ onClick={() => onDelete(acct.id)}
+ >
+ <Trash2 className="h-3.5 w-3.5" />
+ </Button>
+ </div>
+ </div>
+ );
}