Browse Source

Fix state errors

Arnaud Vergnet 6 months ago
parent
commit
ffa4cfa376

+ 1
- 1
src/components/Amicale/Login/LoginForm.tsx View File

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

+ 1
- 0
src/components/Amicale/LogoutDialog.tsx View File

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

+ 4
- 1
src/components/Amicale/Vote/VoteSelect.tsx View File

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

+ 4
- 1
src/screens/Amicale/Equipment/EquipmentRentScreen.tsx View File

@@ -407,7 +407,10 @@ function EquipmentRentScreen(props: Props) {
407 407
         />
408 408
 
409 409
         <ErrorDialog
410
-          visible={currentError.status !== REQUEST_STATUS.SUCCESS}
410
+          visible={
411
+            currentError.status !== REQUEST_STATUS.SUCCESS ||
412
+            currentError.code !== undefined
413
+          }
411 414
           onDismiss={onErrorDialogDismiss}
412 415
           status={currentError.status}
413 416
           code={currentError.code}

+ 8
- 2
src/screens/Amicale/LoginScreen.tsx View File

@@ -35,11 +35,13 @@ import LoginForm from '../../components/Amicale/Login/LoginForm';
35 35
 import { useFocusEffect, useNavigation } from '@react-navigation/native';
36 36
 import { TabRoutes } from '../../navigation/TabNavigator';
37 37
 import { useShouldShowMascot } from '../../context/preferencesContext';
38
+import { useLogin } from '../../context/loginContext';
38 39
 
39 40
 type Props = StackScreenProps<MainStackParamsList, 'login'>;
40 41
 
41 42
 function LoginScreen(props: Props) {
42 43
   const navigation = useNavigation<StackNavigationProp<any>>();
44
+  const { setLogin } = useLogin();
43 45
   const [loading, setLoading] = useState(false);
44 46
   const [nextScreen, setNextScreen] = useState<string | undefined>(undefined);
45 47
   const [mascotDialogVisible, setMascotDialogVisible] = useState(false);
@@ -88,11 +90,12 @@ function LoginScreen(props: Props) {
88 90
    * Navigates to the screen specified in navigation parameters or simply go back tha stack.
89 91
    * Saves in user preferences to not show the login banner again.
90 92
    */
91
-  const handleSuccess = () => {
93
+  const handleSuccess = (token: string) => {
92 94
     // Do not show the home login banner again
93 95
     if (homeMascot.shouldShow) {
94 96
       homeMascot.setShouldShow(false);
95 97
     }
98
+    setLogin(token);
96 99
     if (!nextScreen) {
97 100
       navigation.goBack();
98 101
     } else {
@@ -138,7 +141,10 @@ function LoginScreen(props: Props) {
138 141
             emotion={MASCOT_STYLE.NORMAL}
139 142
           />
140 143
           <ErrorDialog
141
-            visible={currentError.status !== REQUEST_STATUS.SUCCESS}
144
+            visible={
145
+              currentError.status !== REQUEST_STATUS.SUCCESS ||
146
+              currentError.code !== undefined
147
+            }
142 148
             onDismiss={hideErrorDialog}
143 149
             status={currentError.status}
144 150
             code={currentError.code}

Loading…
Cancel
Save