Button criar alerta
This commit is contained in:
@@ -65,3 +65,14 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
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;
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
IonRadio,
|
IonRadio,
|
||||||
IonCheckbox,
|
IonCheckbox,
|
||||||
IonFooter,
|
IonFooter,
|
||||||
|
IonToast,
|
||||||
} from "@ionic/react";
|
} from "@ionic/react";
|
||||||
import {
|
import {
|
||||||
arrowBack,
|
arrowBack,
|
||||||
@@ -45,6 +46,7 @@ import {
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useHistory, useLocation } from "react-router";
|
import { useHistory, useLocation } from "react-router";
|
||||||
import { getTransportes } from "../../services/transportes";
|
import { getTransportes } from "../../services/transportes";
|
||||||
|
import { createUserSearch } from "../../services/users";
|
||||||
import "./Transportes.css";
|
import "./Transportes.css";
|
||||||
|
|
||||||
interface InfoBusca {
|
interface InfoBusca {
|
||||||
@@ -60,6 +62,9 @@ const Transportes: React.FC = () => {
|
|||||||
const props = location.state as InfoBusca;
|
const props = location.state as InfoBusca;
|
||||||
const [transportes, setTransportes] = useState([]);
|
const [transportes, setTransportes] = useState([]);
|
||||||
const [showModalFilters, setShowModalFilters] = useState(false);
|
const [showModalFilters, setShowModalFilters] = useState(false);
|
||||||
|
const [showToast, setShowToast] = useState(false);
|
||||||
|
const [messageToast, setMessageToast ] = useState('');
|
||||||
|
const [toastColor, setToastColor] = useState('success');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props) {
|
if (props) {
|
||||||
@@ -72,6 +77,17 @@ const Transportes: React.FC = () => {
|
|||||||
setTransportes(data);
|
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 (
|
return (
|
||||||
<IonPage>
|
<IonPage>
|
||||||
<IonHeader>
|
<IonHeader>
|
||||||
@@ -91,22 +107,26 @@ const Transportes: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
</IonHeader>
|
</IonHeader>
|
||||||
<IonContent fullscreen>
|
<IonContent fullscreen>
|
||||||
<div className="header-tabs">
|
{transportes && transportes.length > 0? (
|
||||||
<IonSlides>
|
<div className="header-tabs">
|
||||||
<IonSlide>
|
<IonSlides>
|
||||||
<h5>Mais barata</h5>
|
<IonSlide>
|
||||||
<IonCard className="card-transporte">
|
<h5>Mais barata</h5>
|
||||||
<IonCardContent>Seu João</IonCardContent>
|
<IonCard className="card-transporte">
|
||||||
</IonCard>
|
<IonCardContent>Seu João</IonCardContent>
|
||||||
</IonSlide>
|
</IonCard>
|
||||||
<IonSlide>
|
</IonSlide>
|
||||||
<h5>Melhor avaliação</h5>
|
<IonSlide>
|
||||||
<IonCard className="card-transporte">
|
<h5>Melhor avaliação</h5>
|
||||||
<IonCardContent>Seu Zé</IonCardContent>
|
<IonCard className="card-transporte">
|
||||||
</IonCard>
|
<IonCardContent>Seu Zé</IonCardContent>
|
||||||
</IonSlide>
|
</IonCard>
|
||||||
</IonSlides>
|
</IonSlide>
|
||||||
</div>
|
</IonSlides>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
:
|
||||||
|
(<h1 className="msg-not-found">Não foi encontrado nenhum transporte que atenda essa rota.</h1>)}
|
||||||
{transportes &&
|
{transportes &&
|
||||||
transportes.map((record: any, index: any) => {
|
transportes.map((record: any, index: any) => {
|
||||||
return (
|
return (
|
||||||
@@ -119,7 +139,11 @@ const Transportes: React.FC = () => {
|
|||||||
</IonCardContent>
|
</IonCardContent>
|
||||||
</IonCard>
|
</IonCard>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
|
<div className="button-criar-alerta">
|
||||||
|
<IonButton onClick={() => criaAlerta()}>Criar Alerta</IonButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
<IonFab
|
<IonFab
|
||||||
onClick={() => setShowModalFilters(true)}
|
onClick={() => setShowModalFilters(true)}
|
||||||
@@ -182,6 +206,14 @@ const Transportes: React.FC = () => {
|
|||||||
</IonButton>
|
</IonButton>
|
||||||
</IonFooter>
|
</IonFooter>
|
||||||
</IonModal>
|
</IonModal>
|
||||||
|
<IonToast
|
||||||
|
// cssClass={"toast-notification"}
|
||||||
|
color={toastColor}
|
||||||
|
isOpen={showToast}
|
||||||
|
onDidDismiss={() => setShowToast(false)}
|
||||||
|
message={messageToast}
|
||||||
|
duration={2500}
|
||||||
|
/>
|
||||||
</IonContent>
|
</IonContent>
|
||||||
</IonPage>
|
</IonPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -56,3 +56,10 @@ export async function getUsersSearching(currentPoint: any) {
|
|||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
setStore(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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user