@vijayp-07/react-native-boiler-plate 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +355 -64
- package/package.json +1 -1
- package/template/README.md +108 -5
- package/template/src/api/apiMethods.ts +65 -0
- package/template/src/api/axiosInstance.ts +10 -20
- package/template/src/api/endPoints.ts +18 -0
- package/template/src/api/index.ts +3 -0
- package/template/src/appRedux/modules/ProfileSlice.ts +3 -3
- package/template/src/assets/images/IC_HidePassword.svg +4 -0
- package/template/src/assets/images/IC_ShowPassword.svg +4 -0
- package/template/src/assets/images/index.ts +4 -0
- package/template/src/components/Container.tsx +62 -0
- package/template/src/components/PrimaryFlashMessage.tsx +0 -2
- package/template/src/components/PrimaryLoader.tsx +1 -1
- package/template/src/components/PrimaryTextInput.tsx +84 -0
- package/template/src/components/index.ts +4 -0
- package/template/src/i18n/en.json +12 -8
- package/template/src/i18n/es.json +13 -9
- package/template/src/i18n/hi.json +34 -0
- package/template/src/i18n/i18n.ts +5 -1
- package/template/src/screens/Home/index.tsx +3 -10
- package/template/src/screens/Login/index.tsx +69 -17
- package/template/src/screens/ModalScreen/index.tsx +1 -1
- package/template/src/screens/Profile/index.tsx +11 -3
- package/template/src/services/authService.ts +23 -0
- package/template/src/services/index.ts +1 -0
- package/template/src/types/index.ts +72 -6
- package/template/yarn.lock +7488 -0
|
@@ -1,33 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import React, {FC, useState} from 'react';
|
|
2
|
+
import {StyleSheet} from 'react-native';
|
|
3
3
|
import {AuthStackScreenProps} from '@types';
|
|
4
4
|
import {colors, perfectSize} from '@theme';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Container,
|
|
7
|
+
PrimaryButton,
|
|
8
|
+
PrimaryText,
|
|
9
|
+
PrimaryTextInput,
|
|
10
|
+
} from '@components';
|
|
6
11
|
import {fonts} from '@fonts';
|
|
7
|
-
import {showDangerMessage} from '@common';
|
|
12
|
+
import {prettyPrint, showDangerMessage, showSuccessMessage} from '@common';
|
|
8
13
|
import {useTranslation} from 'react-i18next';
|
|
9
14
|
import {dispatch, initialState, setUserData} from '@appRedux';
|
|
15
|
+
import {loginService} from '@services';
|
|
16
|
+
import {isEmail, isEmpty} from 'validator';
|
|
10
17
|
|
|
11
18
|
const LogIn: FC<AuthStackScreenProps<'LogIn'>> = ({navigation}) => {
|
|
19
|
+
const [email, setEmail] = useState<string>('');
|
|
20
|
+
const [password, setPassword] = useState<string>('');
|
|
21
|
+
const [isBtnLoading, setIsBtnLoading] = useState<boolean>(false);
|
|
22
|
+
|
|
12
23
|
const {t: translate} = useTranslation();
|
|
24
|
+
const handleLogin = async () => {
|
|
25
|
+
if (isEmpty(email)) {
|
|
26
|
+
showDangerMessage(translate('validations.email'));
|
|
27
|
+
} else if (!isEmail(email)) {
|
|
28
|
+
showDangerMessage(translate('validations.validEmail'));
|
|
29
|
+
} else if (isEmpty(password)) {
|
|
30
|
+
showDangerMessage(translate('validations.password'));
|
|
31
|
+
} else {
|
|
32
|
+
setIsBtnLoading(true);
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
setIsBtnLoading(false);
|
|
35
|
+
showSuccessMessage(translate('messages.loginSuccessful'));
|
|
36
|
+
dispatch(setUserData(initialState.userData));
|
|
37
|
+
}, 5000);
|
|
38
|
+
|
|
39
|
+
// This is the api calling function for yours reference how to call api
|
|
40
|
+
|
|
41
|
+
// const res = await loginService({
|
|
42
|
+
// email: email,
|
|
43
|
+
// password: password,
|
|
44
|
+
// });
|
|
45
|
+
// setIsBtnLoading(false);
|
|
46
|
+
// if (res.success && res.data) {
|
|
47
|
+
// dispatch(setUserData(res.data.user));
|
|
48
|
+
// showSuccessMessage('Login successful!');
|
|
49
|
+
// } else {
|
|
50
|
+
// prettyPrint({res});
|
|
51
|
+
// // showDangerMessage(res.message);
|
|
52
|
+
// }
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
13
56
|
return (
|
|
14
|
-
<
|
|
57
|
+
<Container
|
|
58
|
+
padding={perfectSize(20)}
|
|
59
|
+
style={styles.mainView}
|
|
60
|
+
backgroundColor={colors.white}>
|
|
15
61
|
<PrimaryText style={styles.lblLoginScreen}>
|
|
16
|
-
{translate('loginScreen.
|
|
62
|
+
{translate('loginScreen.logIn')}
|
|
17
63
|
</PrimaryText>
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
64
|
+
<PrimaryTextInput
|
|
65
|
+
placeholder="Email"
|
|
66
|
+
value={email}
|
|
67
|
+
onChangeText={setEmail}
|
|
68
|
+
keyboardType="email-address"
|
|
69
|
+
/>
|
|
70
|
+
<PrimaryTextInput
|
|
71
|
+
placeholder="Password"
|
|
72
|
+
value={password}
|
|
73
|
+
onChangeText={setPassword}
|
|
74
|
+
isPassword
|
|
23
75
|
/>
|
|
24
76
|
<PrimaryButton
|
|
25
|
-
label={translate('loginScreen.
|
|
77
|
+
label={translate('loginScreen.login')}
|
|
26
78
|
onPress={() => {
|
|
27
|
-
|
|
79
|
+
handleLogin();
|
|
28
80
|
}}
|
|
81
|
+
loading={isBtnLoading}
|
|
29
82
|
/>
|
|
30
|
-
</
|
|
83
|
+
</Container>
|
|
31
84
|
);
|
|
32
85
|
};
|
|
33
86
|
|
|
@@ -36,12 +89,11 @@ export default LogIn;
|
|
|
36
89
|
const styles = StyleSheet.create({
|
|
37
90
|
mainView: {
|
|
38
91
|
flex: 1,
|
|
39
|
-
backgroundColor: colors.white,
|
|
40
|
-
justifyContent: 'center',
|
|
41
|
-
alignItems: 'center',
|
|
42
92
|
rowGap: perfectSize(20),
|
|
43
93
|
},
|
|
44
94
|
lblLoginScreen: {
|
|
95
|
+
marginTop: perfectSize(60),
|
|
96
|
+
alignSelf: 'center',
|
|
45
97
|
fontFamily: fonts.bold,
|
|
46
98
|
fontSize: perfectSize(20),
|
|
47
99
|
},
|
|
@@ -6,6 +6,7 @@ import {fonts} from '@fonts';
|
|
|
6
6
|
import {PrimaryButton, PrimaryText} from '@components';
|
|
7
7
|
import {useTranslation} from 'react-i18next';
|
|
8
8
|
import {dispatch, resetUserData, setLanguage} from '@appRedux';
|
|
9
|
+
import {showSuccessMessage} from '@common';
|
|
9
10
|
|
|
10
11
|
const Profile: FC<TabNavigationWithAppStackScreenProps<'Profile'>> = ({
|
|
11
12
|
navigation,
|
|
@@ -30,13 +31,17 @@ const Profile: FC<TabNavigationWithAppStackScreenProps<'Profile'>> = ({
|
|
|
30
31
|
text: translate('languages.es'),
|
|
31
32
|
onPress: async () => dispatch(setLanguage('es')),
|
|
32
33
|
},
|
|
34
|
+
{
|
|
35
|
+
text: translate('languages.hi'),
|
|
36
|
+
onPress: async () => dispatch(setLanguage('hi')),
|
|
37
|
+
},
|
|
33
38
|
],
|
|
34
39
|
);
|
|
35
40
|
};
|
|
36
41
|
|
|
37
42
|
return (
|
|
38
43
|
<View style={styles.mainView}>
|
|
39
|
-
<PrimaryText style={styles.
|
|
44
|
+
<PrimaryText style={styles.lblProfileScreen}>
|
|
40
45
|
{translate('profileScreen.profileScreen')}
|
|
41
46
|
</PrimaryText>
|
|
42
47
|
<PrimaryButton
|
|
@@ -45,7 +50,10 @@ const Profile: FC<TabNavigationWithAppStackScreenProps<'Profile'>> = ({
|
|
|
45
50
|
/>
|
|
46
51
|
<PrimaryButton
|
|
47
52
|
label={translate('profileScreen.logout')}
|
|
48
|
-
onPress={() =>
|
|
53
|
+
onPress={() => {
|
|
54
|
+
dispatch(resetUserData());
|
|
55
|
+
showSuccessMessage(translate('messages.logoutSuccessful'));
|
|
56
|
+
}}
|
|
49
57
|
/>
|
|
50
58
|
</View>
|
|
51
59
|
);
|
|
@@ -61,7 +69,7 @@ const styles = StyleSheet.create({
|
|
|
61
69
|
alignItems: 'center',
|
|
62
70
|
rowGap: perfectSize(20),
|
|
63
71
|
},
|
|
64
|
-
|
|
72
|
+
lblProfileScreen: {
|
|
65
73
|
fontFamily: fonts.bold,
|
|
66
74
|
fontSize: perfectSize(20),
|
|
67
75
|
},
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// ─────────────────────────────────────────────────────
|
|
2
|
+
// AUTH SERVICE
|
|
3
|
+
// All authentication-related API calls live here.
|
|
4
|
+
// ─────────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
import {apiPost, endPoints} from '@api';
|
|
7
|
+
import {ApiResponseType, LoginPayload, LoginResponse} from '@types';
|
|
8
|
+
import {getDetailForAPI} from '@common';
|
|
9
|
+
|
|
10
|
+
// ── API Calls ───────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Login user with email & password
|
|
14
|
+
*/
|
|
15
|
+
export const loginService = async (
|
|
16
|
+
payload: LoginPayload,
|
|
17
|
+
): Promise<ApiResponseType<LoginResponse>> => {
|
|
18
|
+
const deviceInfo = getDetailForAPI();
|
|
19
|
+
return apiPost<LoginResponse>(endPoints.auth.login, {
|
|
20
|
+
...payload,
|
|
21
|
+
...deviceInfo,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './authService';
|
|
@@ -5,34 +5,68 @@ import {
|
|
|
5
5
|
} from '@react-navigation/native';
|
|
6
6
|
import {NativeStackScreenProps} from '@react-navigation/native-stack';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Authentication stack routes
|
|
10
|
+
* Used for screens before user login/authentication
|
|
11
|
+
*/
|
|
8
12
|
export type AuthStackParamList = {
|
|
9
13
|
LogIn: undefined;
|
|
10
14
|
};
|
|
11
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Main application stack routes
|
|
18
|
+
* Contains app-level screens and nested navigators
|
|
19
|
+
*/
|
|
12
20
|
export type AppStackParamList = {
|
|
13
21
|
// https://reactnavigation.org/docs/typescript#nesting-navigators
|
|
14
22
|
TabNavigation?: NavigatorScreenParams<TabScreenRouteProp>;
|
|
15
23
|
ModalScreen: undefined;
|
|
16
24
|
};
|
|
17
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Bottom tab navigator routes
|
|
28
|
+
*/
|
|
18
29
|
export type TabScreenRouteProp = {
|
|
19
30
|
Home: undefined;
|
|
20
31
|
Profile: undefined;
|
|
21
32
|
};
|
|
22
33
|
|
|
23
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Screen props type for Auth stack screens
|
|
36
|
+
*
|
|
37
|
+
* Example:
|
|
38
|
+
* type Props = AuthStackScreenProps<'LogIn'>
|
|
39
|
+
*/
|
|
24
40
|
export type AuthStackScreenProps<T extends keyof AuthStackParamList> =
|
|
25
41
|
NativeStackScreenProps<AuthStackParamList, T>;
|
|
26
42
|
|
|
27
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Screen props type for App stack screens
|
|
45
|
+
*
|
|
46
|
+
* Example:
|
|
47
|
+
* type Props = AppStackScreenProps<'ModalScreen'>
|
|
48
|
+
*/
|
|
28
49
|
export type AppStackScreenProps<T extends keyof AppStackParamList> =
|
|
29
50
|
NativeStackScreenProps<AppStackParamList, T>;
|
|
30
51
|
|
|
31
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Screen props type for Bottom Tab screens
|
|
54
|
+
*
|
|
55
|
+
* Example:
|
|
56
|
+
* type Props = TabNavigationScreenProps<'Home'>
|
|
57
|
+
*/
|
|
32
58
|
export type TabNavigationScreenProps<T extends keyof TabScreenRouteProp> =
|
|
33
59
|
BottomTabScreenProps<TabScreenRouteProp, T>;
|
|
34
60
|
|
|
35
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Combined screen props type
|
|
63
|
+
*
|
|
64
|
+
* Used when a Tab screen also needs access
|
|
65
|
+
* to AppStack navigation methods/screens
|
|
66
|
+
*
|
|
67
|
+
* Example:
|
|
68
|
+
* type Props = TabNavigationWithAppStackScreenProps<'Home'>
|
|
69
|
+
*/
|
|
36
70
|
export type TabNavigationWithAppStackScreenProps<
|
|
37
71
|
T extends keyof TabScreenRouteProp,
|
|
38
72
|
> = CompositeScreenProps<
|
|
@@ -40,6 +74,10 @@ export type TabNavigationWithAppStackScreenProps<
|
|
|
40
74
|
NativeStackScreenProps<AppStackParamList, keyof AppStackParamList>
|
|
41
75
|
>;
|
|
42
76
|
|
|
77
|
+
/**
|
|
78
|
+
* User model type
|
|
79
|
+
* Represents logged-in user data received from API
|
|
80
|
+
*/
|
|
43
81
|
export type UserTypes = {
|
|
44
82
|
_id: string;
|
|
45
83
|
user_name: string;
|
|
@@ -57,8 +95,36 @@ export type UserTypes = {
|
|
|
57
95
|
token: string;
|
|
58
96
|
};
|
|
59
97
|
|
|
60
|
-
|
|
61
|
-
|
|
98
|
+
/**
|
|
99
|
+
* User Language type
|
|
100
|
+
* Represents user selected language
|
|
101
|
+
*/
|
|
102
|
+
export type Languages = 'en' | 'es' | 'hi';
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Common API response structure
|
|
106
|
+
*
|
|
107
|
+
* @template Data - Expected response data type
|
|
108
|
+
*/
|
|
109
|
+
export type ApiResponseType<Data = any> = {
|
|
110
|
+
success: boolean;
|
|
111
|
+
data?: Data | null;
|
|
62
112
|
status: number;
|
|
63
113
|
message: string;
|
|
64
114
|
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Login API request payload
|
|
118
|
+
*/
|
|
119
|
+
export interface LoginPayload {
|
|
120
|
+
email: string;
|
|
121
|
+
password: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Login API response data
|
|
126
|
+
*/
|
|
127
|
+
export interface LoginResponse {
|
|
128
|
+
user: UserTypes;
|
|
129
|
+
token: string;
|
|
130
|
+
}
|