"use client"; import { useEffect } from "react"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useCaseStudy } from "@/lib/hooks/useCaseStudy"; import { getImageUrl } from "@/lib/imageUtils"; import { sanitizeHTML } from "@/lib/security/sanitize"; interface CaseSingleProps { slug: string; } const CaseSingle = ({ slug }: CaseSingleProps) => { const router = useRouter(); const { caseStudy, loading, error } = useCaseStudy(slug); const handleGoBack = () => { router.back(); }; // Debug logging useEffect(() => { if (error) { console.error('Error loading case study:', error); } if (caseStudy) { console.log('Case Study Data:', { title: caseStudy.title, hasCategory: !!caseStudy.category, hasClient: !!caseStudy.client, processStepsCount: caseStudy.process_steps?.length || 0, relatedCaseStudiesCount: caseStudy.related_case_studies?.length || 0, hasPosterImage: !!caseStudy.poster_image, hasProjectImage: !!caseStudy.project_image, hasFeaturedImage: !!caseStudy.featured_image, hasProjectOverview: !!caseStudy.project_overview, hasSiteMapContent: !!caseStudy.site_map_content, fullData: caseStudy }); } }, [caseStudy, error]); if (loading) { return ( Loading case study... ); } if (error || !caseStudy) { return ( Case Study Not Found The case study you're looking for doesn't exist or has been removed. View All Case Studies ); } return ( <> {/* Hero Banner Section */} {/* Category Badge */} {caseStudy.category && ( {caseStudy.category.name} )} {/* Title */} {caseStudy.title} {/* Subtitle */} {caseStudy.subtitle && ( {caseStudy.subtitle} )} {/* Meta Information */} {caseStudy.client && ( {caseStudy.client.name} )} {caseStudy.published_at && ( {new Date(caseStudy.published_at).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })} )} {caseStudy.views_count !== undefined && ( {caseStudy.views_count} views )} {/* Hero Image */} {caseStudy.featured_image && ( )} {/* Main Content Section */} {/* Back Button - Top */} { e.currentTarget.style.backgroundColor = '#0056b3'; e.currentTarget.style.borderColor = '#0056b3'; e.currentTarget.style.boxShadow = '0 4px 12px rgba(0, 123, 255, 0.4)'; e.currentTarget.style.transform = 'translateY(-2px)'; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = '#007bff'; e.currentTarget.style.borderColor = '#007bff'; e.currentTarget.style.boxShadow = '0 2px 8px rgba(0, 123, 255, 0.3)'; e.currentTarget.style.transform = 'translateY(0)'; }} > Back to Case Studies {/* Project Overview Section */} Project Overview {caseStudy.project_overview ? ( ) : ( )} {/* Full Description Content */} {caseStudy.description && ( )} {/* Project Image */} {caseStudy.project_image && ( )} {/* Project Info Card */} Project Details {caseStudy.category && ( Category {caseStudy.category.name} )} {caseStudy.client && ( Client {caseStudy.client.name} )} {caseStudy.published_at && ( Published {new Date(caseStudy.published_at).toLocaleDateString('en-US', { year: 'numeric', month: 'short' })} )} {caseStudy.featured && ( Status Featured )} {caseStudy.client?.website && ( Visit Client Website )} {/* Statistics/Metrics Section */} {caseStudy.description && caseStudy.description.includes('Key Results') && ( Key Achievements {(() => { // Extract metrics from description const resultsMatch = caseStudy.description.match(/Key Results<\/h3>[\s\S]*?([\s\S]*?)<\/ul>/i); if (resultsMatch) { const items = resultsMatch[1].match(/([^<]+)<\/li>/g); if (items && items.length > 0) { return items.slice(0, 4).map((item, index) => { const text = item.replace(/<[^>]+>/g, ''); const numberMatch = text.match(/(\d+[%$]?)/); const number = numberMatch ? numberMatch[1] : ''; const description = text.replace(/\d+[%$]?\s*/, '').trim(); return ( {number} {description} ); }); } } return null; })()} )} {/* Site Map / Process Section */} {caseStudy.site_map_content && ( Site Map & Process )} {/* Back Button - Bottom */} { e.currentTarget.style.backgroundColor = '#0056b3'; e.currentTarget.style.borderColor = '#0056b3'; e.currentTarget.style.boxShadow = '0 4px 12px rgba(0, 123, 255, 0.4)'; e.currentTarget.style.transform = 'translateY(-2px)'; }} onMouseLeave={(e) => { e.currentTarget.style.backgroundColor = '#007bff'; e.currentTarget.style.borderColor = '#007bff'; e.currentTarget.style.boxShadow = '0 2px 8px rgba(0, 123, 255, 0.3)'; e.currentTarget.style.transform = 'translateY(0)'; }} > Back to Case Studies > ); }; export default CaseSingle;
Loading case study...
The case study you're looking for doesn't exist or has been removed.