refactor(transportes): ♻️ Ajusta rota de transportes
This commit is contained in:
@@ -103,7 +103,7 @@ const IonicApp: React.FC = () => {
|
|||||||
<IonRouterOutlet>{routes}</IonRouterOutlet>
|
<IonRouterOutlet>{routes}</IonRouterOutlet>
|
||||||
|
|
||||||
<IonTabBar slot="bottom">
|
<IonTabBar slot="bottom">
|
||||||
<IonTabButton tab="buscar" href="/buscar">
|
<IonTabButton tab="buscar" href="/buscar-transporte">
|
||||||
<IonIcon icon={search} />
|
<IonIcon icon={search} />
|
||||||
<IonLabel>Buscar</IonLabel>
|
<IonLabel>Buscar</IonLabel>
|
||||||
</IonTabButton>
|
</IonTabButton>
|
||||||
|
|||||||
14
src/constants/routes/transportsRoutes.ts
Normal file
14
src/constants/routes/transportsRoutes.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const transportsRoutesDefault = '/transports';
|
||||||
|
const transportsRoutes = {
|
||||||
|
create: {
|
||||||
|
url: `${transportsRoutesDefault}`
|
||||||
|
},
|
||||||
|
get: {
|
||||||
|
url: `${transportsRoutesDefault}`
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
url: `${transportsRoutesDefault}`
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default transportsRoutes;
|
||||||
@@ -293,10 +293,21 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
|||||||
<IonIcon icon={carOutline} slot="start" />
|
<IonIcon icon={carOutline} slot="start" />
|
||||||
<IonLabel>Cadastrar Van</IonLabel>
|
<IonLabel>Cadastrar Van</IonLabel>
|
||||||
</IonItem>
|
</IonItem>
|
||||||
<IonItem button onClick={() => history.push({ pathname: '/minhas-vans'})}>
|
|
||||||
<IonIcon icon={carOutline} slot="start" />
|
{ isDriver ?
|
||||||
<IonLabel>Minhas Vans</IonLabel>
|
<>
|
||||||
</IonItem>
|
<IonItem button onClick={() => history.push({ pathname: '/minhas-vans'})}>
|
||||||
|
<IonIcon icon={carOutline} slot="start" />
|
||||||
|
<IonLabel>Minhas Vans</IonLabel>
|
||||||
|
</IonItem>
|
||||||
|
<IonItem button onClick={() => history.push({ pathname: '/buscar-passageiro'})}>
|
||||||
|
<IonIcon icon={personOutline} slot="start" />
|
||||||
|
<IonLabel>Buscar passageiros</IonLabel>
|
||||||
|
</IonItem>
|
||||||
|
</>
|
||||||
|
: <></>
|
||||||
|
}
|
||||||
|
|
||||||
<IonItem>
|
<IonItem>
|
||||||
<IonIcon icon={cardOutline} slot="start" />
|
<IonIcon icon={cardOutline} slot="start" />
|
||||||
<IonLabel>Pagamentos</IonLabel>
|
<IonLabel>Pagamentos</IonLabel>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import {
|
|||||||
} from "ionicons/icons";
|
} from "ionicons/icons";
|
||||||
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/functions/transportsService";
|
||||||
import { createUserSearch } from "../../services/api/users";
|
import { createUserSearch } from "../../services/api/users";
|
||||||
import "./Transportes.css";
|
import "./Transportes.css";
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
|
|
||||||
export class ApiClient{
|
|
||||||
private static api = axios.create({
|
|
||||||
baseURL: "http://localhost:8080"
|
|
||||||
});
|
|
||||||
|
|
||||||
public static async doPost (url: string, body: any): Promise<any> {
|
|
||||||
return await this.api
|
|
||||||
.post(url, body)
|
|
||||||
.then(res => {
|
|
||||||
console.log(res.data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
38
src/services/api/transports.ts
Normal file
38
src/services/api/transports.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import instance from './api';
|
||||||
|
// import LocalStorage from '../LocalStorage';
|
||||||
|
|
||||||
|
import transportsRoutes from '../../constants/routes/transportsRoutes';
|
||||||
|
import { AxiosRequestHeaders } from 'axios';
|
||||||
|
import LocalStorage from '../../LocalStorage';
|
||||||
|
import { setStore } from '../../store/RecordsStore';
|
||||||
|
|
||||||
|
let token: string;
|
||||||
|
let header: AxiosRequestHeaders;
|
||||||
|
|
||||||
|
function updateHeader() {
|
||||||
|
token = LocalStorage.getToken();
|
||||||
|
|
||||||
|
header = {
|
||||||
|
"Accept": 'application/json',
|
||||||
|
"Content-Type": 'application/json',
|
||||||
|
"Authorization": 'Bearer ' + token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface getTransportsRequest {
|
||||||
|
coordinatesFrom: {
|
||||||
|
lat: number,
|
||||||
|
lng: number
|
||||||
|
},
|
||||||
|
coordinatesTo: {
|
||||||
|
lat: number,
|
||||||
|
lng: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get(coordinates: getTransportsRequest) {
|
||||||
|
updateHeader();
|
||||||
|
|
||||||
|
const response = await instance.get(transportsRoutes.get.url + `/${coordinates}`, { headers: header });
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
20
src/services/functions/transportsService.ts
Normal file
20
src/services/functions/transportsService.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import * as transportsRoutes from '../api/transports';
|
||||||
|
|
||||||
|
interface CoordinatesRequest {
|
||||||
|
coordinatesFrom:{
|
||||||
|
lat: number,
|
||||||
|
lng: number
|
||||||
|
},
|
||||||
|
coordinatesTo:{
|
||||||
|
lat: number,
|
||||||
|
lng: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getTransportes(request: CoordinatesRequest) : Promise<any> {
|
||||||
|
try {
|
||||||
|
let res : any = await transportsRoutes.get(request);
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import instance from "../services/api/api";
|
|
||||||
import { setStore } from "../store/RecordsStore";
|
|
||||||
// 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
|
|
||||||
}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CoordinatesRequest {
|
|
||||||
coordinatesFrom:{
|
|
||||||
lat: number,
|
|
||||||
lng: number
|
|
||||||
},
|
|
||||||
coordinatesTo:{
|
|
||||||
lat: number,
|
|
||||||
lng: number
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getTransportes(request: CoordinatesRequest) {
|
|
||||||
updateHeader();
|
|
||||||
|
|
||||||
console.log(request)
|
|
||||||
const response = await instance.post("http://localhost:3333/transportes/", request);
|
|
||||||
return response.data as [];
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user