4194
package-lock.json
generated
4194
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -19,12 +19,12 @@
|
|||||||
"@types/react-dom": "^16.9.10",
|
"@types/react-dom": "^16.9.10",
|
||||||
"@types/react-router": "^5.1.11",
|
"@types/react-router": "^5.1.11",
|
||||||
"@types/react-router-dom": "^5.1.7",
|
"@types/react-router-dom": "^5.1.7",
|
||||||
|
"axios": "^0.26.1",
|
||||||
"ionicons": "^5.4.0",
|
"ionicons": "^5.4.0",
|
||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
"react-router": "^5.2.0",
|
"react-router": "^5.2.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-scripts": "^5.0.0",
|
|
||||||
"typescript": "^4.1.3",
|
"typescript": "^4.1.3",
|
||||||
"web-vitals": "^0.2.4",
|
"web-vitals": "^0.2.4",
|
||||||
"workbox-background-sync": "^5.1.4",
|
"workbox-background-sync": "^5.1.4",
|
||||||
@@ -65,7 +65,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@capacitor/cli": "3.4.3"
|
"@capacitor/cli": "3.4.3",
|
||||||
|
"react-scripts": "5.0.1"
|
||||||
},
|
},
|
||||||
"description": "An Ionic project"
|
"description": "An Ionic project"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
setupIonicReact
|
setupIonicReact
|
||||||
} from '@ionic/react';
|
} from '@ionic/react';
|
||||||
import { IonReactRouter } from '@ionic/react-router';
|
import { IonReactRouter } from '@ionic/react-router';
|
||||||
import Cadastro from './pages/Cadastro';
|
import Cadastro from './pages/Cadastro/Cadastro';
|
||||||
import MainPages from './pages/MainPages';
|
import MainPages from './pages/MainPages';
|
||||||
|
|
||||||
/* Core CSS required for Ionic components to work properly */
|
/* Core CSS required for Ionic components to work properly */
|
||||||
|
|||||||
18
src/config/api.config.ts
Normal file
18
src/config/api.config.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import environment from "../environments/environment";
|
||||||
|
|
||||||
|
function getBaseUrl() {
|
||||||
|
const { hostname } = window.location;
|
||||||
|
const { url } = environment;
|
||||||
|
|
||||||
|
let apiUrl = null;
|
||||||
|
|
||||||
|
// if (hostname === '') {
|
||||||
|
// apiUrl = url.prod;
|
||||||
|
// } else {
|
||||||
|
apiUrl = url.local;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return apiUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { getBaseUrl };
|
||||||
6
src/environments/environment.ts
Normal file
6
src/environments/environment.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export default {
|
||||||
|
url: {
|
||||||
|
prod: 'https://projeto-integrado-f.herokuapp.com',
|
||||||
|
local: 'http://localhost:3000'
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#nome-sobrenome{
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
import { IonIcon, 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 CustomField from '../components/CustomField';
|
|
||||||
import { Action } from '../components/Action';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
// import { validateForm } from '../data/utils';
|
|
||||||
import { useParams } from 'react-router';
|
|
||||||
import './Cadastro.css';
|
|
||||||
import ModalExample from '../components/Email';
|
|
||||||
|
|
||||||
const Cadastro: React.FC = () => {
|
|
||||||
const [ errors, setErrors ] = useState(false);
|
|
||||||
const createAccount = () => {
|
|
||||||
|
|
||||||
// const errors = validateForm();
|
|
||||||
setErrors(errors);
|
|
||||||
|
|
||||||
// if (!errors.length) {
|
|
||||||
|
|
||||||
// Submit your form here
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
const { name } = useParams<{ name: string; }>();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IonPage>
|
|
||||||
<IonHeader>
|
|
||||||
<IonToolbar>
|
|
||||||
<IonButtons slot="start">
|
|
||||||
<IonBackButton text={''} icon={arrowBack} defaultHref='mainpages' />
|
|
||||||
</IonButtons>
|
|
||||||
</IonToolbar>
|
|
||||||
</IonHeader>
|
|
||||||
<IonContent fullscreen>
|
|
||||||
<IonGrid className="ion-padding">
|
|
||||||
<IonRow>
|
|
||||||
<IonCol size="12">
|
|
||||||
<IonCardTitle>Como você deseja se cadastrar?</IonCardTitle>
|
|
||||||
</IonCol>
|
|
||||||
</IonRow>
|
|
||||||
{/* <IonItem>
|
|
||||||
<IonIcon icon={logoFacebook} />
|
|
||||||
Continuar com Facebook
|
|
||||||
</IonItem>
|
|
||||||
<IonItem>
|
|
||||||
<IonIcon icon={mail} />
|
|
||||||
Continuar com e-mail
|
|
||||||
</IonItem> */}
|
|
||||||
<IonRow>
|
|
||||||
<IonCol size="12">
|
|
||||||
<div id='nome-sobrenome'>
|
|
||||||
<IonItem>
|
|
||||||
<IonLabel position='floating'>Nome</IonLabel>
|
|
||||||
<IonInput clearInput></IonInput>
|
|
||||||
</IonItem>
|
|
||||||
<IonItem>
|
|
||||||
<IonLabel position='floating'>Sobrenome</IonLabel>
|
|
||||||
<IonInput clearInput></IonInput>
|
|
||||||
</IonItem>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<IonItem>
|
|
||||||
<IonLabel position='floating'>E-mail</IonLabel>
|
|
||||||
<IonInput clearInput type='email'></IonInput>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem>
|
|
||||||
<IonLabel position='stacked'>Data de nascimento</IonLabel>
|
|
||||||
<IonInput type='date'></IonInput>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonItem>
|
|
||||||
<IonLabel position='floating'>Senha</IonLabel>
|
|
||||||
<IonInput clearInput type='password'></IonInput>
|
|
||||||
</IonItem>
|
|
||||||
<IonItem>
|
|
||||||
<IonLabel position='floating'>Confirme a senha</IonLabel>
|
|
||||||
<IonInput clearInput type='password'></IonInput>
|
|
||||||
</IonItem>
|
|
||||||
|
|
||||||
<IonButton className="ion-margin-top" expand="block" onClick={ createAccount }>Cadastrar-se</IonButton>
|
|
||||||
</IonCol>
|
|
||||||
</IonRow>
|
|
||||||
<small className='ion-margin-top'>
|
|
||||||
Ao se cadastrar, você aceita nossos <a href="">Termos e Condições</a> e nossa <a href=""> Política de Privacidade</a>.
|
|
||||||
</small>
|
|
||||||
<Action message="Já tem conta?" text="Login" link="/login" />
|
|
||||||
</IonGrid>
|
|
||||||
</IonContent>
|
|
||||||
</IonPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Cadastro;
|
|
||||||
7
src/pages/Cadastro/Cadastro.css
Normal file
7
src/pages/Cadastro/Cadastro.css
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#nome-sobrenome{
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toast-notification{
|
||||||
|
--background: rgb(255, 0, 0);
|
||||||
|
}
|
||||||
216
src/pages/Cadastro/Cadastro.tsx
Normal file
216
src/pages/Cadastro/Cadastro.tsx
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
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 { Action } from '../../components/Action';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { useHistory, useParams } from 'react-router';
|
||||||
|
import './Cadastro.css';
|
||||||
|
import ModalExample from '../../components/Email';
|
||||||
|
import * as UsersService from '../../services/users'
|
||||||
|
|
||||||
|
const Cadastro: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const [showToast, setShowToast] = useState(false);
|
||||||
|
const [messageToast, setMessageToast ] = useState('');
|
||||||
|
|
||||||
|
const [email, setEmail] = useState<string>('');
|
||||||
|
const [password, setPassword] = useState<string>('');
|
||||||
|
const [confirmPassword, setConfirmPassword] = useState<string>('');
|
||||||
|
const [firstName, setFirstName] = useState<string>('');
|
||||||
|
const [lastName, setLastName] = useState<string>('');
|
||||||
|
const [birthDate, setBirthDate] = useState<string>('');
|
||||||
|
const [lResult, setlResult] = useState({
|
||||||
|
error: '',
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const emailValidate = () => {
|
||||||
|
var usuario = email.substring(0, email.indexOf("@"));
|
||||||
|
var dominio = email.substring(email.indexOf("@") + 1, email.length);
|
||||||
|
|
||||||
|
if ((usuario.length >= 1) &&
|
||||||
|
(dominio.length >= 3) &&
|
||||||
|
(usuario.search("@") == -1) &&
|
||||||
|
(dominio.search("@") == -1) &&
|
||||||
|
(usuario.search(" ") == -1) &&
|
||||||
|
(dominio.search(" ") == -1) &&
|
||||||
|
(dominio.search(".") != -1) &&
|
||||||
|
(dominio.indexOf(".") >= 1) &&
|
||||||
|
(dominio.lastIndexOf(".") < dominio.length - 1))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearResult = () => {
|
||||||
|
lResult.error = '';
|
||||||
|
lResult.success = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fieldValidate = async () => {
|
||||||
|
clearResult();
|
||||||
|
|
||||||
|
if(!emailValidate()) {
|
||||||
|
lResult.error = 'O EMAIL é inválido!';
|
||||||
|
lResult.success = false;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
|
||||||
|
if(name != '' && email != '' && birthDate != '' && password != '' && confirmPassword != '') {
|
||||||
|
if(password === confirmPassword){
|
||||||
|
const signUpForm = {
|
||||||
|
name: firstName +' '+ lastName,
|
||||||
|
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; }>();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IonPage>
|
||||||
|
<IonHeader>
|
||||||
|
<IonToolbar>
|
||||||
|
<IonButtons slot="start">
|
||||||
|
<IonBackButton text={''} icon={arrowBack} defaultHref='mainpages' />
|
||||||
|
</IonButtons>
|
||||||
|
</IonToolbar>
|
||||||
|
</IonHeader>
|
||||||
|
<IonContent fullscreen>
|
||||||
|
<IonGrid className="ion-padding">
|
||||||
|
<IonRow>
|
||||||
|
<IonCol size="12">
|
||||||
|
{/* <IonCardTitle>Como você deseja se cadastrar?</IonCardTitle> */}
|
||||||
|
<IonCardTitle>Cadastro</IonCardTitle>
|
||||||
|
</IonCol>
|
||||||
|
</IonRow>
|
||||||
|
{/* <IonItem>
|
||||||
|
<IonIcon icon={logoFacebook} />
|
||||||
|
Continuar com Facebook
|
||||||
|
</IonItem>
|
||||||
|
<IonItem>
|
||||||
|
<IonIcon icon={mail} />
|
||||||
|
Continuar com e-mail
|
||||||
|
</IonItem> */}
|
||||||
|
<IonRow>
|
||||||
|
<IonCol size="12">
|
||||||
|
<div id='nome-sobrenome'>
|
||||||
|
<IonItem>
|
||||||
|
<IonLabel position='floating'>Nome</IonLabel>
|
||||||
|
<IonInput
|
||||||
|
type='text'
|
||||||
|
clearInput
|
||||||
|
onIonInput={(e: any) => setFirstName(e.target.value)}
|
||||||
|
>
|
||||||
|
</IonInput>
|
||||||
|
</IonItem>
|
||||||
|
<IonItem>
|
||||||
|
<IonLabel position='floating'>Sobrenome</IonLabel>
|
||||||
|
<IonInput
|
||||||
|
clearInput
|
||||||
|
onIonInput={(e: any) => setLastName(e.target.value)}
|
||||||
|
>
|
||||||
|
</IonInput>
|
||||||
|
</IonItem>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<IonItem>
|
||||||
|
<IonLabel position='floating'>E-mail</IonLabel>
|
||||||
|
<IonInput
|
||||||
|
clearInput
|
||||||
|
type='email'
|
||||||
|
onIonInput={(e: any) => setEmail(e.target.value)}
|
||||||
|
>
|
||||||
|
</IonInput>
|
||||||
|
</IonItem>
|
||||||
|
|
||||||
|
<IonItem>
|
||||||
|
<IonLabel position='stacked'>Data de nascimento</IonLabel>
|
||||||
|
<IonInput
|
||||||
|
type='date'
|
||||||
|
onIonInput={(e: any) => setBirthDate(e.target.value)}
|
||||||
|
>
|
||||||
|
</IonInput>
|
||||||
|
</IonItem>
|
||||||
|
|
||||||
|
<IonItem>
|
||||||
|
<IonLabel position='floating'>Senha</IonLabel>
|
||||||
|
<IonInput
|
||||||
|
clearInput
|
||||||
|
type='password'
|
||||||
|
onIonInput={(e: any) => setPassword(e.target.value)}
|
||||||
|
></IonInput>
|
||||||
|
</IonItem>
|
||||||
|
<IonItem>
|
||||||
|
<IonLabel position='floating'>Confirme a senha</IonLabel>
|
||||||
|
<IonInput
|
||||||
|
clearInput
|
||||||
|
type='password'
|
||||||
|
onIonInput={(e: any) => setConfirmPassword(e.target.value)}
|
||||||
|
></IonInput>
|
||||||
|
</IonItem>
|
||||||
|
|
||||||
|
<IonButton className="ion-margin-top" expand="block" onClick={ handleSubmit }>Cadastrar-se</IonButton>
|
||||||
|
</IonCol>
|
||||||
|
</IonRow>
|
||||||
|
<small className='ion-margin-top'>
|
||||||
|
Ao se cadastrar, você aceita nossos <a href="">Termos e Condições</a> e nossa <a href=""> Política de Privacidade</a>.
|
||||||
|
</small>
|
||||||
|
<Action message="Já tem conta?" text="Login" link="/login" />
|
||||||
|
</IonGrid>
|
||||||
|
{/* <IonProgressBar type="indeterminate"></IonProgressBar><br /> */}
|
||||||
|
<IonToast
|
||||||
|
// cssClass={"toast-notification"}
|
||||||
|
color='danger'
|
||||||
|
isOpen={showToast}
|
||||||
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
message={messageToast}
|
||||||
|
duration={2500}
|
||||||
|
/>
|
||||||
|
</IonContent>
|
||||||
|
</IonPage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Cadastro;
|
||||||
8
src/services/api.ts
Normal file
8
src/services/api.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import apiConfig from '../config/api.config';
|
||||||
|
|
||||||
|
const instance = axios.create({
|
||||||
|
baseURL: apiConfig.getBaseUrl(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default instance;
|
||||||
45
src/services/users.ts
Normal file
45
src/services/users.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import instance from '../services/api';
|
||||||
|
// import LocalStorage from '../LocalStorage';
|
||||||
|
|
||||||
|
let token:string;
|
||||||
|
let header:string;
|
||||||
|
|
||||||
|
function updateHeader() {
|
||||||
|
// token = LocalStorage.getToken();
|
||||||
|
header = `{
|
||||||
|
"Accept": 'application/json',
|
||||||
|
"Content-Type": 'application/json',
|
||||||
|
"Authorization": 'Bearer ' + token
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CadastroResponse {
|
||||||
|
message?: string;
|
||||||
|
|
||||||
|
token?: {
|
||||||
|
token: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CadastroRequest {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
birth_date: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// export async function get(cpf) {
|
||||||
|
// updateHeader();
|
||||||
|
|
||||||
|
// const response = await instance.get(userRoutes.get.url + `/${cpf}`, { headers: header });
|
||||||
|
// return response.data;
|
||||||
|
// }
|
||||||
|
|
||||||
|
export async function create(CadastroRequest: any) {
|
||||||
|
updateHeader();
|
||||||
|
|
||||||
|
const response = await instance.post("http://localhost:3333/users/", CadastroRequest);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user