Skip to content

Commit

Permalink
ajuste matricula do estudante em uma trilha
Browse files Browse the repository at this point in the history
  • Loading branch information
yaskisoba committed Dec 13, 2023
1 parent 7033b24 commit 11cc942
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
2 changes: 1 addition & 1 deletion backend/controllers/UserControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ exports.userLogin = async (req, res) => {
secure: true,
});

res.json({ accessToken: accessToken, superuser: user.superuser, userId: user.id});
res.json({ accessToken: accessToken, superuser: user.superuser, userId: user.id, sy: user.school_year});
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Erro durante o login.' });
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/contexts/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ export const AuthProvider = ({ children }) => {
return user
}

const userSy = () => {
const user_sy = sessionStorage.getItem("sy");
return user_sy
}

return (
<AuthContext.Provider
value={{signin, isAuthenticated, isSuperUser, userId}}
value={{signin, isAuthenticated, isSuperUser, userId, userSy}}
>
{children}
</AuthContext.Provider>
Expand Down
61 changes: 40 additions & 21 deletions frontend/src/pages/NewEnrolmentLP/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import ButtonCadastrar from "../../components/Button";
import { Link } from "react-router-dom";

const NewEnrolmentLP = () => {
const { userId } = useAuth();
const { userId, userSy } = useAuth();
const user = userId()
const schoolYear = userSy()
const [showAlert, setShowAlert] = useState(false);

const navigate = useNavigate();
Expand Down Expand Up @@ -47,17 +48,11 @@ const NewEnrolmentLP = () => {
}),
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) {
if(schoolYear === '1'){
toast({
title: "Matrícula realizada.",
description: "Matrícula realizada com sucesso!",
status: "success",
title: " Sua matrícula não pode ser realizada.",
description: "Só alunos do segundo e terceiro ano podem se matricular!",
status: "error",
duration: 2800,
isClosable: true,
position: "top",
Expand All @@ -68,15 +63,39 @@ const NewEnrolmentLP = () => {
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",
});
}else{
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);
Expand Down Expand Up @@ -120,7 +139,7 @@ const NewEnrolmentLP = () => {
{...formik.getFieldProps("learning_path_id")}
>
{trilhas.map((op) => (
<option value={op.id}>{op.name}</option>
<option value={op.name}>{op.name}</option>
))}
</Select>
{formik.touched.learning_path_id && formik.errors.learning_path_id && (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Signin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Signin = () => {
sessionStorage.setItem("accessToken", response.data.accessToken);
sessionStorage.setItem("superuser", response.data.superuser);
sessionStorage.setItem("user_id", response.data.userId);
sessionStorage.setItem("sy", response.data.sy);

signin();
let typeUser = isSuperUser()
Expand Down

0 comments on commit 11cc942

Please sign in to comment.