diff --git a/backend/controllers/LearningPathsEnrolmentController.js b/backend/controllers/LearningPathsEnrolmentController.js
index 0cfb5e69..4f22db5d 100644
--- a/backend/controllers/LearningPathsEnrolmentController.js
+++ b/backend/controllers/LearningPathsEnrolmentController.js
@@ -1,4 +1,6 @@
const { LearningPathsEnrolment } = require('../models/schemas');
+const { Registration } = require('../models/schemas')
+
exports.studentEnrolment = async (req, res) => {
const { learning_path_id, student_id } = req.body;
@@ -18,4 +20,27 @@ exports.studentEnrolment = async (req, res) => {
};
});
};
+}
+
+exports.isOpenEnrolment = async() => {
+ let registrationsPeriod = Registration.findAll()
+
+ for(let res of registrationsPeriod){
+ let startDate = new Date(res.start)
+ let endDate = new Date(res.end)
+ const now = new Date()
+
+ if(startDate < now){
+ await Registration.update(
+ { isOpen: false },
+ { where: { id: registrationsPeriod.id } }
+ );
+ }else if(startDate >= now && endDate < now){
+ await Registration.update(
+ { isOpen: true },
+ { where: { id: registrationsPeriod.id } }
+ );
+ }
+ }
+
}
\ No newline at end of file
diff --git a/backend/controllers/UserControllers.js b/backend/controllers/UserControllers.js
index 14ca91ba..44bb3057 100644
--- a/backend/controllers/UserControllers.js
+++ b/backend/controllers/UserControllers.js
@@ -70,7 +70,7 @@ exports.userLogin = async (req, res) => {
secure: true,
});
- res.json({ accessToken: accessToken, superuser: user.superuser });
+ res.json({ accessToken: accessToken, superuser: user.superuser, userId: user.id});
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Erro durante o login.' });
diff --git a/frontend/src/App.js b/frontend/src/App.js
index e47c615a..5054036e 100644
--- a/frontend/src/App.js
+++ b/frontend/src/App.js
@@ -6,7 +6,7 @@ import GlobalStyle from "./styles/global";
const App = () => (
- {/* */}
+
);
diff --git a/frontend/src/contexts/auth.js b/frontend/src/contexts/auth.js
index 27f57317..7e036eff 100644
--- a/frontend/src/contexts/auth.js
+++ b/frontend/src/contexts/auth.js
@@ -27,14 +27,17 @@ export const AuthProvider = ({ children }) => {
const isSuperUser = () => {
const userType = sessionStorage.getItem("superuser");
- console.log(userType)
return userType
}
+ const userId = () => {
+ const user = sessionStorage.getItem("user_sy");
+ return user
+ }
return (
{children}
diff --git a/frontend/src/pages/NewEnrolmentLP/index.js b/frontend/src/pages/NewEnrolmentLP/index.js
new file mode 100644
index 00000000..7a1b9b82
--- /dev/null
+++ b/frontend/src/pages/NewEnrolmentLP/index.js
@@ -0,0 +1,146 @@
+import React, { useState, useEffect } from "react";
+import { useNavigate } from "react-router-dom";
+import { useToast } from "@chakra-ui/react";
+import { Container, Flex, Text, Select, FormControl, FormLabel, Input, Button, Center } from "@chakra-ui/react";
+import Header from "../../components/Header/index.js";
+import Footer from "../../components/Footer/index.js";
+import { ChakraProvider } from "@chakra-ui/react";
+import useAuth from "../../hooks/useAuth";
+import * as C from "./styles.js";
+import { useFormik } from "formik";
+import * as yup from "yup";
+import axios from "axios";
+import ButtonCadastrar from "../../components/Button";
+
+
+import { Link } from "react-router-dom";
+
+const NewEnrolmentLP = () => {
+ const { userId } = useAuth();
+ const user = userId()
+ const [showAlert, setShowAlert] = useState(false);
+
+ const navigate = useNavigate();
+ const toast = useToast();
+ const [trilhas, setTrilhas] = useState([]);
+
+ 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'
+ } catch (error) {
+ console.error('Erro ao buscar trilhas:', error);
+ }
+ }
+ fetchTrilhas();
+ }, []);
+
+ const formik = useFormik({
+ initialValues: {
+ learning_path_id: "",
+ },
+ validationSchema: yup.object({
+ learning_path_id: yup
+ .string()
+ .required("Uma trilha deve ser selecionada!")
+ }),
+ onSubmit: async(values) => {
+ try{
+ const response = await axios.post("http://localhost:3001/learningpathenrolment/studentenrolment",
+ {
+ student_id: parseInt(user),
+ learning_path_id: values.learning_path_id
+ }
+ )
+ if (response.status === 201) {
+ toast({
+ title: "Matrícula realizada.",
+ description: "Matrícula realizada com sucesso!",
+ status: "success",
+ duration: 2800,
+ isClosable: true,
+ position: "top",
+ });
+
+
+ setShowAlert(true);
+ setTimeout(() => {
+ navigate("/home-student");
+ }, 1000);
+ } else {
+ toast({
+ title: "Erro na matrícula.",
+ description: response.data.message || "Erro desconhecido.",
+ status: "error",
+ duration: 2800,
+ isClosable: true,
+ position: "top",
+ });
+ }
+ }catch(error){
+ console.error("Erro ao cadastrar:", error);
+ toast({
+ title: "Erro na matrícula.",
+ description: "Tente novamente mais tarde.",
+ status: "error",
+ duration: 2800,
+ isClosable: true,
+ position: "top",
+ });
+ }
+ }
+ })
+
+ return (
+
+
+
+
+
+
+
+ Matricule-se em uma trilha
+
+
+
+
+
+ Selecione uma trilha
+
+
+ {formik.touched.learning_path_id && formik.errors.learning_path_id && (
+
+ {formik.errors.learning_path_id}
+
+ )}
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export default NewEnrolmentLP;
diff --git a/frontend/src/pages/NewEnrolmentLP/styles.js b/frontend/src/pages/NewEnrolmentLP/styles.js
new file mode 100644
index 00000000..b7a9cba7
--- /dev/null
+++ b/frontend/src/pages/NewEnrolmentLP/styles.js
@@ -0,0 +1,10 @@
+import styled from "styled-components";
+
+export const titulo = styled.div`
+ font-size: 150%;
+ font-weight: 600;
+ color: #243A69;
+ margin-left: 20px;
+ margin-top: 20px;
+ align: center;
+`;
\ No newline at end of file
diff --git a/frontend/src/pages/Signin/index.js b/frontend/src/pages/Signin/index.js
index d3bb391a..892cdfb6 100644
--- a/frontend/src/pages/Signin/index.js
+++ b/frontend/src/pages/Signin/index.js
@@ -12,7 +12,7 @@ import { Text } from '@chakra-ui/react';
import axios from 'axios';
const Signin = () => {
- const { signin, isSuperUser } = useAuth();
+ const { signin, isSuperUser, userId} = useAuth();
const navigate = useNavigate();
const [email, setEmail] = useState("");
@@ -29,10 +29,12 @@ const Signin = () => {
if (response.data.accessToken) {
sessionStorage.setItem("accessToken", response.data.accessToken);
sessionStorage.setItem("superuser", response.data.superuser);
+ sessionStorage.setItem("user_id", response.data.userId);
signin();
let typeUser = isSuperUser()
-
+ let user = userId()
+
if(typeUser == "true"){
console.log("é adm ")
navigate("/home");
diff --git a/frontend/src/pages/StudentHome/index.js b/frontend/src/pages/StudentHome/index.js
index 2f08c6e7..6e7bf3f6 100644
--- a/frontend/src/pages/StudentHome/index.js
+++ b/frontend/src/pages/StudentHome/index.js
@@ -29,10 +29,10 @@ const StudentHome = () => {
diff --git a/frontend/src/routes/index.js b/frontend/src/routes/index.js
index 9a9febe9..23a7b71a 100644
--- a/frontend/src/routes/index.js
+++ b/frontend/src/routes/index.js
@@ -12,6 +12,7 @@ import Recommendations from "../pages/Recommendations";
import SendStudent from "../pages/SendStudents";
import RegistrationPeriod from "../pages/RegistrationPeriod"
import StudentHome from "../pages/StudentHome"
+import NewEnrolmentLP from "../pages/NewEnrolmentLP"
const RoutesApp = () => {
const { isAuthenticated, isSuperUser } = useAuth();
@@ -27,7 +28,7 @@ const RoutesApp = () => {
} />
} />
- {typeUser == 'true' ? (
+ {typeUser === 'true' ? (
<>
{
/>
>
) : (
-
+ :
}
/>
+ :
+ }
+ />
+ >
+
)}