diff --git a/src/pages/Transportes/Transportes.css b/src/pages/Transportes/Transportes.css index 4b3ee50..966beea 100644 --- a/src/pages/Transportes/Transportes.css +++ b/src/pages/Transportes/Transportes.css @@ -64,4 +64,15 @@ display: flex; justify-content: space-between; align-items: center; +} + +.button-criar-alerta{ + display: flex; + justify-content: center; + align-items: center; + margin: 1rem 0 5.5rem 0; +} + +.msg-not-found{ + margin: 1.5rem; } \ No newline at end of file diff --git a/src/pages/Transportes/Transportes.tsx b/src/pages/Transportes/Transportes.tsx index aa7b36b..37984aa 100644 --- a/src/pages/Transportes/Transportes.tsx +++ b/src/pages/Transportes/Transportes.tsx @@ -30,6 +30,7 @@ import { IonRadio, IonCheckbox, IonFooter, + IonToast, } from "@ionic/react"; import { arrowBack, @@ -45,6 +46,7 @@ import { import { useEffect, useState } from "react"; import { useHistory, useLocation } from "react-router"; import { getTransportes } from "../../services/transportes"; +import { createUserSearch } from "../../services/users"; import "./Transportes.css"; interface InfoBusca { @@ -60,6 +62,9 @@ const Transportes: React.FC = () => { const props = location.state as InfoBusca; const [transportes, setTransportes] = useState([]); const [showModalFilters, setShowModalFilters] = useState(false); + const [showToast, setShowToast] = useState(false); + const [messageToast, setMessageToast ] = useState(''); + const [toastColor, setToastColor] = useState('success'); useEffect(() => { if (props) { @@ -72,6 +77,17 @@ const Transportes: React.FC = () => { setTransportes(data); } + function criaAlerta(){ + createUserSearch(props.coordinatesFrom.lat, props.coordinatesFrom.lng, props.addressTo.label).then(() => { + setMessageToast('Alerta criado com sucesso!'); + setShowToast(true); + }).catch((err:any) => { + setMessageToast('Não foi possível criar o alerta!'); + setToastColor('danger'); + setShowToast(true); + }) + } + return ( @@ -91,22 +107,26 @@ const Transportes: React.FC = () => { -
- - -
Mais barata
- - Seu João - -
- -
Melhor avaliação
- - Seu Zé - -
-
-
+ {transportes && transportes.length > 0? ( +
+ + +
Mais barata
+ + Seu João + +
+ +
Melhor avaliação
+ + Seu Zé + +
+
+
+ ) + : + (

Não foi encontrado nenhum transporte que atenda essa rota.

)} {transportes && transportes.map((record: any, index: any) => { return ( @@ -119,7 +139,11 @@ const Transportes: React.FC = () => { ); - })} + })} + +
+ criaAlerta()}>Criar Alerta +
setShowModalFilters(true)} @@ -182,6 +206,14 @@ const Transportes: React.FC = () => { + setShowToast(false)} + message={messageToast} + duration={2500} + />
); diff --git a/src/services/users.ts b/src/services/users.ts index 7654149..ce9e13a 100644 --- a/src/services/users.ts +++ b/src/services/users.ts @@ -55,4 +55,11 @@ export async function getUsersSearching(currentPoint: any) { // const data = await response.json(); console.log(response.data) setStore(response.data); +} + +export async function createUserSearch(latitude_from: any, longitude_from: any, addres_to: any) { + const response = await instance.post("http://localhost:3333/search/", { latitude_from, longitude_from, addres_to }); + + console.log(response) + setStore(response); } \ No newline at end of file