Formulário finalizado, com todas as restrições necessárias
main
Hugo Oliveira 1 year ago
parent 2771eb111c
commit 0e40093aca

@ -7,7 +7,7 @@ import { Box, Container, Grid, Typography, Button, Stepper, Step, StepLabel } fr
import { useFormik } from 'formik'; import { useFormik } from 'formik';
import { useState } from "react"; import { useState } from "react";
import { matchIsValidTel } from 'mui-tel-input'; import { matchIsValidTel } from 'mui-tel-input';
//import axios from "axios"; import axios from "axios";
interface dados { interface dados {
@ -132,6 +132,7 @@ function App() {
zipcode: values.codigoPostal, zipcode: values.codigoPostal,
location: values.cidade, location: values.cidade,
country: values.pais, country: values.pais,
email: values.emailDP,
contacts: [{ contacts: [{
name: values.nomePessoaContacto, name: values.nomePessoaContacto,
email: values.emailPessoaContacto, email: values.emailPessoaContacto,
@ -144,17 +145,17 @@ function App() {
console.log('Dados API:', extractedData); console.log('Dados API:', extractedData);
/*try { try {
// Make a POST request using Axios // Make a POST request using Axios
const response = await axios.post('https://dev-hgp-sgi.streamline.pt/api/entities', extractedData); const response = await axios.post('https://dev-hgp-sgi.streamline.pt/api/pendings', extractedData);
console.log('Data submitted successfully', response.data); console.log('Data submitted successfully', response.data);
} catch (error) { } catch (error) {
// Handle errors // Handle errors
console.error('Error submitting data:', error); console.error('Error submitting data:', error);
}*/ }
}; };
const formik = useFormik<dados> ({ const formik = useFormik<dados> ({
@ -205,6 +206,7 @@ function App() {
} }
if (formik.values.tiporegisto == '1'){ if (formik.values.tiporegisto == '1'){
formik.values.empresa = '',
formik.values.nomePessoaContacto = formik.values.representante; formik.values.nomePessoaContacto = formik.values.representante;
formik.values.telemovelPC = formik.values.telemovelDP; formik.values.telemovelPC = formik.values.telemovelDP;
formik.values.emailPessoaContacto = formik.values.emailDP; formik.values.emailPessoaContacto = formik.values.emailDP;
@ -265,59 +267,62 @@ function App() {
))} ))}
</Stepper> </Stepper>
<form onSubmit={formik.handleSubmit}> <form onSubmit={formik.handleSubmit}>
<Box sx={{ pb: 2 }}> <Box sx={{ pb: 2 }}>
{getStepContent(activeStep)} {getStepContent(activeStep)}
</Box> </Box>
{validationErrors.map((error, index) => ( {validationErrors.map((error, index) => (
<Box <Box
sx={{ mt: 1, color: 'red'}} sx={{ mt: 1, color: 'red'}}
key={index}> key={index}>
{error} {error}
</Box> </Box>
))} ))}
{(activeStep < steps.length - 1) && ( <Box
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: '3rem',
}}
>
{(activeStep > 0) && (activeStep < steps.length) && (
<Button <Button
type="button" type="button"
variant="contained" variant="contained"
onClick={handleNext} onClick={handleBack}
sx={{ mt: 3, ml: 1 }}
> >
Avançar Retroceder
</Button> </Button>
)} )}
{(activeStep === steps.length - 1) && ( {(activeStep === steps.length - 1) && (
<Button <Button
type="submit" type="submit"
variant="contained" variant="contained"
sx={{ mt: 3, ml: 1 }}
> >
Finalizar Finalizar
</Button> </Button>
)} )}
{(activeStep > 0) && (activeStep < steps.length) && (
{(activeStep < steps.length - 1) && (
<Button <Button
type="button" type="button"
variant="contained" variant="contained"
onClick={handleBack} onClick={handleNext}
sx={{ mt: 3, ml: 1 }} style={{ marginLeft: 'auto' }}
> >
Retroceder Avançar
</Button> </Button>
)} )}
</form> </Box>
</form>
</Grid> </Grid>
</Grid> </Grid>

Loading…
Cancel
Save