Page cadastro finalizada
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
#nome-sobrenome{
|
#nome-sobrenome{
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toast-notification{
|
||||||
|
--background: rgb(255, 0, 0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IonProgressBar, IonItem, IonLabel, IonInput, IonBackButton, IonButton, IonButtons, IonCardTitle, IonCol, IonContent, IonGrid, IonHeader, IonPage, IonRow, IonToolbar } from '@ionic/react';
|
import { IonToast, IonProgressBar, IonItem, IonLabel, IonInput, IonBackButton, IonButton, IonButtons, IonCardTitle, IonCol, IonContent, IonGrid, IonHeader, IonPage, IonRow, IonToolbar } from '@ionic/react';
|
||||||
import { arrowBack, logoFacebook, mail } from 'ionicons/icons';
|
import { arrowBack, logoFacebook, mail } from 'ionicons/icons';
|
||||||
import { Action } from '../components/Action';
|
import { Action } from '../components/Action';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
@@ -10,55 +10,100 @@ import * as UsersService from '../services/users'
|
|||||||
const Cadastro: React.FC = () => {
|
const Cadastro: React.FC = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const [ errors, setErrors ] = useState(false);
|
const [showToast, setShowToast] = useState(false);
|
||||||
|
const [messageToast, setMessageToast ] = useState('');
|
||||||
|
|
||||||
const [email, setEmail] = useState({});
|
const [email, setEmail] = useState<string>('');
|
||||||
const [password, setPassword] = useState<string>('');
|
const [password, setPassword] = useState<string>('');
|
||||||
const [confirmPassword, setConfirmPassword] = useState<string>('');
|
const [confirmPassword, setConfirmPassword] = useState<string>('');
|
||||||
const [firstName, setFirstName] = useState<string>('');
|
const [firstName, setFirstName] = useState<string>('');
|
||||||
const [lastName, setLastName] = useState<string>('');
|
const [lastName, setLastName] = useState<string>('');
|
||||||
const [birthDate, setBirthDate] = useState<string>('');
|
const [birthDate, setBirthDate] = useState<string>('');
|
||||||
|
const [lResult, setlResult] = useState({
|
||||||
|
error: '',
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const emailValidate = () => {
|
||||||
// setDisableSubmitButton(true)
|
var usuario = email.substring(0, email.indexOf("@"));
|
||||||
// event.preventDefault();
|
var dominio = email.substring(email.indexOf("@") + 1, email.length);
|
||||||
// const data = new FormData(event.currentTarget);
|
|
||||||
|
|
||||||
const signUpForm = {
|
if ((usuario.length >= 1) &&
|
||||||
name: firstName +' '+ lastName,
|
(dominio.length >= 3) &&
|
||||||
email: email,
|
(usuario.search("@") == -1) &&
|
||||||
birth_date: birthDate,
|
(dominio.search("@") == -1) &&
|
||||||
password: password
|
(usuario.search(" ") == -1) &&
|
||||||
|
(dominio.search(" ") == -1) &&
|
||||||
|
(dominio.search(".") != -1) &&
|
||||||
|
(dominio.indexOf(".") >= 1) &&
|
||||||
|
(dominio.lastIndexOf(".") < dominio.length - 1))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
console.log(signUpForm);
|
const clearResult = () => {
|
||||||
|
lResult.error = '';
|
||||||
|
lResult.success = true;
|
||||||
|
}
|
||||||
|
|
||||||
await UsersService.create(signUpForm).catch(error => {
|
const fieldValidate = async () => {
|
||||||
if (!error.response) return
|
clearResult();
|
||||||
|
|
||||||
if (error.response.data.message) {
|
if(!emailValidate()) {
|
||||||
// setAlertContent(error.response.data.message);
|
lResult.error = 'O EMAIL é inválido!';
|
||||||
} else {
|
lResult.success = false;
|
||||||
// setAlertContent('Houve um erro ao realizar o cadastro.');
|
return lResult;
|
||||||
|
} else if(password.length < 7 || password.length > 12) { //TODO: validar de acordo com a documentação
|
||||||
|
lResult.error = 'A senha deve ter de 7 a 12 caracteres!';
|
||||||
|
lResult.success = false;
|
||||||
|
return lResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setAlertSeverity('error');
|
return lResult;
|
||||||
// setAlert(true);
|
};
|
||||||
// setDisableSubmitButton(false)
|
|
||||||
}).then(response => {
|
|
||||||
if (!response) return;
|
|
||||||
|
|
||||||
history.push(
|
const handleSubmit = async () => {
|
||||||
{
|
|
||||||
pathname: '/home',
|
if(name != '' && email != '' && birthDate != '' && password != '' && confirmPassword != '') {
|
||||||
state: {
|
if(password === confirmPassword){
|
||||||
detail: 'signedUp',
|
const signUpForm = {
|
||||||
alertSeverity: 'success',
|
name: firstName +' '+ lastName,
|
||||||
alertContent: 'Usuário cadastrado com sucesso!'
|
email: email,
|
||||||
}
|
birth_date: birthDate,
|
||||||
|
password: password
|
||||||
}
|
}
|
||||||
)
|
|
||||||
});
|
let result = fieldValidate();
|
||||||
|
if((await result).success) {
|
||||||
|
|
||||||
|
let retorno = await UsersService.create(signUpForm);
|
||||||
|
console.log(retorno);
|
||||||
|
if(retorno.token) {
|
||||||
|
// let signIn = await Api.signIn(email, passwordField);
|
||||||
|
// if(signIn.token) {
|
||||||
|
// await AsyncStorage.setItem('token', signIn.token);
|
||||||
|
// await AsyncStorage.setItem('cpf', retorno.cpf);
|
||||||
|
history.push('home');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setMessageToast(retorno.message);
|
||||||
|
setShowToast(true);
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
setMessageToast(lResult.error);
|
||||||
|
setShowToast(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setMessageToast('As senhas devem ser iguais!');
|
||||||
|
setShowToast(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setMessageToast('Nenhum campo pode ser nulo!');
|
||||||
|
setShowToast(true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const { name } = useParams<{ name: string; }>();
|
const { name } = useParams<{ name: string; }>();
|
||||||
@@ -76,7 +121,8 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonGrid className="ion-padding">
|
<IonGrid className="ion-padding">
|
||||||
<IonRow>
|
<IonRow>
|
||||||
<IonCol size="12">
|
<IonCol size="12">
|
||||||
<IonCardTitle>Como você deseja se cadastrar?</IonCardTitle>
|
{/* <IonCardTitle>Como você deseja se cadastrar?</IonCardTitle> */}
|
||||||
|
<IonCardTitle>Cadastro</IonCardTitle>
|
||||||
</IonCol>
|
</IonCol>
|
||||||
</IonRow>
|
</IonRow>
|
||||||
{/* <IonItem>
|
{/* <IonItem>
|
||||||
@@ -154,6 +200,14 @@ const Cadastro: React.FC = () => {
|
|||||||
<Action message="Já tem conta?" text="Login" link="/login" />
|
<Action message="Já tem conta?" text="Login" link="/login" />
|
||||||
</IonGrid>
|
</IonGrid>
|
||||||
{/* <IonProgressBar type="indeterminate"></IonProgressBar><br /> */}
|
{/* <IonProgressBar type="indeterminate"></IonProgressBar><br /> */}
|
||||||
|
<IonToast
|
||||||
|
// cssClass={"toast-notification"}
|
||||||
|
color='danger'
|
||||||
|
isOpen={showToast}
|
||||||
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
message={messageToast}
|
||||||
|
duration={2500}
|
||||||
|
/>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user