diff --git a/src/components/Action.tsx b/src/components/Action.tsx index 8384042..e584295 100644 --- a/src/components/Action.tsx +++ b/src/components/Action.tsx @@ -1,17 +1,19 @@ import { IonCol, IonRouterLink, IonRow } from "@ionic/react"; interface ComponentProps { - message: string, - link: string, - text: string + message: string; + link: string; + text: string; } export const Action = (props: ComponentProps) => ( - - - - { props.message } - { props.text } → - - -); \ No newline at end of file + + + {props.message} + + {" "} + {props.text} → + + + +); diff --git a/src/components/PageHeader.tsx b/src/components/PageHeader.tsx new file mode 100644 index 0000000..7069b8f --- /dev/null +++ b/src/components/PageHeader.tsx @@ -0,0 +1,17 @@ +import { IonBackButton, IonButtons, IonHeader, IonTitle, IonToolbar } from "@ionic/react"; + +interface ComponentProps { + pageName: string; + backButtonPageUrl?: string; +} + +export const PageHeader = (props: ComponentProps) => ( + + + {props.pageName} + + + + + +); diff --git a/src/pages/BuscarItinerario.tsx b/src/pages/BuscarItinerario.tsx index 603fdad..acb5a48 100644 --- a/src/pages/BuscarItinerario.tsx +++ b/src/pages/BuscarItinerario.tsx @@ -1,16 +1,21 @@ import { + IonBackButton, IonButton, + IonButtons, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, + IonHeader, IonIcon, IonItem, IonItemDivider, IonPage, IonRow, + IonTitle, + IonToolbar, } from "@ionic/react"; import { arrowForwardOutline, @@ -34,6 +39,7 @@ import GooglePlacesAutocomplete, { getLatLng, } from "react-google-places-autocomplete"; import { Itinerary } from "../models/itinerary.model"; +import { PageHeader } from "../components/PageHeader"; const BuscarItinerario: React.FC = () => { const history = useHistory(); @@ -108,6 +114,11 @@ const BuscarItinerario: React.FC = () => { return ( + + @@ -156,7 +167,7 @@ const BuscarItinerario: React.FC = () => { - Pesquisas recentes + Pesquisas recentes { {itinerariesList ? ( <> - Resultados + Resultados {itinerariesList.map((itinerary, index) => { return ( { history.push(`/itinerary/${itinerary.id_itinerary}`) }}> diff --git a/src/pages/BuscarItinerarioList.tsx b/src/pages/BuscarItinerarioList.tsx index dac430c..3135171 100644 --- a/src/pages/BuscarItinerarioList.tsx +++ b/src/pages/BuscarItinerarioList.tsx @@ -25,6 +25,7 @@ import { cashOutline, personOutline, starOutline } from "ionicons/icons"; import { useEffect, useState } from "react"; import { useHistory } from "react-router"; +import { PageHeader } from "../components/PageHeader"; interface coordinates { lat: number; @@ -109,14 +110,10 @@ const BuscarItinerario: React.FC = () => { return ( - - - Buscar itinerários - - - - - + {/* diff --git a/src/pages/BuscarPassageiro/BuscarPassageiro.tsx b/src/pages/BuscarPassageiro/BuscarPassageiro.tsx index b03819d..5673045 100644 --- a/src/pages/BuscarPassageiro/BuscarPassageiro.tsx +++ b/src/pages/BuscarPassageiro/BuscarPassageiro.tsx @@ -1,127 +1,163 @@ -import { IonContent, IonPage, IonFab, IonFabButton, IonIcon } from '@ionic/react'; -import { search } from 'ionicons/icons'; -import './BuscarPassageiro.css'; +import { + IonContent, + IonPage, + IonFab, + IonFabButton, + IonIcon, +} from "@ionic/react"; +import { search } from "ionicons/icons"; +import "./BuscarPassageiro.css"; import { Map, Marker, Overlay } from "pigeon-maps"; -import { maptiler } from 'pigeon-maps/providers'; -import { useEffect, useState } from 'react'; +import { maptiler } from "pigeon-maps/providers"; +import { useEffect, useState } from "react"; -import RecordsStore from '../../store/RecordsStore'; -import { fetchRecords } from '../../store/Selectors'; -import { getUsersSearching } from '../../services/api/users'; -import { UserSearchInfos } from '../../components/UserSearchInfos/UserSearchInfos'; +import RecordsStore from "../../store/RecordsStore"; +import { fetchRecords } from "../../store/Selectors"; +import { getUsersSearching } from "../../services/api/users"; +import { UserSearchInfos } from "../../components/UserSearchInfos/UserSearchInfos"; +import { PageHeader } from "../../components/PageHeader"; -const maptilerProvider = maptiler('d5JQJPLLuap8TkJJlTdJ', 'streets'); +const maptilerProvider = maptiler("d5JQJPLLuap8TkJJlTdJ", "streets"); const BuscarPassageiro: React.FC = () => { + // UNCOMMENT THESE TO USE CURRENT LOCATION. - // UNCOMMENT THESE TO USE CURRENT LOCATION. + // const [ currentPoint, setCurrentPoint ] = useState(false); - // const [ currentPoint, setCurrentPoint ] = useState(false); + // useEffect(() => { - // useEffect(() => { + // const getCurrentLocation = async () => { - // const getCurrentLocation = async () => { + // const fetchedLocation = await getLocation(); + // setCurrentPoint(fetchedLocation.currentLocation); + // } - // const fetchedLocation = await getLocation(); - // setCurrentPoint(fetchedLocation.currentLocation); - // } + // getCurrentLocation(); + // }, []); - // getCurrentLocation(); - // }, []); + // useIonViewWillEnter(() => { - // useIonViewWillEnter(() => { + // getUsersSearching(currentPoint); + // }); - // getUsersSearching(currentPoint); - // }); + const [currentPoint, setCurrentPoint] = useState({ + latitude: -22.907829, + longitude: -47.062943, + }); - const [ currentPoint, setCurrentPoint ] = useState({ latitude: -22.907829, longitude: -47.062943 }); + const records = RecordsStore.useState(fetchRecords); + const center = { latitude: -22.907829, longitude: -47.062943 }; - const records = RecordsStore.useState(fetchRecords); - const center = { latitude: -22.907829, longitude: -47.062943 }; + const [results, setResults] = useState([]); + const [zoom, setZoom] = useState(14); - const [ results, setResults ] = useState([]); - const [ zoom, setZoom ] = useState(14); + const [moveMode, setMoveMode] = useState(false); - const [ moveMode, setMoveMode ] = useState(false); + // useEffect(() => { - // useEffect(() => { + // const getData = async () => { - // const getData = async () => { + // await getUsersSearching(currentPoint); + // } - // await getUsersSearching(currentPoint); - // } + // getData(); + // }, [ currentPoint ]); - // getData(); - // }, [ currentPoint ]); + useEffect(() => { + setResults(records); + }, [records]); - useEffect(() => { + const hideMarkers = () => { + console.log("entrou"); + const tempRecords = JSON.parse(JSON.stringify(results)); + tempRecords.forEach((tempRecord: any) => (tempRecord.showInfo = false)); + console.log(tempRecords); + setResults(tempRecords); + }; - setResults(records); - }, [ records ]); - - const hideMarkers = () => { - console.log('entrou') - const tempRecords = JSON.parse(JSON.stringify(results)); - tempRecords.forEach((tempRecord:any) => tempRecord.showInfo = false); - console.log(tempRecords) - setResults(tempRecords); - } - - const handleMap = (e:any) => { + const handleMap = (e: any) => { setCurrentPoint({ latitude: e.center[0], longitude: e.center[1] }); - } + }; const searchResults = async () => { await getUsersSearching(currentPoint); - } + }; - const showMarkerInfo = (e:any, index:any) => { + const showMarkerInfo = (e: any, index: any) => { + const tempRecords = JSON.parse(JSON.stringify(results)); - const tempRecords = JSON.parse(JSON.stringify(results)); + // Hide all current marker infos + !tempRecords[index].showInfo && + tempRecords.forEach((tempRecord: any) => (tempRecord.showInfo = false)); + tempRecords[index].showInfo = !tempRecords[index].showInfo; - // Hide all current marker infos - !tempRecords[index].showInfo && tempRecords.forEach((tempRecord:any) => tempRecord.showInfo = false); - tempRecords[index].showInfo = !tempRecords[index].showInfo; - - console.log(tempRecords) - setResults(tempRecords); - } + console.log(tempRecords); + setResults(tempRecords); + }; return ( - - {/* { results && + + + {/* { results && <> */} - handleMap(e)} defaultCenter={ [center.latitude, center.longitude] } defaultZoom={ zoom } provider={ maptilerProvider } touchEvents={ true }> + handleMap(e)} + defaultCenter={[center.latitude, center.longitude]} + defaultZoom={zoom} + provider={maptilerProvider} + touchEvents={true} + > + {results && + results.map( + (record: { latitude_from: any; longitude_from: any }, index) => { + return ( + showMarkerInfo(e, index)} + key={index} + color="#3578e5" + width={50} + anchor={[ + parseFloat(record.latitude_from), + parseFloat(record.longitude_from), + ]} + /> + ); + } + )} - {results && results.map((record:{latitude_from:any, longitude_from:any}, index) => { - return showMarkerInfo(e, index) } key={ index } color="#3578e5" width={ 50 } anchor={ [ parseFloat(record.latitude_from), parseFloat(record.longitude_from) ] } /> - })} + {results.map((record: any, index) => { + if (record.showInfo) { + return ( + + + + ); + } + })} + - { results.map((record:any, index) => { - - if (record.showInfo) { - - return ( - - - - ) - } - })} - - - - - - - - {/* */} - {/* } */} - - + + + + + + {/* */} + {/* } */} + + ); }; -export default BuscarPassageiro; \ No newline at end of file +export default BuscarPassageiro; diff --git a/src/pages/Buscas.tsx b/src/pages/Buscas.tsx index f6c2623..073fb2a 100644 --- a/src/pages/Buscas.tsx +++ b/src/pages/Buscas.tsx @@ -2,6 +2,7 @@ import { IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, import { useEffect, useState } from "react"; import { useHistory } from "react-router"; +import { PageHeader } from "../components/PageHeader"; const Buscas: React.FC = () => { useEffect(() => {}, []); @@ -9,11 +10,9 @@ const Buscas: React.FC = () => { return ( - - - Buscas - - + history.push({ pathname: "/buscar/itinerario"}) }> diff --git a/src/pages/CadastrarItinerario/CadastrarItinerario.tsx b/src/pages/CadastrarItinerario/CadastrarItinerario.tsx index c7dd740..8bf2ab4 100644 --- a/src/pages/CadastrarItinerario/CadastrarItinerario.tsx +++ b/src/pages/CadastrarItinerario/CadastrarItinerario.tsx @@ -20,25 +20,19 @@ import { import { close, locateOutline, locationOutline } from "ionicons/icons"; import { useState } from "react"; import GooglePlacesAutocomplete from "react-google-places-autocomplete"; +import { PageHeader } from "../../components/PageHeader"; export default function CadastrarItinerario() { const [selected, setSelected] = useState(""); return ( - - - - - - - + + - - - Cadastrar Itinerário - -
diff --git a/src/pages/Cadastro/Cadastro.tsx b/src/pages/Cadastro/Cadastro.tsx index feb513c..7252f1a 100644 --- a/src/pages/Cadastro/Cadastro.tsx +++ b/src/pages/Cadastro/Cadastro.tsx @@ -10,6 +10,7 @@ import LocalStorage from '../../LocalStorage'; import { UserContext } from '../../App'; import { Color } from '@ionic/core'; import { closeToast } from '../../services/utils'; +import { PageHeader } from '../../components/PageHeader'; const Cadastro: React.FC = () => { const history = useHistory(); @@ -129,13 +130,11 @@ const Cadastro: React.FC = () => { return ( - - - - - - - + + diff --git a/src/pages/CadastroCompletar/CadastroCompletar.tsx b/src/pages/CadastroCompletar/CadastroCompletar.tsx index 4840328..5a61719 100644 --- a/src/pages/CadastroCompletar/CadastroCompletar.tsx +++ b/src/pages/CadastroCompletar/CadastroCompletar.tsx @@ -22,6 +22,7 @@ import { callOutline, documentTextOutline } from "ionicons/icons"; import '../Cadastro/Cadastro.css' import { Color } from "@ionic/core"; import { closeToast } from "../../services/utils"; +import { PageHeader } from "../../components/PageHeader"; interface cardItem { icon: string; @@ -104,14 +105,10 @@ const CadastroCompletar: React.FC = () => { return ( - - - Completar cadastro - - - - - + { items.map((item, index) => { diff --git a/src/pages/CadastroCompletar/CompletarDocumento.tsx b/src/pages/CadastroCompletar/CompletarDocumento.tsx index 892a259..158f9e8 100644 --- a/src/pages/CadastroCompletar/CompletarDocumento.tsx +++ b/src/pages/CadastroCompletar/CompletarDocumento.tsx @@ -29,6 +29,7 @@ import * as usersRoutes from '../../services/api/users'; import validateCpf from '../../services/validateCpf' import { closeToast } from "../../services/utils"; +import { PageHeader } from "../../components/PageHeader"; interface documentTypesInterface { label: string; @@ -155,22 +156,12 @@ const CompletarDocumento: React.FC = () => { return ( - - - Completar cadastro - - - - - + - - - Completar cadastro - - - diff --git a/src/pages/CadastroCompletar/CompletarTelefone.tsx b/src/pages/CadastroCompletar/CompletarTelefone.tsx index 353547d..05e69b1 100644 --- a/src/pages/CadastroCompletar/CompletarTelefone.tsx +++ b/src/pages/CadastroCompletar/CompletarTelefone.tsx @@ -26,6 +26,7 @@ import { saveOutline } from "ionicons/icons"; import * as usersRoutes from '../../services/api/users'; import { Color } from "@ionic/core"; import { closeToast } from "../../services/utils"; +import { PageHeader } from "../../components/PageHeader"; interface documentTypesInterface { label: string; @@ -113,22 +114,12 @@ const CompletarTelefone: React.FC = () => { return ( - - - Completar cadastro - - - - - + - - - Completar cadastro - - - diff --git a/src/pages/CadastroVan.tsx b/src/pages/CadastroVan.tsx index 02e927c..d3eac23 100644 --- a/src/pages/CadastroVan.tsx +++ b/src/pages/CadastroVan.tsx @@ -30,6 +30,7 @@ import * as vansRoutes from '../services/api/vans'; import "./CadastroVan.css"; import { Color } from "@ionic/core"; import { closeToast } from "../services/utils"; +import { PageHeader } from "../components/PageHeader"; const CadastroVan: React.FC = () => { const history = useHistory(); @@ -241,14 +242,10 @@ const CadastroVan: React.FC = () => { return ( - - - Cadastro de veículo - - - - - + diff --git a/src/pages/Debug.tsx b/src/pages/Debug.tsx index 41ae278..fbda950 100644 --- a/src/pages/Debug.tsx +++ b/src/pages/Debug.tsx @@ -1,60 +1,58 @@ import { - IonContent, - IonHeader, - IonPage, - IonTitle, - IonToolbar - } from "@ionic/react"; - import React, { useContext, useState } from "react"; - import { IonGrid, IonRow, IonCol, IonToast } from "@ionic/react"; - import { useHistory } from "react-router-dom"; - import { - IonItem, - IonLabel, - IonInput, - IonButton, - } from "@ionic/react"; + IonContent, + IonHeader, + IonPage, + IonTitle, + IonToolbar, +} from "@ionic/react"; +import React, { useContext, useState } from "react"; +import { IonGrid, IonRow, IonCol, IonToast } from "@ionic/react"; +import { useHistory } from "react-router-dom"; +import { IonItem, IonLabel, IonInput, IonButton } from "@ionic/react"; - import { UserContext } from "../App"; - - const Debug: React.FC = () => { - const [input, setInput] = useState(''); - - return ( - - +import { UserContext } from "../App"; +import { PageHeader } from "../components/PageHeader"; + +const Debug: React.FC = () => { + const [input, setInput] = useState(""); + + return ( + + + + + - Debug + Debug - - - - - Debug - - - - - - - - Input - { setInput(e.detail.value!) }} - > - - { setInput('1994-12-15'); console.log(input) }}>Enviar - - - - - - ); - }; - - export default Debug; - \ No newline at end of file + + + + + Input + { setInput(e.detail.value!) }} + > + + + { + setInput("1994-12-15"); + console.log(input); + }} + > + Enviar + + + + + + + ); +}; + +export default Debug; diff --git a/src/pages/Itinerario.tsx b/src/pages/Itinerario.tsx index 558a199..d6f5309 100644 --- a/src/pages/Itinerario.tsx +++ b/src/pages/Itinerario.tsx @@ -1,22 +1,40 @@ -import { IonBackButton, IonButtons, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonPage, IonTitle, IonToast, IonToolbar } from '@ionic/react'; -import { Color } from '@ionic/core'; -import { carOutline } from 'ionicons/icons'; -import { useContext, useEffect, useState } from 'react'; -import { useHistory, useLocation } from 'react-router'; +import { + IonBackButton, + IonButtons, + IonCard, + IonCardContent, + IonCardHeader, + IonCardSubtitle, + IonCardTitle, + IonContent, + IonHeader, + IonIcon, + IonItem, + IonLabel, + IonPage, + IonTitle, + IonToast, + IonToolbar, +} from "@ionic/react"; +import { Color } from "@ionic/core"; +import { carOutline } from "ionicons/icons"; +import { useContext, useEffect, useState } from "react"; +import { useHistory, useLocation } from "react-router"; -import { UserContext } from '../App'; +import { UserContext } from "../App"; -import * as vansRoutes from '../services/api/vans'; +import * as vansRoutes from "../services/api/vans"; -import sessionsService from '../services/functions/sessionsService' -import { closeToast } from '../services/utils'; +import sessionsService from "../services/functions/sessionsService"; +import { closeToast } from "../services/utils"; +import { PageHeader } from "../components/PageHeader"; interface VanInfo { plate: string; brand: string; model: string; seats_number: string; - document_status: boolean, + document_status: boolean; locator_name: string; locator_address: string; locator_complement: string; @@ -28,90 +46,100 @@ const Itinerario: React.FC = () => { const history = useHistory(); const [showToast, setShowToast] = useState(false); - const [toastMessage, setToastMessage] = useState(''); + const [toastMessage, setToastMessage] = useState(""); const [toastColor, setToastColor] = useState("primary"); const [userVans, setUserVans] = useState(); const redirectUserToLogin = () => { - history.push({ pathname: '/login' }); - } + history.push({ pathname: "/login" }); + }; useEffect(() => { const getUserVans = async () => { - let userId = '' + let userId = ""; + + const refreshSessionRes = await sessionsService.refreshSession(); - const refreshSessionRes = await sessionsService.refreshSession() - if (refreshSessionRes.error) { - redirectUserToLogin() - return + redirectUserToLogin(); + return; } - + if (refreshSessionRes.userId) { - userId = refreshSessionRes.userId + userId = refreshSessionRes.userId; } - vansRoutes.getByUserId(userId).then(response => { - if (response.status === 'error') { - setToastColor("danger") - setToastMessage(response.message); - setShowToast(true); - - return - } - - setUserVans(response.data) - }).catch((err) => { - setToastColor("danger") - setToastMessage(err); - setShowToast(true); - }) - } + vansRoutes + .getByUserId(userId) + .then((response) => { + if (response.status === "error") { + setToastColor("danger"); + setToastMessage(response.message); + setShowToast(true); + + return; + } + + setUserVans(response.data); + }) + .catch((err) => { + setToastColor("danger"); + setToastMessage(err); + setShowToast(true); + }); + }; + + getUserVans(); + }, []); - getUserVans() - }, []) - return ( - - - Minhas vans - - - - - - - - { userVans ? userVans.map((van, index) => { + + + + {userVans ? ( + userVans.map((van, index) => { return ( - - {van.plate} - {van.brand} - {van.model} - - { van.locator_name ? + + {van.plate} + + {van.brand} - {van.model} + + + {van.locator_name ? ( <> - {van.seats_number} assentos - Locador: {van.locator_name} - : - <> - {van.seats_number} assentos - Não é alugado + + {van.seats_number} assentos - Locador: {van.locator_name} + - } + ) : ( + <> + + {van.seats_number} assentos - Não é alugado + + + )} - ) - }) : <>} + ); + }) + ) : ( + <> + )} - closeToast(setShowToast)} - message={toastMessage} - duration={2500} - /> - + closeToast(setShowToast)} + message={toastMessage} + duration={2500} + /> + ); }; diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx index 8d29023..b186db5 100644 --- a/src/pages/Login.tsx +++ b/src/pages/Login.tsx @@ -3,31 +3,27 @@ import { IonHeader, IonPage, IonTitle, - IonToolbar + IonToolbar, } from "@ionic/react"; import React, { useContext, useState } from "react"; import { IonGrid, IonRow, IonCol, IonToast } from "@ionic/react"; import { useHistory } from "react-router-dom"; -import { - IonItem, - IonLabel, - IonInput, - IonButton, -} from "@ionic/react"; +import { IonItem, IonLabel, IonInput, IonButton } from "@ionic/react"; -import * as sessionRoutes from '../services/api/session'; -import LocalStorage from '../LocalStorage'; +import * as sessionRoutes from "../services/api/session"; +import LocalStorage from "../LocalStorage"; import { Action } from "../components/Action"; import { UserContext } from "../App"; import { closeToast } from "../services/utils"; +import { PageHeader } from "../components/PageHeader"; const Page: React.FC = () => { const [showToast, setShowToast] = useState(false); - const [messageToast, setMessageToast ] = useState(''); - + const [messageToast, setMessageToast] = useState(""); + const history = useHistory(); - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); const user = useContext(UserContext); @@ -57,18 +53,18 @@ const Page: React.FC = () => { return false; } - if(password.length < 7 || password.length > 12) { + if (password.length < 7 || password.length > 12) { setMessageToast("A senha deve conter entre 7 e 12 dígitos"); setShowToast(true); return false; } return true; - } + }; const handleLogin = async () => { if (!validateForm()) { - return + return; } const singinForm = { @@ -76,50 +72,48 @@ const Page: React.FC = () => { password: password, }; - await sessionRoutes.create(singinForm).then(response => { - if (response.status === 'error') { - setMessageToast(response.message); - setShowToast(true); + await sessionRoutes + .create(singinForm) + .then((response) => { + if (response.status === "error") { + setMessageToast(response.message); + setShowToast(true); - return - } + return; + } - const { token } = response.token + const { token } = response.token; - LocalStorage.setToken(token); + LocalStorage.setToken(token); - user.setIsLoggedIn(true); + user.setIsLoggedIn(true); - history.push({ pathname: '/home', state: { redirectData: { - showToastMessage: true, - toastColor: "success", - toastMessage: "Usuário autenticado com sucesso!", - }}}) - }).catch(error => { - // if (!error.response) return + history.push({ + pathname: "/home", + state: { + redirectData: { + showToastMessage: true, + toastColor: "success", + toastMessage: "Usuário autenticado com sucesso!", + }, + }, + }); + }) + .catch((error) => { + // if (!error.response) return - // se o backend retornou uma mensagem de erro customizada - // if (error.response.data.message) { - console.dir('Houve um erro: ', { error }) - alert('Houve um erro') - }) + // se o backend retornou uma mensagem de erro customizada + // if (error.response.data.message) { + console.dir("Houve um erro: ", { error }); + alert("Houve um erro"); + }); }; return ( - - - Login - - + - - - Login - - - @@ -153,7 +147,11 @@ const Page: React.FC = () => { Login

- +

@@ -161,7 +159,7 @@ const Page: React.FC = () => { closeToast(setShowToast)} message={messageToast} diff --git a/src/pages/MeusItinerarios/MeusItinerarios.tsx b/src/pages/MeusItinerarios/MeusItinerarios.tsx index 0652f3b..e08b1fa 100644 --- a/src/pages/MeusItinerarios/MeusItinerarios.tsx +++ b/src/pages/MeusItinerarios/MeusItinerarios.tsx @@ -16,6 +16,7 @@ import { } from "@ionic/react"; import { add, locateOutline, locationOutline } from "ionicons/icons"; import { useState } from "react"; +import { PageHeader } from "../../components/PageHeader"; import "./MeusItinerarios.css"; interface ItineraryInfo { @@ -93,20 +94,12 @@ export default function MeusItinerarios() { return ( - - - Meus Itinerários - - - - - + + - - - Meus Itinerários - - {routes ? ( routes.map((itinerary, index) => { return ( diff --git a/src/pages/MinhasVans.tsx b/src/pages/MinhasVans.tsx index 792493a..e5dd513 100644 --- a/src/pages/MinhasVans.tsx +++ b/src/pages/MinhasVans.tsx @@ -1,22 +1,40 @@ -import { IonBackButton, IonButtons, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonPage, IonTitle, IonToast, IonToolbar } from '@ionic/react'; -import { Color } from '@ionic/core'; -import { carOutline } from 'ionicons/icons'; -import { useContext, useEffect, useState } from 'react'; -import { useHistory, useLocation } from 'react-router'; +import { + IonBackButton, + IonButtons, + IonCard, + IonCardContent, + IonCardHeader, + IonCardSubtitle, + IonCardTitle, + IonContent, + IonHeader, + IonIcon, + IonItem, + IonLabel, + IonPage, + IonTitle, + IonToast, + IonToolbar, +} from "@ionic/react"; +import { Color } from "@ionic/core"; +import { carOutline } from "ionicons/icons"; +import { useContext, useEffect, useState } from "react"; +import { useHistory, useLocation } from "react-router"; -import { UserContext } from '../App'; +import { UserContext } from "../App"; -import * as vansRoutes from '../services/api/vans'; +import * as vansRoutes from "../services/api/vans"; -import sessionsService from '../services/functions/sessionsService' -import { closeToast } from '../services/utils'; +import sessionsService from "../services/functions/sessionsService"; +import { closeToast } from "../services/utils"; +import { PageHeader } from "../components/PageHeader"; interface VanInfo { plate: string; brand: string; model: string; seats_number: string; - document_status: boolean, + document_status: boolean; locator_name: string; locator_address: string; locator_complement: string; @@ -28,90 +46,100 @@ const MinhasVans: React.FC = () => { const history = useHistory(); const [showToast, setShowToast] = useState(false); - const [toastMessage, setToastMessage] = useState(''); + const [toastMessage, setToastMessage] = useState(""); const [toastColor, setToastColor] = useState("primary"); const [userVans, setUserVans] = useState(); const redirectUserToLogin = () => { - history.push({ pathname: '/login' }); - } + history.push({ pathname: "/login" }); + }; useEffect(() => { const getUserVans = async () => { - let userId = '' + let userId = ""; + + const refreshSessionRes = await sessionsService.refreshSession(); - const refreshSessionRes = await sessionsService.refreshSession() - if (refreshSessionRes.error) { - redirectUserToLogin() - return + redirectUserToLogin(); + return; } - + if (refreshSessionRes.userId) { - userId = refreshSessionRes.userId + userId = refreshSessionRes.userId; } - vansRoutes.getByUserId(userId).then(response => { - if (response.status === 'error') { - setToastColor("danger") - setToastMessage(response.message); - setShowToast(true); - - return - } - - setUserVans(response.data) - }).catch((err) => { - setToastColor("danger") - setToastMessage(err); - setShowToast(true); - }) - } + vansRoutes + .getByUserId(userId) + .then((response) => { + if (response.status === "error") { + setToastColor("danger"); + setToastMessage(response.message); + setShowToast(true); + + return; + } + + setUserVans(response.data); + }) + .catch((err) => { + setToastColor("danger"); + setToastMessage(err); + setShowToast(true); + }); + }; + + getUserVans(); + }, []); - getUserVans() - }, []) - return ( - - - Minhas vans - - - - - - - - { userVans ? userVans.map((van, index) => { + + + + {userVans ? ( + userVans.map((van, index) => { return ( - - {van.plate} - {van.brand} - {van.model} - - { van.locator_name ? + + {van.plate} + + {van.brand} - {van.model} + + + {van.locator_name ? ( <> - {van.seats_number} assentos - Locador: {van.locator_name} - : - <> - {van.seats_number} assentos - Não é alugado + + {van.seats_number} assentos - Locador: {van.locator_name} + - } + ) : ( + <> + + {van.seats_number} assentos - Não é alugado + + + )} - ) - }) : <>} + ); + }) + ) : ( + <> + )} - closeToast(setShowToast)} - message={toastMessage} - duration={2500} - /> - + closeToast(setShowToast)} + message={toastMessage} + duration={2500} + /> + ); }; diff --git a/src/pages/Perfil.tsx b/src/pages/Perfil.tsx index 1c08e0a..9a6f2b4 100644 --- a/src/pages/Perfil.tsx +++ b/src/pages/Perfil.tsx @@ -41,6 +41,7 @@ import usersService from "../services/functions/usersService"; import { UserContext } from "../App"; import { Color } from "@ionic/core"; import { closeToast } from "../services/utils"; +import { PageHeader } from "../components/PageHeader"; interface ScanNewProps { match: { @@ -212,22 +213,9 @@ const Perfil: React.FC = (props) => { return ( - - - Seu perfil - - - - - + - - - Seu perfil - - - { @@ -48,97 +49,101 @@ const PerfilEditar: React.FC = () => { const location = useLocation(); const [showToast, setShowToast] = useState(false); - const [messageToast, setMessageToast] = useState(''); + const [messageToast, setMessageToast] = useState(""); const [toastColor, setToastColor] = useState("primary"); const [userData, setUserData] = useState({ - name: '', - lastname: '', - email: '', - birth_date: '', - bio: '', + name: "", + lastname: "", + email: "", + birth_date: "", + bio: "", }); const [inputValues, setInputValues] = useReducer( (state: any, newState: any) => ({ ...state, ...newState }), { - name: '', - lastname: '', - email: '', - birth_date: '', - bio: '', + name: "", + lastname: "", + email: "", + birth_date: "", + bio: "", } ); useEffect(() => { if (!location.state) { - history.push({ pathname: '/perfil' }) + history.push({ pathname: "/perfil" }); } - let userData = location.state.userData + let userData = location.state.userData; - setUserData(location.state.userData) + setUserData(location.state.userData); setInputValues({ - 'name': userData.name, - 'lastname': userData.lastname, - 'email': userData.email, - 'birth_date': userData.birth_date, - 'bio': userData.bio + name: userData.name, + lastname: userData.lastname, + email: userData.email, + birth_date: userData.birth_date, + bio: userData.bio, }); - console.log(inputValues) + console.log(inputValues); }, [userData]); const handleUpdateUserData = () => { - usersRoutes.update(inputValues).then(response => { - if (response.status === 'error') { - setToastColor("danger") - setMessageToast(response.message); + usersRoutes + .update(inputValues) + .then((response) => { + if (response.status === "error") { + setToastColor("danger"); + setMessageToast(response.message); + setShowToast(true); + + return; + } + + history.push({ + pathname: "/perfil", + state: { + redirectData: { + showToastMessage: true, + toastColor: "success", + toastMessage: response.message, + }, + }, + }); + }) + .catch((err) => { + setToastColor("danger"); + setMessageToast(err); setShowToast(true); - - return - } - - history.push({ pathname: '/perfil', state: { - redirectData: { - showToastMessage: true, - toastColor: "success", - toastMessage: response.message, - }, - }}) - }).catch((err) => { - setToastColor("danger") - setMessageToast(err); - setShowToast(true); - }) - } + }); + }; const hasChangedSinceInitialState = () => { - return isEqual(userData, inputValues) - } + return isEqual(userData, inputValues); + }; return ( - - - Editar perfil - - - - - + -
+
Nome setInputValues({'name': e.detail.value!})} + onIonChange={(e) => + setInputValues({ name: e.detail.value! }) + } > @@ -147,7 +152,9 @@ const PerfilEditar: React.FC = () => { setInputValues({'lastname': e.detail.value!})} + onIonChange={(e) => + setInputValues({ lastname: e.detail.value! }) + } >
@@ -157,25 +164,28 @@ const PerfilEditar: React.FC = () => { setInputValues({'email': e.detail.value!})} + onIonChange={(e) => + setInputValues({ email: e.detail.value! }) + } > - Data de nascimento - Data de nascimento + setInputValues({'birth_date': e.detail.value!}) } - > - + onIonChange={(e) => + setInputValues({ birth_date: e.detail.value! }) + } + > Biografia setInputValues({'bio': e.detail.value!})} + onIonChange={(e) => setInputValues({ bio: e.detail.value! })} > @@ -183,7 +193,10 @@ const PerfilEditar: React.FC = () => { - + diff --git a/src/pages/Transportes/Transportes.tsx b/src/pages/Transportes/Transportes.tsx index 9b09f8e..d13f207 100644 --- a/src/pages/Transportes/Transportes.tsx +++ b/src/pages/Transportes/Transportes.tsx @@ -91,6 +91,7 @@ const Transportes: React.FC = () => { return ( + {/* TODO, componentizar Header */}
{/*