diff --git a/frontend/src/pages/Home/index.js b/frontend/src/pages/Home/index.js index 880825d4..f5ecc218 100644 --- a/frontend/src/pages/Home/index.js +++ b/frontend/src/pages/Home/index.js @@ -13,22 +13,22 @@ const Home = () => { - - Criar trilha - - - Criar Eletiva - - - Excluir trilha - - - Excluir eletiva - - - Recomendações - + + Criar trilha + + + Criar Eletiva + + + Excluir trilha + + + Excluir eletiva + + + Recomendações + diff --git a/frontend/src/pages/Recommendations/index.js b/frontend/src/pages/Recommendations/index.js index 87980007..54ffc2b9 100644 --- a/frontend/src/pages/Recommendations/index.js +++ b/frontend/src/pages/Recommendations/index.js @@ -11,12 +11,9 @@ import { Table, Thead, Tbody, - Tfoot, Tr, Th, Td, - Checkbox, - TableContainer, Button, AlertDialog, AlertDialogOverlay, @@ -26,24 +23,33 @@ import { AlertDialogFooter, Container, Alert, - AlertIcon + AlertIcon, + Select } from "@chakra-ui/react" ; const Recommendations = () => { const [trilhas, setTrilhas] = useState([]); - const [trilhasSelecionadas, setTrilhasSelecionadas] = useState([]); - - const { isOpen, onOpen, onClose } = useDisclosure() - const cancelRef = React.useRef() + const [eletivasPorTrilha, setEletivasPorTrilha] = useState({}); + const [descricaoTrilha, setDescricaoTrilha] = useState(''); + + const { isOpen, onOpen, onClose } = useDisclosure(); + const cancelRef = React.useRef(); const [showAlert, setShowAlert] = useState(false); - // Carregar trilhas do backend ao carregar o componente + useEffect(() => { async function fetchTrilhas() { try { - const response = await axios.get('http://localhost:3001/learningpath/learningpath'); // Endpoint para buscar trilhas - setTrilhas(response.data); // Define as trilhas na state 'trilhas' + const response = await axios.get('http://localhost:3001/learningpath/learningpath'); + setTrilhas(response.data); + + // Mapear as eletivas por trilha para posterior uso + const eletivasMap = {}; + response.data.forEach((trilha) => { + eletivasMap[trilha.id] = trilha.related_eletivas || []; + }); + setEletivasPorTrilha(eletivasMap); } catch (error) { console.error('Erro ao buscar trilhas:', error); } @@ -51,120 +57,95 @@ const Recommendations = () => { fetchTrilhas(); }, []); - // Função para marcar/desmarcar trilha selecionada - const handleCheckboxChange = (id) => { - const isSelected = trilhasSelecionadas.includes(id); - - if (isSelected) { - // Se já estiver selecionado, remova da lista de selecionados - setTrilhasSelecionadas(trilhasSelecionadas.filter((eleId) => eleId !== id)); - } else { - // Se não estiver selecionado, adicione à lista de selecionados - setTrilhasSelecionadas([...trilhasSelecionadas, id]); - } - - console.log(trilhasSelecionadas) + // Função para abrir o modal e exibir a descrição da trilha + const handleVerDescricaoClick = (descricao) => { + setDescricaoTrilha(descricao); + onOpen(); }; - - // Função para excluir trilhas selecionadas - const handleExcluirClick = async () => { - try { - // Enviar uma solicitação para excluir as eletivas selecionadas - trilhasSelecionadas.map(async (eletiva) => { - await axios.delete('http://localhost:3001/learningpath/deleteLearningPaths', { - data: { id: eletiva }, - }); - }) - - // Atualizar a lista de eletivas após a exclusão - const response = await axios.get('http://localhost:3001/learningpath/learningpath'); - setTrilhas(response.data); - - // Limpar a lista de eletivas selecionadas - setTrilhasSelecionadas([]); - onClose(); - setTimeout(() => { - window.location.reload();; - }, 2000); - setShowAlert(true); - } catch (error) { - console.error('Erro ao excluir trilhas:', error); - } - }; - - - return ( - - - - - - Exclusão de Trilhas - - - - - - Nome da eletiva - Ano letivo - - - - - {trilhas.map((linha) => ( + + + + + + Disciplinas disponíveis + + + - {linha.name} - {linha.school_year} - handleCheckboxChange(linha.id)}> + Nome da trilha + Descrição + Eletivas relacionadas - ))} - - - - - Excluir trilhas selecionadas - - - - - Excluir Trilhas - - - - Você tem certeza? Essa ação não pode ser desfeita. - - - - - Cancelar - - - Excluir - - - - - - - - {showAlert && ( - - - Trilhas excluídas com sucesso! - - )} - - - - - + + + {trilhas.map((linha) => ( + + {linha.name} + + handleVerDescricaoClick(linha.description)} + > + Ver Descrição + + + + + {eletivasPorTrilha[linha.id]?.map((eletiva) => ( + {eletiva.name} + ))} + + + + ))} + + + {/* Modal de Ver Descrição */} + + + + + Descrição da Trilha + + + {descricaoTrilha} + + + + Fechar + + + + + + + {showAlert && ( + + + + Trilhas excluídas com sucesso! + + + )} + + + + ); };