Refatorando Van para Vehicle
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
const vansRoutesDefault = '/vans/locator';
|
||||
const vansRoutes = {
|
||||
const vehiclesRoutesDefault = '/vehicles/locator';
|
||||
const vehiclesRoutes = {
|
||||
list: {
|
||||
url: `${vansRoutesDefault}/list`
|
||||
url: `${vehiclesRoutesDefault}/list`
|
||||
},
|
||||
getById: {
|
||||
url: `${vansRoutesDefault}/`
|
||||
url: `${vehiclesRoutesDefault}/`
|
||||
},
|
||||
create: {
|
||||
url: `${vansRoutesDefault}/`
|
||||
url: `${vehiclesRoutesDefault}/`
|
||||
},
|
||||
update: {
|
||||
url: `${vansRoutesDefault}/edit`
|
||||
url: `${vehiclesRoutesDefault}/edit`
|
||||
}
|
||||
}
|
||||
|
||||
export default vansRoutes;
|
||||
export default vehiclesRoutes;
|
||||
@@ -1,20 +0,0 @@
|
||||
const vansRoutesDefault = '/vans';
|
||||
const vansRoutes = {
|
||||
list: {
|
||||
url: `${vansRoutesDefault}/list`
|
||||
},
|
||||
getByPlate: {
|
||||
url: `${vansRoutesDefault}/plate`
|
||||
},
|
||||
getByUserId: {
|
||||
url: `${vansRoutesDefault}/user`
|
||||
},
|
||||
create: {
|
||||
url: `${vansRoutesDefault}/`
|
||||
},
|
||||
update: {
|
||||
url: `${vansRoutesDefault}/`
|
||||
}
|
||||
}
|
||||
|
||||
export default vansRoutes;
|
||||
20
src/constants/routes/vehiclesRoutes.ts
Normal file
20
src/constants/routes/vehiclesRoutes.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
const vehiclesRoutesDefault = '/vehicles';
|
||||
const vehiclesRoutes = {
|
||||
list: {
|
||||
url: `${vehiclesRoutesDefault}/list`
|
||||
},
|
||||
getByPlate: {
|
||||
url: `${vehiclesRoutesDefault}/plate`
|
||||
},
|
||||
getByUserId: {
|
||||
url: `${vehiclesRoutesDefault}/user`
|
||||
},
|
||||
create: {
|
||||
url: `${vehiclesRoutesDefault}/`
|
||||
},
|
||||
update: {
|
||||
url: `${vehiclesRoutesDefault}/`
|
||||
}
|
||||
}
|
||||
|
||||
export default vehiclesRoutes;
|
||||
@@ -1,6 +1,6 @@
|
||||
export interface Itinerary {
|
||||
id_itinerary: number;
|
||||
van_plate: string;
|
||||
vehicle_plate: string;
|
||||
price: number;
|
||||
days_of_week: number;
|
||||
specific_day: Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type Van = {
|
||||
export type Vehicle = {
|
||||
id: number;
|
||||
carPlate: string;
|
||||
carBrand: string;
|
||||
|
||||
@@ -266,7 +266,7 @@ const BuscarItinerario: React.FC = () => {
|
||||
</p>
|
||||
<p>
|
||||
<IonIcon icon={cashOutline} /> Valor:{" "}
|
||||
{itinerary.van_plate}
|
||||
{itinerary.vehicle_plate}
|
||||
</p>
|
||||
</IonCardSubtitle>
|
||||
</IonCardHeader>
|
||||
|
||||
@@ -23,13 +23,13 @@ import { useHistory, useLocation } from "react-router";
|
||||
|
||||
import { UserContext } from "../App";
|
||||
|
||||
import * as vansRoutes from "../services/api/vans";
|
||||
import * as vehiclesRoutes from "../services/api/vehicles";
|
||||
|
||||
import sessionsService from "../services/functions/sessionsService";
|
||||
import { closeToast } from "../services/utils";
|
||||
import { PageHeader } from "../components/PageHeader";
|
||||
|
||||
interface VanInfo {
|
||||
interface VehicleInfo {
|
||||
plate: string;
|
||||
brand: string;
|
||||
model: string;
|
||||
@@ -49,14 +49,14 @@ const Itinerario: React.FC = () => {
|
||||
const [toastMessage, setToastMessage] = useState("");
|
||||
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||
|
||||
const [userVans, setUserVans] = useState<VanInfo[]>();
|
||||
const [userVehicles, setUserVehicles] = useState<VehicleInfo[]>();
|
||||
|
||||
const redirectUserToLogin = () => {
|
||||
history.push({ pathname: "/login" });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const getUserVans = async () => {
|
||||
const getUserVehicles = async () => {
|
||||
let userId = "";
|
||||
|
||||
const refreshSessionRes = await sessionsService.refreshSession();
|
||||
@@ -70,7 +70,7 @@ const Itinerario: React.FC = () => {
|
||||
userId = refreshSessionRes.userId;
|
||||
}
|
||||
|
||||
vansRoutes
|
||||
vehiclesRoutes
|
||||
.getByUserId(userId)
|
||||
.then((response) => {
|
||||
if (response.status === "error") {
|
||||
@@ -81,7 +81,7 @@ const Itinerario: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
setUserVans(response.data);
|
||||
setUserVehicles(response.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
setToastColor("danger");
|
||||
@@ -90,37 +90,37 @@ const Itinerario: React.FC = () => {
|
||||
});
|
||||
};
|
||||
|
||||
getUserVans();
|
||||
getUserVehicles();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<IonPage>
|
||||
<PageHeader
|
||||
pageName="Minhas vans"
|
||||
pageName="Minhas vehicles"
|
||||
backButtonPageUrl="/perfil"
|
||||
></PageHeader>
|
||||
|
||||
<IonContent>
|
||||
{userVans ? (
|
||||
userVans.map((van, index) => {
|
||||
{userVehicles ? (
|
||||
userVehicles.map((vehicle, index) => {
|
||||
return (
|
||||
<IonCard key={index}>
|
||||
<IonCardHeader>
|
||||
<IonCardTitle>{van.plate}</IonCardTitle>
|
||||
<IonCardTitle>{vehicle.plate}</IonCardTitle>
|
||||
<IonCardSubtitle>
|
||||
{van.brand} - {van.model}
|
||||
{vehicle.brand} - {vehicle.model}
|
||||
</IonCardSubtitle>
|
||||
</IonCardHeader>
|
||||
{van.locator_name ? (
|
||||
{vehicle.locator_name ? (
|
||||
<>
|
||||
<IonCardContent>
|
||||
{van.seats_number} assentos - Locador: {van.locator_name}
|
||||
{vehicle.seats_number} assentos - Locador: {vehicle.locator_name}
|
||||
</IonCardContent>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<IonCardContent>
|
||||
{van.seats_number} assentos - Não é alugado
|
||||
{vehicle.seats_number} assentos - Não é alugado
|
||||
</IonCardContent>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -21,7 +21,7 @@ import "./MeusItinerarios.css";
|
||||
|
||||
interface ItineraryInfo {
|
||||
id_itinerary: number;
|
||||
van_plate: string;
|
||||
vehicle_plate: string;
|
||||
days_of_week: number;
|
||||
specific_day: string;
|
||||
estimated_departure_time: string;
|
||||
@@ -36,7 +36,7 @@ export default function MeusItinerarios() {
|
||||
[
|
||||
{
|
||||
id_itinerary: 1,
|
||||
van_plate: 'FSS1918',
|
||||
vehicle_plate: 'FSS1918',
|
||||
days_of_week: 3,
|
||||
specific_day: '24/08/2022',
|
||||
estimated_departure_time: '10:00',
|
||||
@@ -47,7 +47,7 @@ export default function MeusItinerarios() {
|
||||
},
|
||||
{
|
||||
id_itinerary: 1,
|
||||
van_plate: 'FSS1918',
|
||||
vehicle_plate: 'FSS1918',
|
||||
days_of_week: 3,
|
||||
specific_day: '24/08/2022',
|
||||
estimated_departure_time: '10:00',
|
||||
@@ -58,7 +58,7 @@ export default function MeusItinerarios() {
|
||||
},
|
||||
{
|
||||
id_itinerary: 1,
|
||||
van_plate: 'FSS1918',
|
||||
vehicle_plate: 'FSS1918',
|
||||
days_of_week: 3,
|
||||
specific_day: '24/08/2022',
|
||||
estimated_departure_time: '10:00',
|
||||
@@ -69,7 +69,7 @@ export default function MeusItinerarios() {
|
||||
},
|
||||
{
|
||||
id_itinerary: 1,
|
||||
van_plate: 'FSS1918',
|
||||
vehicle_plate: 'FSS1918',
|
||||
days_of_week: 3,
|
||||
specific_day: '24/08/2022',
|
||||
estimated_departure_time: '10:00',
|
||||
@@ -80,7 +80,7 @@ export default function MeusItinerarios() {
|
||||
},
|
||||
{
|
||||
id_itinerary: 1,
|
||||
van_plate: 'FSS1918',
|
||||
vehicle_plate: 'FSS1918',
|
||||
days_of_week: 3,
|
||||
specific_day: '24/08/2022',
|
||||
estimated_departure_time: '10:00',
|
||||
|
||||
@@ -148,7 +148,7 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if user is driver (if they have vans)
|
||||
// check if user is driver (if they have vehicles)
|
||||
const userIsDriverRes = await usersService.checkIfUserIsDriver(userId);
|
||||
|
||||
// if (userIsDriverRes.error) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import { useHistory } from "react-router-dom";
|
||||
|
||||
import carsService from "../services/functions/carsService";
|
||||
|
||||
import * as vansRoutes from "../services/api/vans";
|
||||
import * as vehiclesRoutes from "../services/api/vehicles";
|
||||
|
||||
import "./VeiculoCadastro.css";
|
||||
import { Color } from "@ionic/core";
|
||||
@@ -80,7 +80,7 @@ const VeiculoCadastro: React.FC = () => {
|
||||
};
|
||||
|
||||
const validateForm = (): boolean => {
|
||||
const vanForm = {
|
||||
const vehicleForm = {
|
||||
carPlate: inputValues.carPlate,
|
||||
carBrand: inputValues.carBrand,
|
||||
carModel: inputValues.carModel,
|
||||
@@ -89,40 +89,40 @@ const VeiculoCadastro: React.FC = () => {
|
||||
};
|
||||
|
||||
if (
|
||||
!vanForm.carPlate ||
|
||||
vanForm.carPlate.length !== 7 ||
|
||||
!vanForm.carPlate.match(/([A-z0-9]){7}/g)
|
||||
!vehicleForm.carPlate ||
|
||||
vehicleForm.carPlate.length !== 7 ||
|
||||
!vehicleForm.carPlate.match(/([A-z0-9]){7}/g)
|
||||
) {
|
||||
setToastMessage("Placa do veículo inválida!");
|
||||
setShowToast(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!vanForm.carBrand) {
|
||||
if (!vehicleForm.carBrand) {
|
||||
setToastMessage("Marca do veículo é obrigatório");
|
||||
setShowToast(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!vanForm.carModel) {
|
||||
if (!vehicleForm.carModel) {
|
||||
setToastMessage("Modelo do veículo é obrigatório");
|
||||
setShowToast(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!vanForm.seats_number || !parseInt(`${vanForm.seats_number}`)) {
|
||||
if (!vehicleForm.seats_number || !parseInt(`${vehicleForm.seats_number}`)) {
|
||||
setToastMessage("Número de passageiros inválido");
|
||||
setShowToast(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Number(vanForm.seats_number) < 1) {
|
||||
if (Number(vehicleForm.seats_number) < 1) {
|
||||
setToastMessage("Número de passageiros deve ser positivo!");
|
||||
setShowToast(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vanForm.isRented) {
|
||||
if (vehicleForm.isRented) {
|
||||
return validateRentalForm();
|
||||
} else {
|
||||
clearRentalData();
|
||||
@@ -187,8 +187,8 @@ const VeiculoCadastro: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// cria registro da van
|
||||
await vansRoutes
|
||||
// cria registro da vehicle
|
||||
await vehiclesRoutes
|
||||
.create({
|
||||
plate: inputValues.carPlate,
|
||||
brand: inputValues.carBrand,
|
||||
@@ -209,7 +209,7 @@ const VeiculoCadastro: React.FC = () => {
|
||||
}
|
||||
|
||||
history.push({
|
||||
pathname: "/minhas-vans",
|
||||
pathname: "/minhas-vehicles",
|
||||
state: {
|
||||
redirectData: {
|
||||
showToastMessage: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import instance from "./api";
|
||||
|
||||
import vansRoutes from "../../constants/routes/vansRoutes";
|
||||
import vehiclesRoutes from "../../constants/routes/vehiclesRoutes";
|
||||
import { AxiosRequestHeaders } from "axios";
|
||||
import LocalStorage from "../../LocalStorage";
|
||||
|
||||
@@ -17,10 +17,10 @@ function updateHeader() {
|
||||
};
|
||||
}
|
||||
|
||||
export async function getByPlate(vanId: string) {
|
||||
export async function getByPlate(vehicleId: string) {
|
||||
updateHeader();
|
||||
|
||||
const response = await instance.get(vansRoutes.getByPlate.url + `/${vanId}`, {
|
||||
const response = await instance.get(vehiclesRoutes.getByPlate.url + `/${vehicleId}`, {
|
||||
headers: header,
|
||||
});
|
||||
|
||||
@@ -30,14 +30,14 @@ export async function getByPlate(vanId: string) {
|
||||
export async function getByUserId(userId: string) {
|
||||
updateHeader();
|
||||
|
||||
const response = await instance.get(vansRoutes.getByUserId.url + `/${userId}`, {
|
||||
const response = await instance.get(vehiclesRoutes.getByUserId.url + `/${userId}`, {
|
||||
headers: header,
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
interface CreateVanBody {
|
||||
interface CreateVehicleBody {
|
||||
plate: string;
|
||||
brand: string;
|
||||
model: string;
|
||||
@@ -49,23 +49,23 @@ interface CreateVanBody {
|
||||
locator_state: string;
|
||||
}
|
||||
|
||||
export async function create(CreateVanBody: CreateVanBody) {
|
||||
export async function create(CreateVehicleBody: CreateVehicleBody) {
|
||||
updateHeader();
|
||||
|
||||
const response = await instance.post(vansRoutes.create.url, CreateVanBody, { headers: header });
|
||||
const response = await instance.post(vehiclesRoutes.create.url, CreateVehicleBody, { headers: header });
|
||||
return response.data;
|
||||
}
|
||||
|
||||
interface UpdateVanBody {
|
||||
interface UpdateVehicleBody {
|
||||
brand?: string;
|
||||
model?: string;
|
||||
seats_number?: string;
|
||||
}
|
||||
|
||||
export async function update(vanData: UpdateVanBody) {
|
||||
export async function update(vehicleData: UpdateVehicleBody) {
|
||||
updateHeader();
|
||||
|
||||
const response = await instance.patch(vansRoutes.update.url, vanData, {
|
||||
const response = await instance.patch(vehiclesRoutes.update.url, vehicleData, {
|
||||
headers: header,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user