Diversas melhorias e toasts aparecem em redirecionamentos de páginas
This commit is contained in:
@@ -8,6 +8,7 @@ import ModalExample from '../../components/Email';
|
|||||||
import * as UsersService from '../../services/api/users'
|
import * as UsersService from '../../services/api/users'
|
||||||
import LocalStorage from '../../LocalStorage';
|
import LocalStorage from '../../LocalStorage';
|
||||||
import { UserContext } from '../../App';
|
import { UserContext } from '../../App';
|
||||||
|
import { Color } from '@ionic/react/node_modules/@ionic/core';
|
||||||
|
|
||||||
const Cadastro: React.FC = () => {
|
const Cadastro: React.FC = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -15,7 +16,8 @@ const Cadastro: React.FC = () => {
|
|||||||
const user = useContext(UserContext);
|
const user = useContext(UserContext);
|
||||||
|
|
||||||
const [showToast, setShowToast] = useState(false);
|
const [showToast, setShowToast] = useState(false);
|
||||||
const [messageToast, setMessageToast ] = useState('');
|
const [messageToast, setMessageToast] = useState('');
|
||||||
|
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||||
|
|
||||||
const [email, setEmail] = useState<string>('');
|
const [email, setEmail] = useState<string>('');
|
||||||
const [password, setPassword] = useState<string>('');
|
const [password, setPassword] = useState<string>('');
|
||||||
@@ -57,7 +59,7 @@ const Cadastro: React.FC = () => {
|
|||||||
clearResult();
|
clearResult();
|
||||||
|
|
||||||
if(!emailValidate()) {
|
if(!emailValidate()) {
|
||||||
lResult.error = 'O EMAIL é inválido!';
|
lResult.error = 'E-mail inválido!';
|
||||||
lResult.success = false;
|
lResult.success = false;
|
||||||
return lResult;
|
return lResult;
|
||||||
} else if(password.length < 7 || password.length > 12) { //TODO: validar de acordo com a documentação
|
} else if(password.length < 7 || password.length > 12) { //TODO: validar de acordo com a documentação
|
||||||
@@ -70,9 +72,20 @@ const Cadastro: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
|
if(name === '' || email === '' || birthDate === '' || password === '' || confirmPassword === '') {
|
||||||
|
setToastColor("warning")
|
||||||
|
setMessageToast('Nenhum campo pode estar vazio!');
|
||||||
|
setShowToast(true);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if(password !== confirmPassword) {
|
||||||
|
setToastColor("warning")
|
||||||
|
setMessageToast('As senhas devem ser iguais!');
|
||||||
|
setShowToast(true);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if(name != '' && email != '' && birthDate != '' && password != '' && confirmPassword != '') {
|
|
||||||
if(password === confirmPassword){
|
|
||||||
const signUpForm = {
|
const signUpForm = {
|
||||||
name: firstName,
|
name: firstName,
|
||||||
lastname: lastName,
|
lastname: lastName,
|
||||||
@@ -82,38 +95,33 @@ const Cadastro: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = fieldValidate();
|
let result = fieldValidate();
|
||||||
if((await result).success) {
|
if(!(await result).success) {
|
||||||
|
setToastColor("warning")
|
||||||
|
setMessageToast(lResult.error);
|
||||||
|
setShowToast(true);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let retorno = await UsersService.create(signUpForm);
|
let retorno = await UsersService.create(signUpForm);
|
||||||
console.log(retorno);
|
|
||||||
if(retorno.token) {
|
if(!retorno.token) {
|
||||||
// let signIn = await Api.signIn(email, passwordField);
|
setToastColor('danger')
|
||||||
// if(signIn.token) {
|
setMessageToast(retorno.message);
|
||||||
// await AsyncStorage.setItem('token', signIn.token);
|
setShowToast(true);
|
||||||
// await AsyncStorage.setItem('cpf', retorno.cpf);
|
return
|
||||||
|
}
|
||||||
|
|
||||||
LocalStorage.setToken(retorno.token.token);
|
LocalStorage.setToken(retorno.token.token);
|
||||||
|
|
||||||
user.setIsLoggedIn(true);
|
user.setIsLoggedIn(true);
|
||||||
|
|
||||||
history.push('home');
|
history.push({ pathname: '/home', state: {
|
||||||
|
redirectData: {
|
||||||
} else {
|
showToastMessage: true,
|
||||||
setMessageToast(retorno.message);
|
toastColor: "success",
|
||||||
setShowToast(true);
|
toastMessage: "Usuário cadastrado com sucesso!",
|
||||||
}
|
|
||||||
} 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; }>();
|
||||||
@@ -135,14 +143,6 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonCardTitle>Cadastro</IonCardTitle>
|
<IonCardTitle>Cadastro</IonCardTitle>
|
||||||
</IonCol>
|
</IonCol>
|
||||||
</IonRow>
|
</IonRow>
|
||||||
{/* <IonItem>
|
|
||||||
<IonIcon icon={logoFacebook} />
|
|
||||||
Continuar com Facebook
|
|
||||||
</IonItem>
|
|
||||||
<IonItem>
|
|
||||||
<IonIcon icon={mail} />
|
|
||||||
Continuar com e-mail
|
|
||||||
</IonItem> */}
|
|
||||||
<IonRow>
|
<IonRow>
|
||||||
<IonCol size="12">
|
<IonCol size="12">
|
||||||
<div id='nome-sobrenome'>
|
<div id='nome-sobrenome'>
|
||||||
@@ -151,7 +151,7 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonInput
|
<IonInput
|
||||||
type='text'
|
type='text'
|
||||||
clearInput
|
clearInput
|
||||||
onIonInput={(e: any) => setFirstName(e.target.value)}
|
onIonChange={(e: any) => setFirstName(e.target.value)}
|
||||||
>
|
>
|
||||||
</IonInput>
|
</IonInput>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
@@ -159,7 +159,7 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonLabel position='floating'>Sobrenome</IonLabel>
|
<IonLabel position='floating'>Sobrenome</IonLabel>
|
||||||
<IonInput
|
<IonInput
|
||||||
clearInput
|
clearInput
|
||||||
onIonInput={(e: any) => setLastName(e.target.value)}
|
onIonChange={(e: any) => setLastName(e.target.value)}
|
||||||
>
|
>
|
||||||
</IonInput>
|
</IonInput>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
@@ -170,7 +170,7 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonInput
|
<IonInput
|
||||||
clearInput
|
clearInput
|
||||||
type='email'
|
type='email'
|
||||||
onIonInput={(e: any) => setEmail(e.target.value)}
|
onIonChange={(e: any) => setEmail(e.target.value)}
|
||||||
>
|
>
|
||||||
</IonInput>
|
</IonInput>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
@@ -179,7 +179,7 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonLabel position='stacked'>Data de nascimento</IonLabel>
|
<IonLabel position='stacked'>Data de nascimento</IonLabel>
|
||||||
<IonInput
|
<IonInput
|
||||||
type='date'
|
type='date'
|
||||||
onIonInput={(e: any) => setBirthDate(e.target.value)}
|
onIonChange={(e: any) => setBirthDate(e.target.value)}
|
||||||
>
|
>
|
||||||
</IonInput>
|
</IonInput>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
@@ -189,7 +189,7 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonInput
|
<IonInput
|
||||||
clearInput
|
clearInput
|
||||||
type='password'
|
type='password'
|
||||||
onIonInput={(e: any) => setPassword(e.target.value)}
|
onIonChange={(e: any) => setPassword(e.target.value)}
|
||||||
></IonInput>
|
></IonInput>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
<IonItem>
|
<IonItem>
|
||||||
@@ -197,7 +197,7 @@ const Cadastro: React.FC = () => {
|
|||||||
<IonInput
|
<IonInput
|
||||||
clearInput
|
clearInput
|
||||||
type='password'
|
type='password'
|
||||||
onIonInput={(e: any) => setConfirmPassword(e.target.value)}
|
onIonChange={(e: any) => setConfirmPassword(e.target.value)}
|
||||||
></IonInput>
|
></IonInput>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
|
|
||||||
@@ -210,9 +210,9 @@ 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
|
<IonToast
|
||||||
// cssClass={"toast-notification"}
|
color={toastColor}
|
||||||
color='danger'
|
|
||||||
isOpen={showToast}
|
isOpen={showToast}
|
||||||
onDidDismiss={() => setShowToast(false)}
|
onDidDismiss={() => setShowToast(false)}
|
||||||
message={messageToast}
|
message={messageToast}
|
||||||
|
|||||||
@@ -10,15 +10,25 @@ IonItem,
|
|||||||
IonLabel,
|
IonLabel,
|
||||||
IonPage,
|
IonPage,
|
||||||
IonTitle,
|
IonTitle,
|
||||||
|
IonToast,
|
||||||
IonToolbar
|
IonToolbar
|
||||||
} from "@ionic/react";
|
} from "@ionic/react";
|
||||||
import React, { useEffect, useReducer } from "react";
|
import React, { useEffect, useReducer, useState } from "react";
|
||||||
|
|
||||||
import '../Perfil.css'
|
import '../Perfil.css'
|
||||||
import { useHistory, useLocation } from "react-router";
|
import { useHistory, useLocation } from "react-router";
|
||||||
import { callOutline, documentTextOutline } from "ionicons/icons";
|
import { callOutline, documentTextOutline } from "ionicons/icons";
|
||||||
|
|
||||||
import '../Cadastro/Cadastro.css'
|
import '../Cadastro/Cadastro.css'
|
||||||
|
import { Color } from "@ionic/react/node_modules/@ionic/core";
|
||||||
|
|
||||||
|
interface cardItem {
|
||||||
|
icon: string;
|
||||||
|
label: string;
|
||||||
|
description: string;
|
||||||
|
url: string;
|
||||||
|
required: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface userData {
|
interface userData {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -32,15 +42,13 @@ interface userData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface LocationState {
|
interface LocationState {
|
||||||
userData: userData
|
userData: userData;
|
||||||
}
|
|
||||||
|
|
||||||
interface cardItem {
|
redirectData?: {
|
||||||
icon: string;
|
showToastMessage: boolean;
|
||||||
label: string;
|
toastColor: Color;
|
||||||
description: string;
|
toastMessage: string;
|
||||||
url: string;
|
}
|
||||||
required: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let items: cardItem[] = [
|
let items: cardItem[] = [
|
||||||
@@ -64,17 +72,31 @@ const CadastroCompletar: React.FC = () => {
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation<LocationState>();
|
const location = useLocation<LocationState>();
|
||||||
|
|
||||||
|
const [showToast, setShowToast] = useState(false);
|
||||||
|
const [toastMessage, setToastMessage] = useState('');
|
||||||
|
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||||
|
|
||||||
const handleCardClick = (item: cardItem) => {
|
const handleCardClick = (item: cardItem) => {
|
||||||
if (!item.required) return
|
if (!item.required) return
|
||||||
|
|
||||||
history.push({ pathname: item.url });
|
history.push({ pathname: item.url, state: { userData: location.state.userData } });
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!location.state) {
|
if (!location.state || !location.state.userData) {
|
||||||
history.push({ pathname: '/perfil' })
|
history.push({ pathname: '/perfil' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (location.state && location.state.redirectData) {
|
||||||
|
const redirectData = location.state.redirectData
|
||||||
|
|
||||||
|
if (redirectData.showToastMessage) {
|
||||||
|
setToastColor(redirectData.toastColor)
|
||||||
|
setToastMessage(redirectData.toastMessage)
|
||||||
|
setShowToast(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!location.state.userData.document) items[0].required = true
|
if (!location.state.userData.document) items[0].required = true
|
||||||
if (!location.state.userData.phone_number) items[1].required = true
|
if (!location.state.userData.phone_number) items[1].required = true
|
||||||
}, []);
|
}, []);
|
||||||
@@ -103,6 +125,15 @@ const CadastroCompletar: React.FC = () => {
|
|||||||
</IonCard>
|
</IonCard>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
<IonToast
|
||||||
|
position="top"
|
||||||
|
color={toastColor}
|
||||||
|
isOpen={showToast}
|
||||||
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
message={toastMessage}
|
||||||
|
duration={2500}
|
||||||
|
/>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,7 +34,24 @@ interface documentTypesInterface {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface userData {
|
||||||
|
name: string;
|
||||||
|
lastname: string;
|
||||||
|
email: string;
|
||||||
|
phone_number: string;
|
||||||
|
birth_date: string;
|
||||||
|
bio: string;
|
||||||
|
document_type: string;
|
||||||
|
document: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LocationState {
|
||||||
|
userData: userData;
|
||||||
|
}
|
||||||
|
|
||||||
const CompletarDocumento: React.FC = () => {
|
const CompletarDocumento: React.FC = () => {
|
||||||
|
const location = useLocation<LocationState>();
|
||||||
|
|
||||||
const [hasChangedSinceInitialState, setHasChangedSinceInitialState] = useState(false);
|
const [hasChangedSinceInitialState, setHasChangedSinceInitialState] = useState(false);
|
||||||
|
|
||||||
const [documentTypes, setDocumentTypes] = useState<documentTypesInterface[]>([]);
|
const [documentTypes, setDocumentTypes] = useState<documentTypesInterface[]>([]);
|
||||||
@@ -48,16 +65,8 @@ const CompletarDocumento: React.FC = () => {
|
|||||||
const [messageToast, setMessageToast] = useState('');
|
const [messageToast, setMessageToast] = useState('');
|
||||||
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!location.state) {
|
|
||||||
history.push({ pathname: '/perfil/completar' })
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const validateform = () => {
|
const validateform = () => {
|
||||||
console.log(document)
|
|
||||||
if (isNaN((Number)(document))) {
|
if (isNaN((Number)(document))) {
|
||||||
setMessageToast('Documento pode conter apenas números!')
|
setMessageToast('Documento pode conter apenas números!')
|
||||||
setShowToast(true)
|
setShowToast(true)
|
||||||
@@ -86,7 +95,13 @@ const CompletarDocumento: React.FC = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(response)
|
history.push({ pathname: '/perfil', state: {
|
||||||
|
redirectData: {
|
||||||
|
showToastMessage: true,
|
||||||
|
toastColor: "success",
|
||||||
|
toastMessage: response.message,
|
||||||
|
}
|
||||||
|
}})
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
setMessageToast(err);
|
setMessageToast(err);
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
@@ -111,6 +126,16 @@ const CompletarDocumento: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!location.state.userData) {
|
||||||
|
history.push({ pathname: '/perfil', state: {
|
||||||
|
redirectData: {
|
||||||
|
showToastMessage: true,
|
||||||
|
toastColor: "warning",
|
||||||
|
toastMessage: "Houve um erro. Por favor, tente novamente.",
|
||||||
|
}, userData: location.state.userData
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
setDocumentTypes([
|
setDocumentTypes([
|
||||||
{
|
{
|
||||||
name: 'cpf',
|
name: 'cpf',
|
||||||
@@ -178,6 +203,7 @@ const CompletarDocumento: React.FC = () => {
|
|||||||
</IonFab>
|
</IonFab>
|
||||||
|
|
||||||
<IonToast
|
<IonToast
|
||||||
|
position="top"
|
||||||
color='danger'
|
color='danger'
|
||||||
isOpen={showToast}
|
isOpen={showToast}
|
||||||
onDidDismiss={() => setShowToast(false)}
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ import {
|
|||||||
IonIcon,
|
IonIcon,
|
||||||
IonList,
|
IonList,
|
||||||
IonPage,
|
IonPage,
|
||||||
IonSelect,
|
|
||||||
IonSelectOption,
|
|
||||||
IonTitle,
|
IonTitle,
|
||||||
IonToast,
|
IonToast,
|
||||||
IonToolbar
|
IonToolbar
|
||||||
} from "@ionic/react";
|
} from "@ionic/react";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { IonGrid, IonRow, IonCol } from "@ionic/react";
|
import { IonGrid, IonRow, IonCol } from "@ionic/react";
|
||||||
import { useHistory, useLocation } from "react-router-dom";
|
import { useHistory, useLocation } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
@@ -26,28 +24,40 @@ import {
|
|||||||
import { saveOutline } from "ionicons/icons";
|
import { saveOutline } from "ionicons/icons";
|
||||||
|
|
||||||
import * as usersRoutes from '../../services/api/users';
|
import * as usersRoutes from '../../services/api/users';
|
||||||
|
import { Color } from "@ionic/react/node_modules/@ionic/core";
|
||||||
|
|
||||||
interface documentTypesInterface {
|
interface documentTypesInterface {
|
||||||
label: string;
|
label: string;
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface userData {
|
||||||
|
name: string;
|
||||||
|
lastname: string;
|
||||||
|
email: string;
|
||||||
|
phone_number: string;
|
||||||
|
birth_date: string;
|
||||||
|
bio: string;
|
||||||
|
document_type: string;
|
||||||
|
document: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LocationState {
|
||||||
|
userData: userData;
|
||||||
|
}
|
||||||
|
|
||||||
const CompletarTelefone: React.FC = () => {
|
const CompletarTelefone: React.FC = () => {
|
||||||
|
const location = useLocation<LocationState>();
|
||||||
|
|
||||||
const [hasChangedSinceInitialState, setHasChangedSinceInitialState] = useState(false);
|
const [hasChangedSinceInitialState, setHasChangedSinceInitialState] = useState(false);
|
||||||
|
|
||||||
const [phone, setPhone] = useState('');
|
const [phone, setPhone] = useState('');
|
||||||
|
|
||||||
const [showToast, setShowToast] = useState(false);
|
const [showToast, setShowToast] = useState(false);
|
||||||
const [messageToast, setMessageToast] = useState('');
|
const [messageToast, setMessageToast] = useState('');
|
||||||
|
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||||
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const location = useLocation();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!location.state) {
|
|
||||||
history.push({ pathname: '/perfil/completar' })
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const validateform = () => {
|
const validateform = () => {
|
||||||
if (isNaN((Number)(phone))) {
|
if (isNaN((Number)(phone))) {
|
||||||
@@ -66,19 +76,40 @@ const CompletarTelefone: React.FC = () => {
|
|||||||
|
|
||||||
usersRoutes.update({ phone_number: phone }).then(response => {
|
usersRoutes.update({ phone_number: phone }).then(response => {
|
||||||
if (response.status === 'error') {
|
if (response.status === 'error') {
|
||||||
|
setToastColor("warning")
|
||||||
setMessageToast(response.message);
|
setMessageToast(response.message);
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(response)
|
const userDataObj = location.state.userData
|
||||||
|
|
||||||
|
history.push({ pathname: '/perfil', state: {
|
||||||
|
redirectData: {
|
||||||
|
showToastMessage: true,
|
||||||
|
toastColor: "success",
|
||||||
|
toastMessage: response.message,
|
||||||
|
},
|
||||||
|
}})
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
setMessageToast(err);
|
setMessageToast(err);
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!location.state.userData) {
|
||||||
|
history.push({ pathname: '/perfil', state: {
|
||||||
|
redirectData: {
|
||||||
|
showToastMessage: true,
|
||||||
|
toastColor: "warning",
|
||||||
|
toastMessage: "Houve um erro. Por favor, tente novamente.",
|
||||||
|
}
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage>
|
<IonPage>
|
||||||
<IonHeader>
|
<IonHeader>
|
||||||
@@ -122,7 +153,8 @@ const CompletarTelefone: React.FC = () => {
|
|||||||
</IonFab>
|
</IonFab>
|
||||||
|
|
||||||
<IonToast
|
<IonToast
|
||||||
color='danger'
|
position="top"
|
||||||
|
color={toastColor}
|
||||||
isOpen={showToast}
|
isOpen={showToast}
|
||||||
onDidDismiss={() => setShowToast(false)}
|
onDidDismiss={() => setShowToast(false)}
|
||||||
message={messageToast}
|
message={messageToast}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
} from "@ionic/react";
|
} from "@ionic/react";
|
||||||
|
|
||||||
import React, { useEffect, useReducer, useState } from "react";
|
import React, { useEffect, useReducer, useState } from "react";
|
||||||
|
import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
// import * as yup from 'yup';
|
// import * as yup from 'yup';
|
||||||
|
|
||||||
@@ -27,10 +28,14 @@ import carsService from '../services/functions/carsService'
|
|||||||
import * as vansRoutes from '../services/api/vans';
|
import * as vansRoutes from '../services/api/vans';
|
||||||
|
|
||||||
import "./CadastroVan.css";
|
import "./CadastroVan.css";
|
||||||
|
import { Color } from "@ionic/react/node_modules/@ionic/core";
|
||||||
|
|
||||||
const CadastroVan: React.FC = () => {
|
const CadastroVan: React.FC = () => {
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const [showToast, setShowToast] = useState<boolean>(false);
|
const [showToast, setShowToast] = useState<boolean>(false);
|
||||||
const [toastMessage, setToastMessage] = useState<string>("");
|
const [toastMessage, setToastMessage] = useState<string>("");
|
||||||
|
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||||
|
|
||||||
const [carModels, setCarModels] = useState([{
|
const [carModels, setCarModels] = useState([{
|
||||||
id_model: '',
|
id_model: '',
|
||||||
@@ -174,8 +179,15 @@ const CadastroVan: React.FC = () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(response)
|
history.push({ pathname: '/perfil', state: {
|
||||||
|
redirectData: {
|
||||||
|
showToastMessage: true,
|
||||||
|
toastColor: "success",
|
||||||
|
toastMessage: response.message,
|
||||||
|
},
|
||||||
|
}})
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
setToastColor("danger")
|
||||||
setToastMessage(err);
|
setToastMessage(err);
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
})
|
})
|
||||||
@@ -188,7 +200,9 @@ const CadastroVan: React.FC = () => {
|
|||||||
const carModelsRes = await carsService.getAllCarModels()
|
const carModelsRes = await carsService.getAllCarModels()
|
||||||
|
|
||||||
if (carModelsRes.error) {
|
if (carModelsRes.error) {
|
||||||
console.log('Houve um erro')
|
setToastColor("danger")
|
||||||
|
setToastMessage(carModelsRes.error.errorMessage);
|
||||||
|
setShowToast(true);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,6 +347,15 @@ const CadastroVan: React.FC = () => {
|
|||||||
duration={2500}
|
duration={2500}
|
||||||
/>
|
/>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
|
|
||||||
|
<IonToast
|
||||||
|
position="top"
|
||||||
|
color={toastColor}
|
||||||
|
isOpen={showToast}
|
||||||
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
message={toastMessage}
|
||||||
|
duration={2500}
|
||||||
|
/>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +1,40 @@
|
|||||||
import { IonButton, IonContent, IonPage } from '@ionic/react';
|
import { IonContent, IonPage, IonToast } from '@ionic/react';
|
||||||
import { useContext, useEffect } from 'react';
|
import { Color } from '@ionic/react/node_modules/@ionic/core';
|
||||||
import { useHistory } from 'react-router';
|
import { useContext, useEffect, useState } from 'react';
|
||||||
|
import { useLocation } from 'react-router';
|
||||||
|
|
||||||
import { UserContext } from '../App';
|
import { UserContext } from '../App';
|
||||||
|
|
||||||
import * as sessionRoutes from '../services/api/session';
|
import * as sessionRoutes from '../services/api/session';
|
||||||
|
|
||||||
|
interface LocationState {
|
||||||
|
redirectData?: {
|
||||||
|
showToastMessage: boolean;
|
||||||
|
toastColor: Color;
|
||||||
|
toastMessage: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Home: React.FC = () => {
|
const Home: React.FC = () => {
|
||||||
const history = useHistory()
|
const location = useLocation<LocationState>();
|
||||||
|
|
||||||
const user = useContext(UserContext);
|
const user = useContext(UserContext);
|
||||||
|
|
||||||
|
const [showToast, setShowToast] = useState(false);
|
||||||
|
const [toastMessage, setToastMessage] = useState('');
|
||||||
|
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (location.state && location.state.redirectData) {
|
||||||
|
const redirectData = location.state.redirectData
|
||||||
|
|
||||||
|
if (redirectData.showToastMessage) {
|
||||||
|
setToastColor(redirectData.toastColor)
|
||||||
|
setToastMessage(redirectData.toastMessage)
|
||||||
|
setShowToast(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const refreshUserToken = async () => {
|
const refreshUserToken = async () => {
|
||||||
await sessionRoutes.refresh().then(response => {
|
await sessionRoutes.refresh().then(response => {
|
||||||
if (response.status === 'error') {
|
if (response.status === 'error') {
|
||||||
@@ -33,12 +56,19 @@ const Home: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refreshUserToken()
|
refreshUserToken()
|
||||||
})
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IonPage>
|
<IonPage>
|
||||||
<IonContent>
|
<IonContent>
|
||||||
{/* <IonButton onClick={() => { history.push({ pathname: '/usuario/56520ae7-faf8-4444-a82b-7f3990ab02d8' }); }}>Ir para o perfil de outra pessoa</IonButton> */}
|
<IonToast
|
||||||
|
position="top"
|
||||||
|
color={toastColor}
|
||||||
|
isOpen={showToast}
|
||||||
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
message={toastMessage}
|
||||||
|
duration={2500}
|
||||||
|
/>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -89,7 +89,11 @@ const Page: React.FC = () => {
|
|||||||
|
|
||||||
user.setIsLoggedIn(true);
|
user.setIsLoggedIn(true);
|
||||||
|
|
||||||
history.push({ pathname: '/home' });
|
history.push({ pathname: '/home', state: { redirectData: {
|
||||||
|
showToastMessage: true,
|
||||||
|
toastColor: "success",
|
||||||
|
toastMessage: "Usuário autenticado com sucesso!",
|
||||||
|
}}})
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
// if (!error.response) return
|
// if (!error.response) return
|
||||||
|
|
||||||
@@ -155,7 +159,7 @@ const Page: React.FC = () => {
|
|||||||
</IonGrid>
|
</IonGrid>
|
||||||
|
|
||||||
<IonToast
|
<IonToast
|
||||||
// cssClass={"toast-notification"}
|
position="top"
|
||||||
color='danger'
|
color='danger'
|
||||||
isOpen={showToast}
|
isOpen={showToast}
|
||||||
onDidDismiss={() => setShowToast(false)}
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
IonBackButton,
|
IonBackButton,
|
||||||
|
IonBadge,
|
||||||
IonButtons,
|
IonButtons,
|
||||||
IonCard,
|
IonCard,
|
||||||
IonCardContent,
|
IonCardContent,
|
||||||
@@ -18,7 +19,7 @@ import {
|
|||||||
IonToast,
|
IonToast,
|
||||||
IonToolbar,
|
IonToolbar,
|
||||||
} from "@ionic/react";
|
} from "@ionic/react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory, useLocation } from "react-router-dom";
|
||||||
import React, { useState, useEffect, useReducer, useContext } from "react";
|
import React, { useState, useEffect, useReducer, useContext } from "react";
|
||||||
import { callOutline, cardOutline, carOutline, createOutline, exitOutline, logoFacebook, logoWhatsapp, shieldCheckmarkOutline, starOutline } from "ionicons/icons";
|
import { callOutline, cardOutline, carOutline, createOutline, exitOutline, logoFacebook, logoWhatsapp, shieldCheckmarkOutline, starOutline } from "ionicons/icons";
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ import LocalStorage from "../LocalStorage";
|
|||||||
import sessionsService from '../services/functions/sessionsService'
|
import sessionsService from '../services/functions/sessionsService'
|
||||||
import usersService from '../services/functions/usersService'
|
import usersService from '../services/functions/usersService'
|
||||||
import { UserContext } from "../App";
|
import { UserContext } from "../App";
|
||||||
|
import { Color } from "@ionic/react/node_modules/@ionic/core";
|
||||||
|
|
||||||
interface ScanNewProps {
|
interface ScanNewProps {
|
||||||
match: {
|
match: {
|
||||||
@@ -37,15 +39,28 @@ interface ScanNewProps {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface LocationState {
|
||||||
|
redirectData?: {
|
||||||
|
showToastMessage: boolean;
|
||||||
|
toastColor: Color;
|
||||||
|
toastMessage: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const Perfil: React.FC<ScanNewProps> = (props) => {
|
const Perfil: React.FC<ScanNewProps> = (props) => {
|
||||||
const user = useContext(UserContext);
|
const user = useContext(UserContext);
|
||||||
|
|
||||||
|
const history = useHistory();
|
||||||
|
const location = useLocation<LocationState>();
|
||||||
|
|
||||||
const [isVisitor, setIsVisitor] = useState(true)
|
const [isVisitor, setIsVisitor] = useState(true)
|
||||||
|
|
||||||
const [incompleteProfile, setIncompleteProfile] = useState(false)
|
const [incompleteProfile, setIncompleteProfile] = useState(false)
|
||||||
|
const [incompleteProfileCounter, setIncompleteProfileCounter] = useState(0)
|
||||||
|
|
||||||
const [showToast, setShowToast] = useState(false);
|
const [showToast, setShowToast] = useState(false);
|
||||||
const [messageToast, setMessageToast] = useState('');
|
const [toastMessage, setToastMessage] = useState('');
|
||||||
|
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||||
|
|
||||||
const [inputValues, setInputValues] = useReducer(
|
const [inputValues, setInputValues] = useReducer(
|
||||||
(state: any, newState: any) => ({ ...state, ...newState }),
|
(state: any, newState: any) => ({ ...state, ...newState }),
|
||||||
@@ -62,12 +77,10 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const history = useHistory();
|
|
||||||
|
|
||||||
const redirectUserToLogin = () => {
|
const redirectUserToLogin = () => {
|
||||||
// TODO, não impede o usuário de retornar a página de login
|
// TODO, não impede o usuário de retornar a página de login
|
||||||
history.push({ pathname: '/login' });
|
history.push({ pathname: '/login' });
|
||||||
setMessageToast("Por favor, autentique-se!");
|
setToastMessage("Por favor, autentique-se!");
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +91,16 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (location.state && location.state.redirectData) {
|
||||||
|
const redirectData = location.state.redirectData
|
||||||
|
|
||||||
|
if (redirectData.showToastMessage) {
|
||||||
|
setToastColor(redirectData.toastColor)
|
||||||
|
setToastMessage(redirectData.toastMessage)
|
||||||
|
setShowToast(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const loadUserData = async () => {
|
const loadUserData = async () => {
|
||||||
let userId = ''
|
let userId = ''
|
||||||
|
|
||||||
@@ -102,11 +125,11 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
|
|
||||||
if (getByIdRes.error) {
|
if (getByIdRes.error) {
|
||||||
if (isVisitor && props.match.params.id) {
|
if (isVisitor && props.match.params.id) {
|
||||||
setMessageToast('Usuário não existe!')
|
setToastMessage('Usuário não existe!')
|
||||||
setShowToast(true)
|
setShowToast(true)
|
||||||
history.push({ pathname: '/home' })
|
history.push({ pathname: '/home' })
|
||||||
} else {
|
} else {
|
||||||
setMessageToast(getByIdRes.error.errorMessage)
|
setToastMessage(getByIdRes.error.errorMessage)
|
||||||
setShowToast(true)
|
setShowToast(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +158,13 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
|
|
||||||
if (!userData.document || !userData.phone_number) {
|
if (!userData.document || !userData.phone_number) {
|
||||||
setIncompleteProfile(true)
|
setIncompleteProfile(true)
|
||||||
|
|
||||||
|
let counter = 0
|
||||||
|
|
||||||
|
if (!userData.document) counter++
|
||||||
|
if (!userData.phone_number) counter++
|
||||||
|
|
||||||
|
setIncompleteProfileCounter(counter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,8 +203,8 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
|
|
||||||
<IonCard>
|
<IonCard>
|
||||||
<IonCardContent>
|
<IonCardContent>
|
||||||
{/* <img src="https://static.generated.photos/vue-static/home/feed/adult.png" alt="avatar" className='avatar' id='avatar'/> */}
|
<img src="https://static.generated.photos/vue-static/home/feed/adult.png" alt="avatar" className='avatar' id='avatar'/>
|
||||||
<img src="https://lastfm.freetls.fastly.net/i/u/avatar170s/faa68f71f3b2a48ca89228c2c2aa72d3" alt="avatar" className='avatar' id='avatar'/>
|
{/* <img src="https://lastfm.freetls.fastly.net/i/u/avatar170s/faa68f71f3b2a48ca89228c2c2aa72d3" alt="avatar" className='avatar' id='avatar'/> */}
|
||||||
<IonCardHeader>
|
<IonCardHeader>
|
||||||
<IonCardTitle class="ion-text-center">{inputValues.name} {inputValues.lastname}</IonCardTitle>
|
<IonCardTitle class="ion-text-center">{inputValues.name} {inputValues.lastname}</IonCardTitle>
|
||||||
</IonCardHeader>
|
</IonCardHeader>
|
||||||
@@ -232,6 +262,7 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
<IonItem button onClick={() => history.push({ pathname: '/perfil/completar', state: { userData: inputValues } })}>
|
<IonItem button onClick={() => history.push({ pathname: '/perfil/completar', state: { userData: inputValues } })}>
|
||||||
<IonIcon icon={shieldCheckmarkOutline} slot="start" />
|
<IonIcon icon={shieldCheckmarkOutline} slot="start" />
|
||||||
<IonLabel>Completar cadastro</IonLabel>
|
<IonLabel>Completar cadastro</IonLabel>
|
||||||
|
<IonBadge color="primary">{incompleteProfileCounter}</IonBadge>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
</>
|
</>
|
||||||
: <></> }
|
: <></> }
|
||||||
@@ -256,10 +287,11 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<IonToast
|
<IonToast
|
||||||
color='danger'
|
position="top"
|
||||||
|
color={toastColor}
|
||||||
isOpen={showToast}
|
isOpen={showToast}
|
||||||
onDidDismiss={() => setShowToast(false)}
|
onDidDismiss={() => setShowToast(false)}
|
||||||
message={messageToast}
|
message={toastMessage}
|
||||||
duration={2500}
|
duration={2500}
|
||||||
/>
|
/>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import isEqual from 'lodash.isequal';
|
|||||||
import * as usersRoutes from '../services/api/users';
|
import * as usersRoutes from '../services/api/users';
|
||||||
|
|
||||||
import './Cadastro/Cadastro.css'
|
import './Cadastro/Cadastro.css'
|
||||||
|
import { Color } from "@ionic/react/node_modules/@ionic/core";
|
||||||
|
|
||||||
interface userData {
|
interface userData {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -47,6 +48,7 @@ const PerfilEditar: React.FC = () => {
|
|||||||
|
|
||||||
const [showToast, setShowToast] = useState(false);
|
const [showToast, setShowToast] = useState(false);
|
||||||
const [messageToast, setMessageToast] = useState('');
|
const [messageToast, setMessageToast] = useState('');
|
||||||
|
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||||
|
|
||||||
const [userData, setUserData] = useState({
|
const [userData, setUserData] = useState({
|
||||||
name: '',
|
name: '',
|
||||||
@@ -87,14 +89,18 @@ const PerfilEditar: React.FC = () => {
|
|||||||
const handleUpdateUserData = () => {
|
const handleUpdateUserData = () => {
|
||||||
usersRoutes.update(inputValues).then(response => {
|
usersRoutes.update(inputValues).then(response => {
|
||||||
if (response.status === 'error') {
|
if (response.status === 'error') {
|
||||||
|
setToastColor("danger")
|
||||||
setMessageToast(response.message);
|
setMessageToast(response.message);
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(response)
|
setToastColor("success")
|
||||||
|
setMessageToast(response.message);
|
||||||
|
setShowToast(true);
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
setToastColor("danger")
|
||||||
setMessageToast(err);
|
setMessageToast(err);
|
||||||
setShowToast(true);
|
setShowToast(true);
|
||||||
})
|
})
|
||||||
@@ -176,7 +182,7 @@ const PerfilEditar: React.FC = () => {
|
|||||||
</IonFab>
|
</IonFab>
|
||||||
|
|
||||||
<IonToast
|
<IonToast
|
||||||
color='danger'
|
color={toastColor}
|
||||||
isOpen={showToast}
|
isOpen={showToast}
|
||||||
onDidDismiss={() => setShowToast(false)}
|
onDidDismiss={() => setShowToast(false)}
|
||||||
message={messageToast}
|
message={messageToast}
|
||||||
|
|||||||
Reference in New Issue
Block a user