Diversas melhorias e toasts aparecem em redirecionamentos de páginas
This commit is contained in:
@@ -1,17 +1,40 @@
|
||||
import { IonButton, IonContent, IonPage } from '@ionic/react';
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { useHistory } from 'react-router';
|
||||
import { IonContent, IonPage, IonToast } from '@ionic/react';
|
||||
import { Color } from '@ionic/react/node_modules/@ionic/core';
|
||||
import { useContext, useEffect, useState } from 'react';
|
||||
import { useLocation } from 'react-router';
|
||||
|
||||
import { UserContext } from '../App';
|
||||
|
||||
import * as sessionRoutes from '../services/api/session';
|
||||
|
||||
interface LocationState {
|
||||
redirectData?: {
|
||||
showToastMessage: boolean;
|
||||
toastColor: Color;
|
||||
toastMessage: string;
|
||||
}
|
||||
}
|
||||
|
||||
const Home: React.FC = () => {
|
||||
const history = useHistory()
|
||||
const location = useLocation<LocationState>();
|
||||
|
||||
const user = useContext(UserContext);
|
||||
|
||||
const [showToast, setShowToast] = useState(false);
|
||||
const [toastMessage, setToastMessage] = useState('');
|
||||
const [toastColor, setToastColor] = useState<Color>("primary");
|
||||
|
||||
useEffect(() => {
|
||||
if (location.state && location.state.redirectData) {
|
||||
const redirectData = location.state.redirectData
|
||||
|
||||
if (redirectData.showToastMessage) {
|
||||
setToastColor(redirectData.toastColor)
|
||||
setToastMessage(redirectData.toastMessage)
|
||||
setShowToast(true)
|
||||
}
|
||||
}
|
||||
|
||||
const refreshUserToken = async () => {
|
||||
await sessionRoutes.refresh().then(response => {
|
||||
if (response.status === 'error') {
|
||||
@@ -33,12 +56,19 @@ const Home: React.FC = () => {
|
||||
}
|
||||
|
||||
refreshUserToken()
|
||||
})
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<IonPage>
|
||||
<IonContent>
|
||||
{/* <IonButton onClick={() => { history.push({ pathname: '/usuario/56520ae7-faf8-4444-a82b-7f3990ab02d8' }); }}>Ir para o perfil de outra pessoa</IonButton> */}
|
||||
<IonToast
|
||||
position="top"
|
||||
color={toastColor}
|
||||
isOpen={showToast}
|
||||
onDidDismiss={() => setShowToast(false)}
|
||||
message={toastMessage}
|
||||
duration={2500}
|
||||
/>
|
||||
</IonContent>
|
||||
</IonPage>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user