Skip to content

Commit

Permalink
matrícula em eletivas
Browse files Browse the repository at this point in the history
  • Loading branch information
yaskisoba committed Dec 13, 2023
1 parent 6f13fa5 commit 7ef4af8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion frontend/src/pages/CreateTrilhas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ const CreateTrilhas = () => {
serie: yup.string().required("A série é obrigatória"),
eletivas: yup
.array()
.min(1, "É necessário selecionar pelo menos uma eletiva")
.min(1, "É necessário selecionar pelo menos uma eletiva além do Projeto de Vida")
.required("É necessário selecionar eletivas relacionadas"),
}),
onSubmit: async (values) => {
values.eletivas.push("Projeto de Vida")
try {
const response = await axios.post(
"http://localhost:3001/learningpath/createLearningPaths",
Expand Down Expand Up @@ -220,6 +221,7 @@ const CreateTrilhas = () => {
}
>
<Stack spacing={[1, 2]} direction={["column", "column"]}>
<Checkbox isChecked>Projeto de Vida</Checkbox>
{isLoading ? (
<Text color="red.500" fontSize="sm">
{formik.errors.eletivas}
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/pages/NewEnrolmentElectives/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ButtonCadastrar from "../../components/Button";

import { Link } from "react-router-dom";

const NewEnrolmentLP = () => {
const NewEnrolmentElectives = () => {
const { userId, userSy } = useAuth();
const user = userId()
const schoolYear = userSy()
Expand Down Expand Up @@ -50,6 +50,9 @@ const NewEnrolmentLP = () => {
fetchEletivas();
}, []);

const eletivasFiltradas = eletivas.filter((eletiva) => eletiva.school_year === parseInt(schoolYear));


const formik = useFormik({
initialValues: {
eletivas: [],
Expand All @@ -59,15 +62,17 @@ const NewEnrolmentLP = () => {
let requiredCount;

if (parseInt(schoolYear) === 1) {
requiredCount = 6;
requiredCount = 5;
} else if (parseInt(schoolYear) === 2 || parseInt(schoolYear) === 3) {
requiredCount = 4;
requiredCount = 3;
}

return value.length === requiredCount;
}),
}),
onSubmit: async(values) => {
values.eletivas.push("Projeto de Vida")

try{
const response = await axios.post("http://localhost:3001/elective/matricula-eletivas",
{
Expand Down Expand Up @@ -144,7 +149,8 @@ const NewEnrolmentLP = () => {

<CheckboxGroup value={formik.values.eletivas} onChange={(values) => formik.setFieldValue("eletivas", values)
}>
{eletivas.map((eletiva) =>
<Checkbox isChecked color="#243A69">Projeto de Vida</Checkbox>
{eletivasFiltradas.map((eletiva) =>
<Checkbox isChecked={formik.values.eletivas.includes(eletiva.name)} color="#243A69" marginLeft="1vh" value={eletiva.name} >{eletiva.name} </Checkbox>
)}
</CheckboxGroup>
Expand All @@ -170,4 +176,4 @@ const NewEnrolmentLP = () => {
);
};

export default NewEnrolmentLP;
export default NewEnrolmentElectives;

0 comments on commit 7ef4af8

Please sign in to comment.