import React, { useState, useEffect } from 'react'; import type { DropdownOptions } from '../App'; import apiService from '../services/apiService'; import { TrashIcon } from './icons/TrashIcon'; import { UserIcon } from './icons/UserIcon'; import { PlusIcon } from './icons/PlusIcon'; import { ChevronDownIcon } from './icons/ChevronDownIcon'; interface ManagementCardProps { title: string; items: string[]; onAdd: (item: string) => void; onRemove: (item: string) => void; disabled?: boolean; placeholder?: string; } const ManagementCard: React.FC = ({ title, items, onAdd, onRemove, disabled = false, placeholder }) => { const [newItem, setNewItem] = useState(''); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (newItem.trim()) { onAdd(newItem.trim()); setNewItem(''); } }; return (

{title}

setNewItem(e.target.value)} placeholder={placeholder || `New ${title.slice(0, -1)}...`} className="flex-grow p-2 border-2 border-oliver-azure rounded-[10px] focus:ring-2 focus:ring-oliver-azure focus:border-oliver-azure transition disabled:bg-oliver-grey disabled:cursor-not-allowed text-oliver-black" disabled={disabled} />
{items.length > 0 ? (
    {items.map((item) => (
  • {item}
  • ))}
) : (
No items found.
)}
); }; // --- USER MANAGEMENT --- interface User { id: string; name: string; email: string; agency: string; } const INITIAL_USERS: User[] = [ { id: '1', name: "Steve O'Donoghue", email: "steveodonoghue@oliver.agency", agency: "OLIVER Agency" }, { id: '2', name: "Jane Doe", email: "jane.doe@barclays.com", agency: "Barclays" }, { id: '3', name: "Sarah Jenkins", email: "sarah.jenkins@mindshare.com", agency: "Mindshare" }, ]; // Fallback agencies if API fails const DEFAULT_AGENCIES = ["OLIVER Agency", "Barclays", "Mindshare", "Zenith", "Unassigned"]; const UsersTab: React.FC = () => { const [users, setUsers] = useState(() => { const saved = localStorage.getItem('barclays_modcomms_users'); return saved ? JSON.parse(saved) : INITIAL_USERS; }); const [agencies, setAgencies] = useState(DEFAULT_AGENCIES); const [newName, setNewName] = useState(''); const [newEmail, setNewEmail] = useState(''); const [newAgency, setNewAgency] = useState(''); // Load agencies from API useEffect(() => { const loadAgencies = async () => { try { const response = await apiService.getAgencies(); const agencyNames = response.map(a => a.name); setAgencies(agencyNames.length > 0 ? agencyNames : DEFAULT_AGENCIES); if (agencyNames.length > 0 && !newAgency) { setNewAgency(agencyNames[0]); } } catch (error) { console.error('Failed to load agencies:', error); setAgencies(DEFAULT_AGENCIES); } }; loadAgencies(); }, []); useEffect(() => { localStorage.setItem('barclays_modcomms_users', JSON.stringify(users)); }, [users]); const handleAddUser = (e: React.FormEvent) => { e.preventDefault(); if (newName && newEmail) { const newUser: User = { id: Date.now().toString(), name: newName, email: newEmail, agency: newAgency }; setUsers([...users, newUser]); setNewName(''); setNewEmail(''); } }; const handleAgencyChange = (userId: string, newAgency: string) => { setUsers(users.map(u => u.id === userId ? { ...u, agency: newAgency } : u)); }; const handleDeleteUser = (userId: string) => { if (window.confirm('Are you sure you want to remove this user?')) { setUsers(users.filter(u => u.id !== userId)); } }; return (
{/* Add User Section */}

Add New User

setNewName(e.target.value)} className="w-full p-2 border-2 border-oliver-azure rounded-[10px] focus:ring-2 focus:ring-oliver-azure focus:border-oliver-azure text-oliver-black" placeholder="e.g. John Smith" required />
setNewEmail(e.target.value)} className="w-full p-2 border-2 border-oliver-azure rounded-[10px] focus:ring-2 focus:ring-oliver-azure focus:border-oliver-azure text-oliver-black" placeholder="user@example.com" required />
{/* User List */}
{users.map((user, index) => ( ))}
Name Email Assigned Agency Actions
{user.name}
{user.email}
); }; // --- SETTINGS COMPONENT --- interface SettingsProps { options: DropdownOptions; onAddCampaign: (value: string) => void; onRemoveCampaign: (value: string) => void; onAddChannel: (value: string) => void; onRemoveChannel: (value: string) => void; onAddSubChannel: (channel: string, value: string) => void; onRemoveSubChannel: (channel: string, value: string) => void; onAddProofType: (channel: string, subChannel: string, value: string) => void; onRemoveProofType: (channel: string, subChannel: string, value: string) => void; readOnly?: boolean; } type Tab = 'Campaigns' | 'Channels' | 'SubChannels' | 'ProofTypes' | 'Users'; export const Settings: React.FC = ({ options, onAddCampaign, onRemoveCampaign, onAddChannel, onRemoveChannel, onAddSubChannel, onRemoveSubChannel, onAddProofType, onRemoveProofType, readOnly = false, }) => { const [activeTab, setActiveTab] = useState('Channels'); const [selectedChannel, setSelectedChannel] = useState(''); const [selectedSubChannel, setSelectedSubChannel] = useState(''); // Update selected channel if it disappears useEffect(() => { if (selectedChannel && !options.channels[selectedChannel]) { setSelectedChannel(''); setSelectedSubChannel(''); } }, [options.channels, selectedChannel]); // Update selected sub-channel if it disappears useEffect(() => { if (selectedChannel && selectedSubChannel) { const subChannels = options.channels[selectedChannel] || {}; if (!subChannels[selectedSubChannel]) { setSelectedSubChannel(''); } } }, [options.channels, selectedChannel, selectedSubChannel]); return (

Settings

Configure application defaults and user access.

{readOnly && (
View-only mode
)}
{/* Tabs Header */}
{/* Tabs Content */}
{activeTab === 'Campaigns' && (
)} {activeTab === 'Channels' && (
)} {activeTab === 'SubChannels' && (
onAddSubChannel(selectedChannel, val)} onRemove={(val) => onRemoveSubChannel(selectedChannel, val)} disabled={readOnly || !selectedChannel} placeholder="e.g. Meta, Video" />
)} {activeTab === 'ProofTypes' && (
onAddProofType(selectedChannel, selectedSubChannel, val)} onRemove={(val) => onRemoveProofType(selectedChannel, selectedSubChannel, val)} disabled={readOnly || !selectedChannel || !selectedSubChannel} placeholder="e.g. In-feed 1x1, 300x600" />
)} {/* Users tab hidden: not connected to backend user system {activeTab === 'Users' && ( )} */}
); };