From ccaa5a1933adc0caeca4365bee2970db56186a65 Mon Sep 17 00:00:00 2001 From: Matheus Albino Brunhara Date: Mon, 20 Jun 2022 17:26:47 -0500 Subject: [PATCH] =?UTF-8?q?Adicionando=20dinamica=20status=20de=20perfil?= =?UTF-8?q?=20do=20usu=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/routes/usersRoutes.ts | 3 ++ src/pages/Perfil.tsx | 27 +++++++++++++++-- src/services/api/users.ts | 7 +++++ src/services/functions/usersService.ts | 42 +++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/constants/routes/usersRoutes.ts b/src/constants/routes/usersRoutes.ts index 18216e9..26f7e7e 100644 --- a/src/constants/routes/usersRoutes.ts +++ b/src/constants/routes/usersRoutes.ts @@ -9,6 +9,9 @@ const usersRoutes = { update: { url: `${usersRoutesDefault}/edit` }, + checkIfUserIsDriver: { + url: `${usersRoutesDefault}/isDriver` + }, getSocialInfo: { url: `${usersRoutesDefault}/social` } diff --git a/src/pages/Perfil.tsx b/src/pages/Perfil.tsx index 1a4cb0c..3661c11 100644 --- a/src/pages/Perfil.tsx +++ b/src/pages/Perfil.tsx @@ -21,7 +21,7 @@ import { } from "@ionic/react"; import { useHistory, useLocation } from "react-router-dom"; import React, { useState, useEffect, useReducer, useContext } from "react"; -import { callOutline, cardOutline, carOutline, createOutline, exitOutline, logoFacebook, logoWhatsapp, shieldCheckmarkOutline, starOutline } from "ionicons/icons"; +import { callOutline, cardOutline, carOutline, createOutline, exitOutline, logoFacebook, logoWhatsapp, personOutline, shieldCheckmarkOutline, starOutline } from "ionicons/icons"; import './Perfil.css' import LocalStorage from "../LocalStorage"; @@ -54,6 +54,7 @@ const Perfil: React.FC = (props) => { const location = useLocation(); const [isVisitor, setIsVisitor] = useState(true) + const [isDriver, setIsDriver] = useState(false) const [incompleteProfile, setIncompleteProfile] = useState(false) const [incompleteProfileCounter, setIncompleteProfileCounter] = useState(0) @@ -134,6 +135,20 @@ const Perfil: React.FC = (props) => { return } + + // check if user is driver (if they have vans) + const userIsDriverRes = await usersService.checkIfUserIsDriver(userId) + + // if (userIsDriverRes.error) { + // setToastColor('warning') + // setToastMessage(userIsDriverRes.error.errorMessage) + // setShowToast(true) + // return + // } + + if (!userIsDriverRes.error && userIsDriverRes.result !== undefined) { + setIsDriver(userIsDriverRes.result) + } if (getByIdRes.userData) { const userData = getByIdRes.userData @@ -209,8 +224,16 @@ const Perfil: React.FC = (props) => {
+ { isDriver ? + <> + + + Motorista + + : <> + } - {/* TODO, deve vir do backend */} + Passageiro
diff --git a/src/services/api/users.ts b/src/services/api/users.ts index d2d16e4..0794366 100644 --- a/src/services/api/users.ts +++ b/src/services/api/users.ts @@ -73,6 +73,13 @@ export async function update(userData: UpdateUserRequest) { return response.data; } +export async function checkIfUserIsDriver(id_user: string) { + updateHeader(); + + const response = await instance.get(userRoutes.checkIfUserIsDriver.url + `/${id_user}`, { headers: header }); + return response.data; +} + // TODO, continuar export async function getSocialInfo(userId: string) { updateHeader(); diff --git a/src/services/functions/usersService.ts b/src/services/functions/usersService.ts index 34b25be..87b4f40 100644 --- a/src/services/functions/usersService.ts +++ b/src/services/functions/usersService.ts @@ -92,4 +92,44 @@ const getUserSocialInfo = async (userId: string): Promise => { } }; -export default { getById, getUserSocialInfo } \ No newline at end of file +interface checkIfUserIsDriverReturn { + result?: boolean; + error?: { + errorMessage: string; + } +} + +interface checkIfUserIsDriverResponse { + status: string; + message: string; + result?: boolean; + error?: { + errorMessage: string; + } +} + +const checkIfUserIsDriver = async (id_user: string): Promise => { + try { + let res: checkIfUserIsDriverResponse = await usersRoutes.checkIfUserIsDriver(id_user) + + if (res.status === "error") { + return { + error: { + errorMessage: res.message, + } + }; + } + + return { + result: res.result, + }; + } catch(err) { + return { + error: { + errorMessage: "Por favor, autentique-se.", + } + }; + } +}; + +export default { getById, getUserSocialInfo, checkIfUserIsDriver } \ No newline at end of file