Adicionando dinamica status de perfil do usuário

This commit is contained in:
Matheus Albino Brunhara
2022-06-20 17:26:47 -05:00
parent d30b3c6664
commit ccaa5a1933
4 changed files with 76 additions and 3 deletions

View File

@@ -9,6 +9,9 @@ const usersRoutes = {
update: { update: {
url: `${usersRoutesDefault}/edit` url: `${usersRoutesDefault}/edit`
}, },
checkIfUserIsDriver: {
url: `${usersRoutesDefault}/isDriver`
},
getSocialInfo: { getSocialInfo: {
url: `${usersRoutesDefault}/social` url: `${usersRoutesDefault}/social`
} }

View File

@@ -21,7 +21,7 @@ import {
} from "@ionic/react"; } from "@ionic/react";
import { useHistory, useLocation } from "react-router-dom"; import { useHistory, useLocation } from "react-router-dom";
import React, { useState, useEffect, useReducer, useContext } from "react"; 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 './Perfil.css'
import LocalStorage from "../LocalStorage"; import LocalStorage from "../LocalStorage";
@@ -54,6 +54,7 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
const location = useLocation<LocationState>(); const location = useLocation<LocationState>();
const [isVisitor, setIsVisitor] = useState(true) const [isVisitor, setIsVisitor] = useState(true)
const [isDriver, setIsDriver] = useState(false)
const [incompleteProfile, setIncompleteProfile] = useState(false) const [incompleteProfile, setIncompleteProfile] = useState(false)
const [incompleteProfileCounter, setIncompleteProfileCounter] = useState(0) const [incompleteProfileCounter, setIncompleteProfileCounter] = useState(0)
@@ -135,6 +136,20 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
return 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) { if (getByIdRes.userData) {
const userData = getByIdRes.userData const userData = getByIdRes.userData
@@ -209,8 +224,16 @@ const Perfil: React.FC<ScanNewProps> = (props) => {
</IonCardHeader> </IonCardHeader>
<div id='profile-status'> <div id='profile-status'>
{ isDriver ?
<>
<IonChip> <IonChip>
{/* TODO, deve vir do backend */} <IonIcon icon={carOutline}></IonIcon>
<IonLabel color="primary">Motorista</IonLabel>
</IonChip>
</> : <></>
}
<IonChip>
<IonIcon icon={personOutline}></IonIcon>
<IonLabel color="primary">Passageiro</IonLabel> <IonLabel color="primary">Passageiro</IonLabel>
</IonChip> </IonChip>
</div> </div>

View File

@@ -73,6 +73,13 @@ export async function update(userData: UpdateUserRequest) {
return response.data; 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 // TODO, continuar
export async function getSocialInfo(userId: string) { export async function getSocialInfo(userId: string) {
updateHeader(); updateHeader();

View File

@@ -92,4 +92,44 @@ const getUserSocialInfo = async (userId: string): Promise<getByIdReturn> => {
} }
}; };
export default { getById, getUserSocialInfo } 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<checkIfUserIsDriverReturn> => {
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 }