diff --git a/src/App.tsx b/src/App.tsx
index ee3dfae..2b012b6 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -43,6 +43,7 @@ import './theme/variables.css';
import { search, home, person } from 'ionicons/icons';
import { useState, useContext } from 'react';
import React from 'react';
+import MinhasVans from './pages/MinhasVans';
setupIonicReact();
@@ -62,6 +63,7 @@ const routes = (
+
diff --git a/src/constants/routes/vansRoutes.ts b/src/constants/routes/vansRoutes.ts
index a4e241c..7bfcd2d 100644
--- a/src/constants/routes/vansRoutes.ts
+++ b/src/constants/routes/vansRoutes.ts
@@ -3,8 +3,11 @@ const vansRoutes = {
list: {
url: `${vansRoutesDefault}/list`
},
- getById: {
- url: `${vansRoutesDefault}/`
+ getByPlate: {
+ url: `${vansRoutesDefault}/plate`
+ },
+ getByUserId: {
+ url: `${vansRoutesDefault}/user`
},
create: {
url: `${vansRoutesDefault}/`
diff --git a/src/pages/MinhasVans.tsx b/src/pages/MinhasVans.tsx
new file mode 100644
index 0000000..904478c
--- /dev/null
+++ b/src/pages/MinhasVans.tsx
@@ -0,0 +1,118 @@
+import { IonBackButton, IonButtons, IonCard, IonCardContent, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonPage, IonTitle, IonToast, IonToolbar } from '@ionic/react';
+import { Color } from '@ionic/react/node_modules/@ionic/core';
+import { carOutline } from 'ionicons/icons';
+import { useContext, useEffect, useState } from 'react';
+import { useHistory, useLocation } from 'react-router';
+
+import { UserContext } from '../App';
+
+import * as vansRoutes from '../services/api/vans';
+
+import sessionsService from '../services/functions/sessionsService'
+
+interface VanInfo {
+ plate: string;
+ brand: string;
+ model: string;
+ seats_number: string;
+ document_status: boolean,
+ locator_name: string;
+ locator_address: string;
+ locator_complement: string;
+ locator_city: string;
+ locator_state: string;
+}
+
+const MinhasVans: React.FC = () => {
+ const history = useHistory();
+
+ const [showToast, setShowToast] = useState(false);
+ const [toastMessage, setToastMessage] = useState('');
+ const [toastColor, setToastColor] = useState("primary");
+
+ const [userVans, setUserVans] = useState();
+
+ const redirectUserToLogin = () => {
+ history.push({ pathname: '/login' });
+ }
+
+ useEffect(() => {
+ const getUserVans = async () => {
+ let userId = ''
+
+ const refreshSessionRes = await sessionsService.refreshSession()
+
+ if (refreshSessionRes.error) {
+ redirectUserToLogin()
+ return
+ }
+
+ if (refreshSessionRes.userId) {
+ userId = refreshSessionRes.userId
+ }
+
+ vansRoutes.getByUserId(userId).then(response => {
+ if (response.status === 'error') {
+ setToastColor("danger")
+ setToastMessage(response.message);
+ setShowToast(true);
+
+ return
+ }
+
+ setUserVans(response.data)
+ }).catch((err) => {
+ setToastColor("danger")
+ setToastMessage(err);
+ setShowToast(true);
+ })
+ }
+
+ getUserVans()
+ }, [])
+
+ return (
+
+
+
+ Minhas vans
+
+
+
+
+
+
+
+ { userVans ? userVans.map((van, index) => {
+ return (
+
+
+ {van.plate}
+ {van.brand} - {van.model}
+
+ { van.locator_name ?
+ <>
+ {van.seats_number} assentos - Locador: {van.locator_name}
+ > :
+ <>
+ {van.seats_number} assentos - Não é alugado
+ >
+ }
+
+ )
+ }) : <>>}
+
+ setShowToast(false)}
+ message={toastMessage}
+ duration={2500}
+ />
+
+
+ );
+};
+
+export default MinhasVans;
diff --git a/src/pages/Perfil.tsx b/src/pages/Perfil.tsx
index 7c88028..1a4cb0c 100644
--- a/src/pages/Perfil.tsx
+++ b/src/pages/Perfil.tsx
@@ -78,7 +78,6 @@ const Perfil: React.FC = (props) => {
);
const redirectUserToLogin = () => {
- // TODO, não impede o usuário de retornar a página de login
history.push({ pathname: '/login' });
setToastMessage("Por favor, autentique-se!");
setShowToast(true);
@@ -271,6 +270,10 @@ const Perfil: React.FC = (props) => {
Cadastrar Van
+ history.push({ pathname: '/minhas-vans'})}>
+
+ Minhas Vans
+
Pagamentos
diff --git a/src/pages/PerfilEditar.tsx b/src/pages/PerfilEditar.tsx
index a8a783a..d3fa677 100644
--- a/src/pages/PerfilEditar.tsx
+++ b/src/pages/PerfilEditar.tsx
@@ -96,9 +96,13 @@ const PerfilEditar: React.FC = () => {
return
}
- setToastColor("success")
- setMessageToast(response.message);
- setShowToast(true);
+ history.push({ pathname: '/perfil', state: {
+ redirectData: {
+ showToastMessage: true,
+ toastColor: "success",
+ toastMessage: response.message,
+ },
+ }})
}).catch((err) => {
setToastColor("danger")
setMessageToast(err);
diff --git a/src/services/api/vans.ts b/src/services/api/vans.ts
index ec7c927..f4b5fd3 100644
--- a/src/services/api/vans.ts
+++ b/src/services/api/vans.ts
@@ -17,10 +17,20 @@ function updateHeader() {
};
}
-export async function getById(vanId: string) {
+export async function getByPlate(vanId: string) {
updateHeader();
- const response = await instance.get(vansRoutes.getById.url + `/${vanId}`, {
+ const response = await instance.get(vansRoutes.getByPlate.url + `/${vanId}`, {
+ headers: header,
+ });
+
+ return response.data;
+}
+
+export async function getByUserId(userId: string) {
+ updateHeader();
+
+ const response = await instance.get(vansRoutes.getByUserId.url + `/${userId}`, {
headers: header,
});