import React, { useState, useEffect } from "react"; import { useAuth } from "../contexts/AuthContext"; import { UserRole } from "../types"; import { Button } from "../components/Button"; import { getCadastroFot } from "../services/apiService"; import { Briefcase, AlertTriangle, Plus, Edit } from "lucide-react"; import { FotForm } from "../components/FotForm"; interface FotData { id: string; fot: number; empresa_nome: string; curso_nome: string; observacoes: string; instituicao: string; ano_formatura_label: string; cidade: string; estado: string; gastos_captacao: number; pre_venda: boolean; } export const CourseManagement: React.FC = () => { const { user } = useAuth(); const [fotList, setFotList] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const [showForm, setShowForm] = useState(false); // Verificar se è admin const isAdmin = user?.role === UserRole.SUPERADMIN || user?.role === UserRole.BUSINESS_OWNER; useEffect(() => { fetchFotData(); }, [isAdmin]); const fetchFotData = async () => { if (!isAdmin) return; const token = localStorage.getItem("token"); if (!token) return; try { setIsLoading(true); const response = await getCadastroFot(token); if (response.data) { setFotList(response.data); setError(null); } else if (response.error) { setError(response.error); } } catch (err) { console.error(err); setError("Erro ao carregar dados."); } finally { setIsLoading(false); } }; const handleFormSubmit = () => { setShowForm(false); fetchFotData(); // Refresh list after successful creation }; // Extract existing FOT numbers for uniqueness validation const existingFots = fotList.map(item => item.fot); if (!isAdmin) { return (

Acesso Negado

Apenas administradores podem acessar esta página.

); } return (
{/* Header */}

Gestão de FOT

Gerencie todas as turmas FOT cadastradas

{/* Form Modal */} {showForm && (
setShowForm(false)} onSubmit={handleFormSubmit} token={localStorage.getItem("token") || ""} existingFots={existingFots} />
)} {/* Error State */} {error && (

{error}

)} {/* Courses Table */}
{isLoading ? (
Carregando dados...
) : (
{fotList.length === 0 ? ( ) : ( fotList.map((item) => ( )) )}
FOT Empresa Cursos Observações Instituição Ano Formatura Cidade Estado Gastos Captação Pré Venda Ações

Nenhuma turma FOT encontrada

{item.fot || "-"}
{item.empresa_nome || "-"}
{item.curso_nome || "-"}
{item.observacoes || "-"}
{item.instituicao || "-"}
{item.ano_formatura_label || "-"}
{item.cidade || "-"}
{item.estado || "-"}
{item.gastos_captacao ? item.gastos_captacao.toLocaleString("pt-BR", { style: "currency", currency: "BRL", }) : "R$ 0,00"}
{item.pre_venda ? "Sim" : "Não"}
)}
); };