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