Files
compor-academy/pages/InstructorProfile.tsx
Cauê Faleiros 21085e887d
All checks were successful
CI / Validate frontend and API (push) Successful in 2m22s
CI / Build and publish Docker images (push) Successful in 1m6s
feat: finalize academy redesign and production readiness
Align admin, community, search, library, learning and course management with the mockup. Add saved courses, download history, public community feed, instructor directory, backend search, course views, admin content tools and community moderation. Harden API and Nginx for production.
2026-11-05 15:06:53 -03:00

39 lines
3.7 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import { Link, useParams } from 'react-router-dom';
import { ArrowSquareOutIcon, CaretRightIcon, CircleNotchIcon, GlobeIcon, InstagramLogoIcon, LinkedinLogoIcon, YoutubeLogoIcon } from '@phosphor-icons/react';
import { Course } from '../types';
import { getPublicProfile, InstructorProfileData } from '../services/db';
import { CourseCoverImage } from '../components/CourseCoverImage';
import { CourseCard, Thumb } from '../components/catalog/Artwork';
import { Avatar } from '../components/ui/Avatar';
import { paths } from '../lib/routes';
import { useIsMobile } from '../hooks/useMediaQuery';
const networks = [
{ key: 'websiteUrl', label: 'Site', icon: GlobeIcon },
{ key: 'linkedinUrl', label: 'LinkedIn', icon: LinkedinLogoIcon },
{ key: 'instagramUrl', label: 'Instagram', icon: InstagramLogoIcon },
{ key: 'youtubeUrl', label: 'YouTube', icon: YoutubeLogoIcon },
] as const;
export const InstructorProfile: React.FC<{ onPlay: (course: Course) => void }> = () => {
const { instructorId, profileId } = useParams<{ instructorId?: string; profileId?: string }>();
const id = instructorId || profileId;
const isMobile = useIsMobile();
const [profile, setProfile] = useState<InstructorProfileData | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => { if (!id) return; setLoading(true); getPublicProfile(id).then(setProfile).catch(() => setProfile(null)).finally(() => setLoading(false)); }, [id]);
if (loading) return <main className="wrap page"><div className="loading"><CircleNotchIcon className="ph spin" /></div></main>;
if (!profile) return <main className="wrap page"><p className="empty">Este perfil não está público.</p></main>;
const isInstructor = profile.role === 'instructor' || profile.role === 'admin';
if (isMobile) return <main className="m-page m-gut enter"><header className="m-person"><Avatar name={profile.name} src={profile.avatarImageUrl || undefined} size="xl" /><h1>{profile.name}</h1>{profile.headline && <p>{profile.headline}</p>}{profile.bio && <p className="m-body">{profile.bio}</p>}</header>
{isInstructor && <section className="m-group"><h2>{profile.courses.length} {profile.courses.length === 1 ? 'curso' : 'cursos'}</h2><div className="m-list">{profile.courses.map((course) => <Link className="m-row" key={course.id} to={paths.course(course.id)}><Thumb course={course} /><span className="m-rt"><b>{course.title}</b><small>{course.lessons.length} aulas · {course.duration}</small></span><CaretRightIcon className="m-chev" /></Link>)}</div></section>}
</main>;
return <main className="wrap page enter"><div className="crumb"><Link to={paths.professors}>Professores</Link><CaretRightIcon className="ph" /><span>{profile.name}</span></div>
<header className="profile-head">{profile.avatarImageUrl ? <span className="av xl"><CourseCoverImage source={profile.avatarImageUrl} alt={`Foto de ${profile.name}`} /></span> : <Avatar name={profile.name} size="xl" />}<div><h1>{profile.name}</h1>{profile.headline && <p>{profile.headline}</p>}</div></header>
{profile.bio && <p className="profile-bio">{profile.bio}</p>}
<div className="profile-links">{networks.map(({ key, label, icon: Icon }) => { const url = profile[key]; return url ? <a className="btn sec" key={key} href={url} target="_blank" rel="noreferrer"><Icon className="ph" />{label}<ArrowSquareOutIcon className="ph" /></a> : null; })}</div>
{isInstructor && <section className="shelf"><header><h2>Cursos</h2><span className="count num">{profile.courses.length}</span></header>{profile.courses.length ? <div className="grid">{profile.courses.map((course) => <CourseCard key={course.id} course={course} />)}</div> : <p className="empty">Nenhum curso publicado ainda.</p>}</section>}
</main>;
};