"use client"; import React, { useState } from 'react'; import { Image as ImageIcon, Sparkles, Youtube, X, Globe, Facebook, Linkedin, Instagram } from 'lucide-react'; import { Business, CATEGORIES } from '../../types'; import { generateBusinessDescription } from '../../lib/geminiService'; // Helper to extract youtube ID const getYouTubeId = (url: string) => { const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/; const match = url.match(regExp); return (match && match[2].length === 11) ? match[2] : null; }; const DashboardProfile = ({ business, setBusiness }: { business: Business, setBusiness: (b: Business) => void }) => { const [formData, setFormData] = useState(business); const [videoInput, setVideoInput] = useState(business.videoUrl || ''); const [videoPreviewId, setVideoPreviewId] = useState(getYouTubeId(business.videoUrl || '')); const [isGenerating, setIsGenerating] = useState(false); const [isMounted, setIsMounted] = useState(false); // Sync formData when business prop changes (initial fetch) React.useEffect(() => { setFormData(business); setVideoInput(business.videoUrl || ''); setVideoPreviewId(getYouTubeId(business.videoUrl || '')); }, [business]); React.useEffect(() => { setIsMounted(true); }, []); const handleInputChange = (e: React.ChangeEvent) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; const handleSocialChange = (network: keyof typeof formData.socialLinks, value: string) => { setFormData({ ...formData, socialLinks: { ...formData.socialLinks, [network]: value } }); }; const handleVideoChange = (e: React.ChangeEvent) => { const url = e.target.value; setVideoInput(url); setVideoPreviewId(getYouTubeId(url)); setFormData({ ...formData, videoUrl: url }); }; const handleAiGenerate = async () => { setIsGenerating(true); const text = await generateBusinessDescription(formData.name, formData.category, "Innovation, Qualité, Service client"); setFormData(prev => ({ ...prev, description: text })); setIsGenerating(false); }; const handleSave = async () => { try { const res = await fetch('/api/businesses', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-user-id': business?.ownerId || (typeof window !== 'undefined' ? JSON.parse(localStorage.getItem('afro_user') || '{}').id : '') }, body: JSON.stringify({ ...formData, ownerId: business?.ownerId || (typeof window !== 'undefined' ? JSON.parse(localStorage.getItem('afro_user') || '{}').id : null) }) }); const data = await res.json(); if (data.error) { alert('Erreur: ' + data.error); } else { setBusiness(data); alert('Profil mis à jour avec succès !'); // Optional: refresh page to show in directory } } catch (error) { console.error('Save error:', error); alert('Erreur lors de la sauvegarde'); } }; return (

Éditer mon profil

{/* A. Bloc Identité Visuelle */}

Identité Visuelle

Logo actuel

Glissez votre logo ici ou cliquez pour parcourir