Skip to content

Commit 6231c97

Browse files
authored
fix : display org login error with toast (#75)
- make sure that org login error is desplied using toast not with ApolloError
1 parent 7ee04e6 commit 6231c97

File tree

5 files changed

+60
-20
lines changed

5 files changed

+60
-20
lines changed

Diff for: app/auth/login/index.tsx

+31-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@ import { LOGIN_MUTATION, ORG_LOGIN_MUTATION } from '@/graphql/mutations/login.mu
44
import { ApolloError, useApolloClient, useMutation } from '@apollo/client';
55
import AsyncStorage from '@react-native-async-storage/async-storage';
66
import { Href, useLocalSearchParams, useRouter } from 'expo-router';
7-
import { useEffect, useState } from 'react';
7+
import { useEffect,useState } from 'react';
88
import { useToast } from 'react-native-toast-notifications';
9+
import {ToastAndroid } from 'react-native';
10+
11+
class ErrorHandler {
12+
static handleNetworkError() {
13+
ToastAndroid.show('There was a problem contacting the server', ToastAndroid.LONG);
14+
}
15+
16+
static handleInvalidCredentials() {
17+
ToastAndroid.show('Error Invalid credentials',ToastAndroid.LONG);
18+
}
19+
20+
static handleCustomError(message: string | undefined) {
21+
ToastAndroid.show('Error:' + message,ToastAndroid.LONG);
22+
}
23+
24+
static handleGeneralError() {
25+
ToastAndroid.show('Error An unexpected error occurred.',ToastAndroid.LONG);
26+
}
27+
}
928

1029
export default function SignInOrganization() {
1130
const toast = useToast();
@@ -47,11 +66,13 @@ export default function SignInOrganization() {
4766
setOrgLoginSuccess(true);
4867
},
4968
onError(err: any) {
50-
if (err instanceof ApolloError) {
51-
toast.show(err.message, { type: 'danger' });
52-
} else {
53-
toast.show(err.message, { type: 'danger' });
54-
}
69+
toast.show(err.message,{
70+
type: 'fail',
71+
placement : 'top',
72+
duration : 5000,
73+
animationType : 'slide-in',
74+
style: { backgroundColor: 'red' },
75+
})
5576
},
5677
});
5778
} catch (err: any) {
@@ -94,6 +115,10 @@ export default function SignInOrganization() {
94115
});
95116
return;
96117
}
118+
119+
} else {
120+
await AsyncStorage.setItem('authToken', data.loginUser.token);
121+
router.push('/dashboard');
97122
}
98123
},
99124
onError: (err) => {

Diff for: app/auth/register.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { useEffect, useState } from 'react';
1414
import { useTranslation } from 'react-i18next';
1515
import {
1616
ActivityIndicator,
17-
Alert,
1817
TextInput,
1918
TouchableOpacity,
2019
useColorScheme,
@@ -317,7 +316,7 @@ export default function RegisterForm() {
317316
<TouchableOpacity
318317
onPress={() => {
319318
if (!TCAccepted) {
320-
Alert.alert('Warning', 'Please accept terms and conditions');
319+
toast.show('Please accept terms and conditions', {type:"Warning"});
321320
return;
322321
}
323322
formik.handleSubmit();

Diff for: components/perfomanceStats/index.tsx

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import React, { useEffect, useState } from 'react';
2+
import AsyncStorage from '@react-native-async-storage/async-storage';
13
import { TRAINEE_RATING } from '@/graphql/queries/rating';
24
import { useQuery } from '@apollo/client';
3-
import AsyncStorage from '@react-native-async-storage/async-storage';
4-
import { useEffect, useState } from 'react';
55
import { useTranslation } from 'react-i18next';
66
import {
77
ScrollView,
@@ -16,6 +16,7 @@ import CircularIndicator from './circleIndicator';
1616
import styles from './styles';
1717

1818
const PerformanceScores = () => {
19+
const toast = useToast()
1920
const { t } = useTranslation();
2021
const colors = {
2122
quality: 'rgba(160, 132, 244, 1)',
@@ -24,7 +25,6 @@ const PerformanceScores = () => {
2425
};
2526

2627
const theme = useColorScheme();
27-
const toast = useToast();
2828
const dimensions = useWindowDimensions();
2929

3030
const backgroundColor = theme === 'dark' ? '#020917' : '#fff';
@@ -47,10 +47,20 @@ const PerformanceScores = () => {
4747
if (token) {
4848
setUserToken(token);
4949
} else {
50-
toast.show('User token not found.', { type: 'danger' });
50+
toast.show('Error: User token not found.', {
51+
type: 'danger',
52+
placement: 'top',
53+
duration: 4000,
54+
animationType: 'slide-in',
55+
});
5156
}
5257
} catch (error) {
53-
toast.show('Failed to fetch token.', { type: 'danger' });
58+
toast.show('Error: Failed to fetch token.', {
59+
type: 'danger',
60+
placement: 'top',
61+
duration: 4000,
62+
animationType: 'slide-in',
63+
});
5464
}
5565
};
5666
fetchToken();

Diff for: components/sidebar.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ interface SidebarProps {
3232
}
3333

3434
const Sidebar: React.FC<SidebarProps> = ({ onClose }) => {
35+
const toast = useToast();
3536
const [activeItem, setActiveItem] = useState<string | null>(null);
3637
const router = useRouter();
3738
const pathname = usePathname();
3839
const colorScheme = useColorScheme();
3940
const { t } = useTranslation();
4041
const client = useApolloClient();
41-
const toast = useToast();
4242

4343
const UpperItems = [
4444
{
@@ -104,7 +104,12 @@ const Sidebar: React.FC<SidebarProps> = ({ onClose }) => {
104104
await AsyncStorage.removeItem('auth');
105105
router.push('/auth/login?logout=1');
106106
} catch (error) {
107-
toast.show(`Failed to log out. Please try again.`);
107+
toast.show(`Error logging out:${error}`, {
108+
type: 'danger',
109+
placement: 'top',
110+
duration: 4000,
111+
animationType: 'slide-in',
112+
});
108113
}
109114
};
110115

@@ -119,10 +124,11 @@ const Sidebar: React.FC<SidebarProps> = ({ onClose }) => {
119124
onClose();
120125
}
121126
} catch (error) {
122-
toast.show(`Failed to navigate: ${error}`, {
127+
toast.show(`Failed to navigate:${error}`, {
123128
type: 'danger',
124129
placement: 'top',
125-
duration: 3000,
130+
duration: 4000,
131+
animationType: 'slide-in',
126132
});
127133
}
128134
};

Diff for: components/sprintRatings.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function TraineeRatings({
3030
if (token) {
3131
setUserToken(token);
3232
} else {
33-
toast.show(t('sprintRating.user_token_not_found'), { type: 'danger' });
33+
toast.show(t('sprintRating.error') + t('sprintRating.user_token_not_found'), {type:"danger"});
3434
}
3535
};
3636
fetchToken();
@@ -56,7 +56,7 @@ export default function TraineeRatings({
5656

5757
useEffect(() => {
5858
if (error) {
59-
toast.show(t('sprintRating.error_loading_ratings'), { type: 'danger' });
59+
toast.show(t('sprintRating.error')+t('sprintRating.error_loading_ratings'),{type:"danger"});
6060
}
6161
}, [loading, error]);
6262

@@ -136,7 +136,7 @@ export default function TraineeRatings({
136136
className="flex-row items-center text-white"
137137
>
138138
<AntDesign name="eye" size={15} color="white" />
139-
<Text className="text-white ml-1">{t('sprintRating.view')}</Text>
139+
<Text className="ml-1 text-white">{t('sprintRating.view')}</Text>
140140
</TouchableOpacity>
141141
</View>
142142
</View>

0 commit comments

Comments
 (0)