feat: finalize academy redesign and production readiness
All checks were successful
CI / Validate frontend and API (push) Successful in 2m22s
CI / Build and publish Docker images (push) Successful in 1m6s

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.
This commit is contained in:
Cauê Faleiros
2026-11-05 15:06:53 -03:00
parent 95a4bd4ac7
commit 21085e887d
99 changed files with 10749 additions and 3935 deletions

View File

@@ -0,0 +1,66 @@
import React, { useEffect, useState } from 'react';
import { adminApi } from '../../services/api';
import { useToast } from '../../context/ToastContext';
import { Switch } from '../ui/Switch';
import { PlusMockIcon } from '../ui/MockupIcons';
type Category = { id: string; name: string; position: number; isActive: boolean };
const CategoryRow: React.FC<{ category: Category; onSave: (category: Category, update: { name: string; isActive: boolean }) => Promise<void> }> = ({ category, onSave }) => {
const [name, setName] = useState(category.name);
useEffect(() => setName(category.name), [category.name]);
const dirty = name.trim() !== category.name && name.trim().length > 0;
return <div className="row" style={{ gridTemplateColumns: 'minmax(0, 1fr) auto auto' }}>
<input className="input" style={{ height: 40, fontSize: 15 }} value={name} onChange={(event) => setName(event.target.value)} aria-label={`Nome da categoria ${category.name}`} />
{dirty ? <button className="btn sec" type="button" onClick={() => void onSave(category, { name: name.trim(), isActive: category.isActive })}>Salvar</button> : <span />}
<Switch checked={category.isActive} onChange={(checked) => void onSave(category, { name: name.trim() || category.name, isActive: checked })} label={`Categoria ${category.name} ativa`} />
</div>;
};
export const CategoryManager: React.FC<{ onChanged?: () => void }> = ({ onChanged }) => {
const { showToast } = useToast();
const [categories, setCategories] = useState<Category[]>([]);
const [newName, setNewName] = useState('');
const [loading, setLoading] = useState(true);
useEffect(() => {
adminApi.categories().then((response) => setCategories(response.data)).catch(() => showToast('Não foi possível carregar as categorias.', 'error')).finally(() => setLoading(false));
}, []);
const create = async (event: React.FormEvent) => {
event.preventDefault();
if (!newName.trim()) return;
try {
const response = await adminApi.createCategory(newName.trim());
setCategories((current) => [...current, response.data].sort((a, b) => a.position - b.position || a.name.localeCompare(b.name)));
setNewName('');
showToast('Categoria criada.', 'success');
onChanged?.();
} catch {
showToast('Não foi possível criar a categoria. Ela pode já existir.', 'error');
}
};
const save = async (category: Category, update: { name: string; isActive: boolean }) => {
try {
const response = await adminApi.updateCategory(category.id, update);
setCategories((current) => current.map((item) => item.id === category.id ? response.data : item));
showToast('Categoria atualizada.', 'success');
onChanged?.();
} catch {
showToast('Não foi possível atualizar a categoria.', 'error');
}
};
if (loading) return <div className="loading">Carregando categorias…</div>;
return <>
<form className="toolbar" onSubmit={create}>
<input className="input" style={{ flex: 1, minWidth: 220 }} value={newName} onChange={(event) => setNewName(event.target.value)} placeholder="Nome da categoria" aria-label="Nova categoria" />
<button className="btn" type="submit" disabled={!newName.trim()}><PlusMockIcon className="ph" /> Adicionar categoria</button>
</form>
<p className="muted" style={{ marginBottom: 12 }}>Categorias ativas aparecem na criação de cursos e nas áreas do catálogo.</p>
<div className="list">{categories.map((category) => <CategoryRow key={category.id} category={category} onSave={save} />)}</div>
{!categories.length && <p className="empty">Nenhuma categoria cadastrada.</p>}
</>;
};