// src/components/Onboarding.tsx 'use client' import { useState } from 'react'; import { X, ArrowRight, Twitter, InstagramIcon, Facebook, Linkedin } from 'lucide-react'; import { createProfile } from '@/lib/api/core'; import { useTheme } from '@/contexts/themecontext'; interface AddProfileProps { onComplete: () => void; } interface SocialInput { type: string; identifier: string; } export default function AddProfile({ onComplete }: AddProfileProps) { const { theme } = useTheme(); const [step, setStep] = useState(1); const [profileName, setProfileName] = useState(''); const [socials, setSocials] = useState([]); const [error, setError] = useState(''); const handleAddSocial = (type: string) => { setSocials([...socials, { type, identifier: '' }]); }; const handleUpdateSocial = (index: number, identifier: string) => { const newSocials = [...socials]; newSocials[index].identifier = identifier; setSocials(newSocials); }; const handleRemoveSocial = (index: number) => { setSocials(socials.filter((_, i) => i !== index)); }; const handleSubmit = async () => { try { setError(''); const workspaceId = localStorage.getItem('selectedWorkspaceId'); if (!workspaceId) { setError('No workspace selected'); return; } if (!profileName.trim()) { setError('Profile name is required'); return; } // Filter out socials with empty identifiers const validSocials = socials.filter(s => s.identifier.trim() !== ''); await createProfile({ name: profileName.trim(), workspace_id: workspaceId, socials: validSocials }); onComplete(); } catch (error) { console.error('Failed to create profile:', error); setError('Failed to create profile. Please try again.'); } }; return (

{step === 1 ? 'Ajouter un profil' : 'Ajouter des réseaux sociaux'}

{error && (
{error}
)} {step === 1 ? (
setProfileName(e.target.value)} className={`w-full px-3 py-2 rounded-md border ${ theme === 'dark' ? 'bg-gray-700 border-gray-600 text-white' : 'bg-white border-gray-300 text-gray-900' } focus:ring-2 focus:ring-blue-500 focus:border-transparent`} placeholder="Entrez le nom du profil" />
) : (
{socials.map((social, index) => (
handleUpdateSocial(index, e.target.value)} className={`flex-1 px-3 py-2 rounded-md border ${ theme === 'dark' ? 'bg-gray-700 border-gray-600 text-white' : 'bg-white border-gray-300 text-gray-900' } focus:ring-2 focus:ring-blue-500 focus:border-transparent`} placeholder={`Entrez l'identifiant ${social.type}`} />
))}
{['twitter', 'instagram', 'facebook', 'linkedin'].filter( type => !socials.some(s => s.type === type) ).map((type) => ( ))}
)}
); }