-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matricula do estudante em uma trilha
- Loading branch information
Showing
9 changed files
with
206 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<ChakraProvider> | ||
<Flex direction="column" minH="100vh"> | ||
<Header /> | ||
<Container flex="1" marginTop='5vh'> | ||
<Center> | ||
<C.titulo> | ||
<Text | ||
textAlign={"center"} | ||
fontSize={"3xl"} | ||
color={"#243A69"} | ||
as={"b"} | ||
> | ||
Matricule-se em uma trilha | ||
</Text> | ||
</C.titulo> | ||
</Center> | ||
<FormControl marginTop="2vh"> | ||
<FormLabel color="#243A69"> | ||
Selecione uma trilha | ||
</FormLabel> | ||
<Select | ||
type="text" | ||
placeholder="Selecione a trilha" | ||
_placeholder={{ opacity: 1, color: "#243A69" }} isRequired | ||
{...formik.getFieldProps("learning_path_id")} | ||
> | ||
{trilhas.map((op) => ( | ||
<option value={op.id}>{op.name}</option> | ||
))} | ||
</Select> | ||
{formik.touched.learning_path_id && formik.errors.learning_path_id && ( | ||
<Text color="red.500" fontSize="sm"> | ||
{formik.errors.learning_path_id} | ||
</Text> | ||
)} | ||
<Center paddingBottom={5} marginTop="3vh"> | ||
<ButtonCadastrar | ||
Text="Cadastrar" | ||
onClick={formik.handleSubmit} | ||
></ButtonCadastrar> | ||
</Center> | ||
</FormControl> | ||
</Container> | ||
<Footer /> | ||
</Flex> | ||
</ChakraProvider> | ||
|
||
); | ||
}; | ||
|
||
export default NewEnrolmentLP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters