Fix state errors

This commit is contained in:
Arnaud Vergnet 2021-05-23 15:04:19 +02:00
parent 541c002558
commit ffa4cfa376
5 changed files with 18 additions and 5 deletions

View file

@ -22,7 +22,7 @@ type Props = {
onResetPasswordPress: () => void; onResetPasswordPress: () => void;
}; };
const ICON_AMICALE = require('../../../assets/amicale.png'); const ICON_AMICALE = require('../../../../assets/amicale.png');
const styles = StyleSheet.create({ const styles = StyleSheet.create({
card: { card: {

View file

@ -33,6 +33,7 @@ function LogoutDialog(props: PropsType) {
const onClickAccept = async (): Promise<void> => { const onClickAccept = async (): Promise<void> => {
return new Promise((resolve: () => void) => { return new Promise((resolve: () => void) => {
onLogout(); onLogout();
props.onDismiss();
resolve(); resolve();
}); });
}; };

View file

@ -128,7 +128,10 @@ function VoteSelect(props: Props) {
message={i18n.t('screens.vote.select.dialogMessage')} message={i18n.t('screens.vote.select.dialogMessage')}
/> />
<ErrorDialog <ErrorDialog
visible={currentError.status !== REQUEST_STATUS.SUCCESS} visible={
currentError.status !== REQUEST_STATUS.SUCCESS ||
currentError.code !== undefined
}
onDismiss={onErrorDialogDismiss} onDismiss={onErrorDialogDismiss}
status={currentError.status} status={currentError.status}
code={currentError.code} code={currentError.code}

View file

@ -407,7 +407,10 @@ function EquipmentRentScreen(props: Props) {
/> />
<ErrorDialog <ErrorDialog
visible={currentError.status !== REQUEST_STATUS.SUCCESS} visible={
currentError.status !== REQUEST_STATUS.SUCCESS ||
currentError.code !== undefined
}
onDismiss={onErrorDialogDismiss} onDismiss={onErrorDialogDismiss}
status={currentError.status} status={currentError.status}
code={currentError.code} code={currentError.code}

View file

@ -35,11 +35,13 @@ import LoginForm from '../../components/Amicale/Login/LoginForm';
import { useFocusEffect, useNavigation } from '@react-navigation/native'; import { useFocusEffect, useNavigation } from '@react-navigation/native';
import { TabRoutes } from '../../navigation/TabNavigator'; import { TabRoutes } from '../../navigation/TabNavigator';
import { useShouldShowMascot } from '../../context/preferencesContext'; import { useShouldShowMascot } from '../../context/preferencesContext';
import { useLogin } from '../../context/loginContext';
type Props = StackScreenProps<MainStackParamsList, 'login'>; type Props = StackScreenProps<MainStackParamsList, 'login'>;
function LoginScreen(props: Props) { function LoginScreen(props: Props) {
const navigation = useNavigation<StackNavigationProp<any>>(); const navigation = useNavigation<StackNavigationProp<any>>();
const { setLogin } = useLogin();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [nextScreen, setNextScreen] = useState<string | undefined>(undefined); const [nextScreen, setNextScreen] = useState<string | undefined>(undefined);
const [mascotDialogVisible, setMascotDialogVisible] = useState(false); const [mascotDialogVisible, setMascotDialogVisible] = useState(false);
@ -88,11 +90,12 @@ function LoginScreen(props: Props) {
* Navigates to the screen specified in navigation parameters or simply go back tha stack. * Navigates to the screen specified in navigation parameters or simply go back tha stack.
* Saves in user preferences to not show the login banner again. * Saves in user preferences to not show the login banner again.
*/ */
const handleSuccess = () => { const handleSuccess = (token: string) => {
// Do not show the home login banner again // Do not show the home login banner again
if (homeMascot.shouldShow) { if (homeMascot.shouldShow) {
homeMascot.setShouldShow(false); homeMascot.setShouldShow(false);
} }
setLogin(token);
if (!nextScreen) { if (!nextScreen) {
navigation.goBack(); navigation.goBack();
} else { } else {
@ -138,7 +141,10 @@ function LoginScreen(props: Props) {
emotion={MASCOT_STYLE.NORMAL} emotion={MASCOT_STYLE.NORMAL}
/> />
<ErrorDialog <ErrorDialog
visible={currentError.status !== REQUEST_STATUS.SUCCESS} visible={
currentError.status !== REQUEST_STATUS.SUCCESS ||
currentError.code !== undefined
}
onDismiss={hideErrorDialog} onDismiss={hideErrorDialog}
status={currentError.status} status={currentError.status}
code={currentError.code} code={currentError.code}