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;
};
const ICON_AMICALE = require('../../../assets/amicale.png');
const ICON_AMICALE = require('../../../../assets/amicale.png');
const styles = StyleSheet.create({
card: {

View file

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

View file

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

View file

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

View file

@ -35,11 +35,13 @@ import LoginForm from '../../components/Amicale/Login/LoginForm';
import { useFocusEffect, useNavigation } from '@react-navigation/native';
import { TabRoutes } from '../../navigation/TabNavigator';
import { useShouldShowMascot } from '../../context/preferencesContext';
import { useLogin } from '../../context/loginContext';
type Props = StackScreenProps<MainStackParamsList, 'login'>;
function LoginScreen(props: Props) {
const navigation = useNavigation<StackNavigationProp<any>>();
const { setLogin } = useLogin();
const [loading, setLoading] = useState(false);
const [nextScreen, setNextScreen] = useState<string | undefined>(undefined);
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.
* 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
if (homeMascot.shouldShow) {
homeMascot.setShouldShow(false);
}
setLogin(token);
if (!nextScreen) {
navigation.goBack();
} else {
@ -138,7 +141,10 @@ function LoginScreen(props: Props) {
emotion={MASCOT_STYLE.NORMAL}
/>
<ErrorDialog
visible={currentError.status !== REQUEST_STATUS.SUCCESS}
visible={
currentError.status !== REQUEST_STATUS.SUCCESS ||
currentError.code !== undefined
}
onDismiss={hideErrorDialog}
status={currentError.status}
code={currentError.code}