@umang-thakkar/base-template 1.0.8 → 1.1.0
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 +110 -38
- package/package.json +1 -1
- package/template/.eslintignore +12 -0
- package/template/.eslintrc +130 -0
- package/template/App.tsx +32 -31
- package/template/Main.tsx +11 -11
- package/template/android/app/build.gradle +2 -2
- package/template/android/app/src/main/AndroidManifest.xml +1 -0
- package/template/android/app/src/main/java/com/basetemplate/MainApplication.kt +10 -21
- package/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/template/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/template/android/gradlew +1 -1
- package/template/ios/BaseTemplate/Info.plist +8 -2
- package/template/ios/BaseTemplate.xcodeproj/project.pbxproj +5 -8
- package/template/ios/Podfile +0 -1
- package/template/package.json +26 -25
- package/template/src/components/ErrorBoundary.tsx +154 -0
- package/template/src/helper/common-functions.ts +13 -18
- package/template/src/navigation/AppStackParams.ts +4 -3
- package/template/src/navigation/screens.ts +9 -7
- package/template/src/redux/slices/authSlice.ts +45 -0
- package/template/src/redux/store.ts +24 -7
- package/template/src/redux/types.d.ts +40 -1
- package/template/src/screens/LoginScreen.tsx +105 -0
- package/template/src/screens/SplashScreen.tsx +32 -23
- package/template/src/theme/darkTheme.ts +5 -4
- package/template/src/theme/lightTheme.ts +6 -5
- package/template/tsconfig.json +7 -2
- package/template/android/app/src/debug/AndroidManifest.xml +0 -9
- package/template/yarn.lock +0 -7003
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
|
|
12
12
|
761780ED2CA45674006654EE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 761780EC2CA45674006654EE /* AppDelegate.swift */; };
|
|
13
13
|
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
|
|
14
|
-
F51ED5429573E67DACCDD39C /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */; };
|
|
15
14
|
/* End PBXBuildFile section */
|
|
16
15
|
|
|
17
16
|
/* Begin PBXFileReference section */
|
|
@@ -160,7 +159,6 @@
|
|
|
160
159
|
files = (
|
|
161
160
|
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
|
|
162
161
|
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
|
|
163
|
-
F51ED5429573E67DACCDD39C /* PrivacyInfo.xcprivacy in Resources */,
|
|
164
162
|
);
|
|
165
163
|
runOnlyForDeploymentPostprocessing = 0;
|
|
166
164
|
};
|
|
@@ -181,7 +179,7 @@
|
|
|
181
179
|
);
|
|
182
180
|
runOnlyForDeploymentPostprocessing = 0;
|
|
183
181
|
shellPath = /bin/sh;
|
|
184
|
-
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
|
|
182
|
+
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"\\\"$WITH_ENVIRONMENT\\\" \\\"$REACT_NATIVE_XCODE\\\"\"\n";
|
|
185
183
|
};
|
|
186
184
|
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
|
|
187
185
|
isa = PBXShellScriptBuildPhase;
|
|
@@ -275,8 +273,10 @@
|
|
|
275
273
|
);
|
|
276
274
|
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
|
|
277
275
|
PRODUCT_NAME = BaseTemplate;
|
|
276
|
+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
|
|
278
277
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
|
279
278
|
SWIFT_VERSION = 5.0;
|
|
279
|
+
TARGETED_DEVICE_FAMILY = "1,2";
|
|
280
280
|
VERSIONING_SYSTEM = "apple-generic";
|
|
281
281
|
};
|
|
282
282
|
name = Debug;
|
|
@@ -302,7 +302,9 @@
|
|
|
302
302
|
);
|
|
303
303
|
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
|
|
304
304
|
PRODUCT_NAME = BaseTemplate;
|
|
305
|
+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
|
|
305
306
|
SWIFT_VERSION = 5.0;
|
|
307
|
+
TARGETED_DEVICE_FAMILY = "1,2";
|
|
306
308
|
VERSIONING_SYSTEM = "apple-generic";
|
|
307
309
|
};
|
|
308
310
|
name = Release;
|
|
@@ -376,10 +378,7 @@
|
|
|
376
378
|
"-DFOLLY_CFG_NO_COROUTINES=1",
|
|
377
379
|
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
|
|
378
380
|
);
|
|
379
|
-
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
|
380
381
|
SDKROOT = iphoneos;
|
|
381
|
-
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
|
|
382
|
-
USE_HERMES = true;
|
|
383
382
|
};
|
|
384
383
|
name = Debug;
|
|
385
384
|
};
|
|
@@ -444,9 +443,7 @@
|
|
|
444
443
|
"-DFOLLY_CFG_NO_COROUTINES=1",
|
|
445
444
|
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
|
|
446
445
|
);
|
|
447
|
-
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
|
448
446
|
SDKROOT = iphoneos;
|
|
449
|
-
USE_HERMES = true;
|
|
450
447
|
VALIDATE_PRODUCT = YES;
|
|
451
448
|
};
|
|
452
449
|
name = Release;
|
package/template/ios/Podfile
CHANGED
package/template/package.json
CHANGED
|
@@ -10,46 +10,47 @@
|
|
|
10
10
|
"test": "jest"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@react-native-async-storage/async-storage": "^
|
|
14
|
-
"@react-navigation/native": "^7.
|
|
15
|
-
"@react-navigation/native-stack": "^7.
|
|
16
|
-
"@react-navigation/stack": "^7.
|
|
17
|
-
"@reduxjs/toolkit": "^2.
|
|
18
|
-
"@tanstack/react-query": "^5.
|
|
19
|
-
"axios": "^1.
|
|
20
|
-
"
|
|
21
|
-
"react": "19.
|
|
22
|
-
"react-native": "0.
|
|
23
|
-
"react-native-gesture-handler": "^
|
|
24
|
-
"react-native-
|
|
25
|
-
"react-native-safe-area-context": "^5.5.2",
|
|
13
|
+
"@react-native-async-storage/async-storage": "^3.1.1",
|
|
14
|
+
"@react-navigation/native": "^7.3.3",
|
|
15
|
+
"@react-navigation/native-stack": "^7.17.5",
|
|
16
|
+
"@react-navigation/stack": "^7.10.5",
|
|
17
|
+
"@reduxjs/toolkit": "^2.12.0",
|
|
18
|
+
"@tanstack/react-query": "^5.101.0",
|
|
19
|
+
"axios": "^1.18.0",
|
|
20
|
+
"date-fns": "^4.4.0",
|
|
21
|
+
"react": "19.2.3",
|
|
22
|
+
"react-native": "0.84.0",
|
|
23
|
+
"react-native-gesture-handler": "^3.0.1",
|
|
24
|
+
"react-native-safe-area-context": "^5.8.0",
|
|
26
25
|
"react-native-screens": "^4.15.0",
|
|
27
26
|
"react-native-svg": "^15.12.1",
|
|
28
|
-
"react-native-
|
|
29
|
-
"react-
|
|
27
|
+
"react-native-reanimated": "^4.4.1",
|
|
28
|
+
"react-native-worklets": "^0.9.0",
|
|
29
|
+
"react-redux": "^9.3.0",
|
|
30
|
+
"redux-persist": "^6.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@babel/core": "^7.25.2",
|
|
33
34
|
"@babel/preset-env": "^7.25.3",
|
|
34
35
|
"@babel/runtime": "^7.25.0",
|
|
35
|
-
"@react-native-community/cli": "20.
|
|
36
|
-
"@react-native-community/cli-platform-android": "20.
|
|
37
|
-
"@react-native-community/cli-platform-ios": "20.
|
|
38
|
-
"@react-native/babel-preset": "0.
|
|
39
|
-
"@react-native/eslint-config": "0.
|
|
40
|
-
"@react-native/metro-config": "0.
|
|
41
|
-
"@react-native/typescript-config": "0.
|
|
36
|
+
"@react-native-community/cli": "20.1.0",
|
|
37
|
+
"@react-native-community/cli-platform-android": "20.1.0",
|
|
38
|
+
"@react-native-community/cli-platform-ios": "20.1.0",
|
|
39
|
+
"@react-native/babel-preset": "0.84.0",
|
|
40
|
+
"@react-native/eslint-config": "0.84.0",
|
|
41
|
+
"@react-native/metro-config": "0.84.0",
|
|
42
|
+
"@react-native/typescript-config": "0.84.0",
|
|
42
43
|
"@tanstack/eslint-plugin-query": "^5.83.1",
|
|
43
44
|
"@types/jest": "^29.5.13",
|
|
44
|
-
"@types/react": "^19.
|
|
45
|
+
"@types/react": "^19.2.0",
|
|
45
46
|
"@types/react-test-renderer": "^19.1.0",
|
|
46
47
|
"eslint": "^8.19.0",
|
|
47
48
|
"jest": "^29.6.3",
|
|
48
49
|
"prettier": "2.8.8",
|
|
49
|
-
"react-test-renderer": "19.
|
|
50
|
+
"react-test-renderer": "19.2.3",
|
|
50
51
|
"typescript": "^5.8.3"
|
|
51
52
|
},
|
|
52
53
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
54
|
+
"node": ">= 22.11.0"
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import React, { ReactNode, ErrorInfo } from "react";
|
|
2
|
+
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface State {
|
|
9
|
+
hasError: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
errorInfo: ErrorInfo | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Error Boundary Component
|
|
16
|
+
* Catches JavaScript errors anywhere in the child component tree
|
|
17
|
+
* and displays a fallback UI instead of crashing the app
|
|
18
|
+
*/
|
|
19
|
+
export class ErrorBoundary extends React.Component<Props, State> {
|
|
20
|
+
constructor(props: Props) {
|
|
21
|
+
super(props);
|
|
22
|
+
this.state = {
|
|
23
|
+
hasError: false,
|
|
24
|
+
error: null,
|
|
25
|
+
errorInfo: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static getDerivedStateFromError(error: Error): Partial<State> {
|
|
30
|
+
return { hasError: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
34
|
+
// Log error details for debugging
|
|
35
|
+
console.error("ErrorBoundary caught an error:", error);
|
|
36
|
+
console.error("Error Info:", errorInfo);
|
|
37
|
+
|
|
38
|
+
this.setState({
|
|
39
|
+
error,
|
|
40
|
+
errorInfo,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
resetError = () => {
|
|
45
|
+
this.setState({
|
|
46
|
+
hasError: false,
|
|
47
|
+
error: null,
|
|
48
|
+
errorInfo: null,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
if (this.state.hasError) {
|
|
54
|
+
return (
|
|
55
|
+
<View style={styles.container}>
|
|
56
|
+
<View style={styles.content}>
|
|
57
|
+
<Text style={styles.title}>⚠️ Something Went Wrong</Text>
|
|
58
|
+
<Text style={styles.message}>
|
|
59
|
+
The app encountered an unexpected error. Please try restarting.
|
|
60
|
+
</Text>
|
|
61
|
+
|
|
62
|
+
{__DEV__ && this.state.error && (
|
|
63
|
+
<View style={styles.errorDetails}>
|
|
64
|
+
<Text style={styles.errorTitle}>Error Details:</Text>
|
|
65
|
+
<Text style={styles.errorText}>
|
|
66
|
+
{this.state.error.toString()}
|
|
67
|
+
</Text>
|
|
68
|
+
{this.state.errorInfo && (
|
|
69
|
+
<Text style={styles.stackTrace}>
|
|
70
|
+
{this.state.errorInfo.componentStack}
|
|
71
|
+
</Text>
|
|
72
|
+
)}
|
|
73
|
+
</View>
|
|
74
|
+
)}
|
|
75
|
+
|
|
76
|
+
<TouchableOpacity style={styles.button} onPress={this.resetError}>
|
|
77
|
+
<Text style={styles.buttonText}>Try Again</Text>
|
|
78
|
+
</TouchableOpacity>
|
|
79
|
+
</View>
|
|
80
|
+
</View>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return this.props.children;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const styles = StyleSheet.create({
|
|
89
|
+
container: {
|
|
90
|
+
flex: 1,
|
|
91
|
+
backgroundColor: "#f5f5f5",
|
|
92
|
+
justifyContent: "center",
|
|
93
|
+
alignItems: "center",
|
|
94
|
+
padding: 20,
|
|
95
|
+
},
|
|
96
|
+
content: {
|
|
97
|
+
backgroundColor: "#ffffff",
|
|
98
|
+
borderRadius: 12,
|
|
99
|
+
padding: 24,
|
|
100
|
+
alignItems: "center",
|
|
101
|
+
shadowColor: "#000",
|
|
102
|
+
shadowOffset: { width: 0, height: 2 },
|
|
103
|
+
shadowOpacity: 0.1,
|
|
104
|
+
shadowRadius: 8,
|
|
105
|
+
elevation: 5,
|
|
106
|
+
},
|
|
107
|
+
title: {
|
|
108
|
+
fontSize: 20,
|
|
109
|
+
fontWeight: "bold",
|
|
110
|
+
color: "#333333",
|
|
111
|
+
marginBottom: 12,
|
|
112
|
+
textAlign: "center",
|
|
113
|
+
},
|
|
114
|
+
message: {
|
|
115
|
+
fontSize: 16,
|
|
116
|
+
color: "#666666",
|
|
117
|
+
textAlign: "center",
|
|
118
|
+
marginBottom: 20,
|
|
119
|
+
lineHeight: 22,
|
|
120
|
+
},
|
|
121
|
+
errorDetails: {
|
|
122
|
+
backgroundColor: "#ffe6e6",
|
|
123
|
+
borderRadius: 8,
|
|
124
|
+
padding: 12,
|
|
125
|
+
marginBottom: 20,
|
|
126
|
+
maxHeight: 200,
|
|
127
|
+
},
|
|
128
|
+
errorTitle: {
|
|
129
|
+
fontWeight: "600",
|
|
130
|
+
color: "#d32f2f",
|
|
131
|
+
marginBottom: 8,
|
|
132
|
+
},
|
|
133
|
+
errorText: {
|
|
134
|
+
color: "#c62828",
|
|
135
|
+
fontSize: 12,
|
|
136
|
+
marginBottom: 8,
|
|
137
|
+
},
|
|
138
|
+
stackTrace: {
|
|
139
|
+
color: "#c62828",
|
|
140
|
+
fontSize: 10,
|
|
141
|
+
fontFamily: "Courier New",
|
|
142
|
+
},
|
|
143
|
+
button: {
|
|
144
|
+
backgroundColor: "#4045EF",
|
|
145
|
+
paddingHorizontal: 32,
|
|
146
|
+
paddingVertical: 12,
|
|
147
|
+
borderRadius: 8,
|
|
148
|
+
},
|
|
149
|
+
buttonText: {
|
|
150
|
+
color: "#ffffff",
|
|
151
|
+
fontSize: 16,
|
|
152
|
+
fontWeight: "600",
|
|
153
|
+
},
|
|
154
|
+
});
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import
|
|
2
|
+
import { format, isValid, parseISO } from "date-fns";
|
|
3
3
|
|
|
4
4
|
const errorMessage = (error: unknown): string => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
if (axios.isAxiosError(error)) {
|
|
6
|
+
return error.response?.data?.message || error.message;
|
|
7
|
+
}
|
|
8
|
+
return String(error);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export function toFormattedDate(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
): string |
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return date.format(format);
|
|
24
|
-
}
|
|
12
|
+
dateString: string,
|
|
13
|
+
formatStr: string,
|
|
14
|
+
): string | null {
|
|
15
|
+
if (!dateString) return null;
|
|
16
|
+
const date = parseISO(dateString);
|
|
17
|
+
if (!isValid(date)) return null;
|
|
18
|
+
return format(date, formatStr);
|
|
19
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { StackNavigationOptions } from "@react-navigation/stack";
|
|
2
2
|
import HomeScreen from "../screens/HomeScreen";
|
|
3
3
|
import SplashScreen from "../screens/SplashScreen";
|
|
4
|
+
import LoginScreen from "../screens/LoginScreen";
|
|
4
5
|
import { AppStackParams } from "./AppStackParams";
|
|
5
6
|
|
|
6
7
|
export const screens: Array<{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
name: keyof AppStackParams;
|
|
9
|
+
component: React.ComponentType<any>;
|
|
10
|
+
options?: StackNavigationOptions;
|
|
10
11
|
}> = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
{ name: "SplashScreen", component: SplashScreen },
|
|
13
|
+
{ name: "LoginScreen", component: LoginScreen },
|
|
14
|
+
{ name: "HomeScreen", component: HomeScreen },
|
|
15
|
+
// Add your other screens here
|
|
16
|
+
];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
2
|
+
|
|
3
|
+
type User = { [key: string]: any } | null;
|
|
4
|
+
|
|
5
|
+
interface AuthState {
|
|
6
|
+
user: User;
|
|
7
|
+
accessToken: string | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const initialState: AuthState = {
|
|
11
|
+
user: null,
|
|
12
|
+
accessToken: null,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const authSlice = createSlice({
|
|
16
|
+
name: "auth",
|
|
17
|
+
initialState,
|
|
18
|
+
reducers: {
|
|
19
|
+
setCredentials(
|
|
20
|
+
state,
|
|
21
|
+
action: PayloadAction<{ user: User; accessToken: string }>,
|
|
22
|
+
) {
|
|
23
|
+
state.user = action.payload.user;
|
|
24
|
+
state.accessToken = action.payload.accessToken;
|
|
25
|
+
},
|
|
26
|
+
setUser(state, action: PayloadAction<User>) {
|
|
27
|
+
state.user = action.payload;
|
|
28
|
+
},
|
|
29
|
+
setAccessToken(state, action: PayloadAction<string | null>) {
|
|
30
|
+
state.accessToken = action.payload;
|
|
31
|
+
},
|
|
32
|
+
clearAuth(state) {
|
|
33
|
+
state.user = null;
|
|
34
|
+
state.accessToken = null;
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const { setCredentials, setUser, setAccessToken, clearAuth } =
|
|
40
|
+
authSlice.actions;
|
|
41
|
+
|
|
42
|
+
export const selectCurrentUser = (state: any) => state.auth?.user;
|
|
43
|
+
export const selectAccessToken = (state: any) => state.auth?.accessToken;
|
|
44
|
+
|
|
45
|
+
export default authSlice.reducer;
|
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
import { configureStore } from
|
|
2
|
-
import { TypedUseSelectorHook, useDispatch, useSelector } from
|
|
3
|
-
import
|
|
1
|
+
import { combineReducers, configureStore } from "@reduxjs/toolkit";
|
|
2
|
+
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
|
|
3
|
+
import { persistReducer, persistStore } from "redux-persist";
|
|
4
|
+
import reducer from "./slice";
|
|
5
|
+
import authReducer from "./slices/authSlice";
|
|
6
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
7
|
+
const persistConfig = {
|
|
8
|
+
key: "root",
|
|
9
|
+
storage: AsyncStorage,
|
|
10
|
+
whitelist: ["auth"],
|
|
11
|
+
};
|
|
4
12
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
const rootReducer = combineReducers({
|
|
14
|
+
global: reducer,
|
|
15
|
+
auth: authReducer,
|
|
16
|
+
});
|
|
17
|
+
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
|
18
|
+
export const store = configureStore({
|
|
19
|
+
reducer: persistedReducer,
|
|
20
|
+
middleware: (getDefaultMiddleware) =>
|
|
21
|
+
getDefaultMiddleware({
|
|
22
|
+
serializableCheck: false,
|
|
23
|
+
}),
|
|
9
24
|
});
|
|
10
25
|
export default store;
|
|
11
26
|
|
|
27
|
+
export const persistor = persistStore(store);
|
|
28
|
+
|
|
12
29
|
export type RootStore = ReturnType<typeof store.getState>;
|
|
13
30
|
export type AppDispatch = typeof store.dispatch;
|
|
14
31
|
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* API Error Response Type
|
|
3
|
+
*/
|
|
4
|
+
export interface ApiErrorResponse {
|
|
5
|
+
message: string;
|
|
6
|
+
statusCode?: number;
|
|
7
|
+
code?: string;
|
|
8
|
+
details?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* API Success Response Type
|
|
13
|
+
*/
|
|
14
|
+
export interface ApiSuccessResponse<T> {
|
|
15
|
+
data: T;
|
|
16
|
+
message?: string;
|
|
17
|
+
statusCode?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Todo Item Type
|
|
22
|
+
*/
|
|
23
|
+
export interface TodoItem {
|
|
24
|
+
id: number;
|
|
25
|
+
title: string;
|
|
26
|
+
completed: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Pagination Type
|
|
31
|
+
*/
|
|
32
|
+
export interface PaginationOptions {
|
|
33
|
+
page: number;
|
|
34
|
+
limit: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generic API Response
|
|
39
|
+
*/
|
|
40
|
+
export type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
TextInput,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
} from "react-native";
|
|
9
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
10
|
+
import { useTheme } from "../hooks/ThemeContext";
|
|
11
|
+
import { useAppDispatch } from "../redux/store";
|
|
12
|
+
import { setCredentials } from "../redux/slices/authSlice";
|
|
13
|
+
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
|
|
14
|
+
import { RouteProp } from "@react-navigation/native";
|
|
15
|
+
import { AppStackParams } from "../navigation/AppStackParams";
|
|
16
|
+
|
|
17
|
+
type Props = {
|
|
18
|
+
navigation: NativeStackNavigationProp<AppStackParams, "LoginScreen">;
|
|
19
|
+
route: RouteProp<AppStackParams, "LoginScreen">;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const LoginScreen = ({ navigation }: Props) => {
|
|
23
|
+
const { theme } = useTheme();
|
|
24
|
+
const dispatch = useAppDispatch();
|
|
25
|
+
const [email, setEmail] = useState("");
|
|
26
|
+
const [password, setPassword] = useState("");
|
|
27
|
+
|
|
28
|
+
const onLogin = () => {
|
|
29
|
+
// store dummy data in auth reducer
|
|
30
|
+
dispatch(
|
|
31
|
+
setCredentials({
|
|
32
|
+
user: { id: "1", name: "Demo User", email: email || "demo@local" },
|
|
33
|
+
accessToken: "dummy-access-token-123",
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
navigation.reset({ index: 0, routes: [{ name: "HomeScreen" }] });
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<SafeAreaView style={{ flex: 1, backgroundColor: theme.background }}>
|
|
41
|
+
<View style={[styles.container, { backgroundColor: theme.background }]}>
|
|
42
|
+
<Text style={[styles.title, { color: theme.text }]}>Welcome back</Text>
|
|
43
|
+
<TextInput
|
|
44
|
+
placeholder="Email"
|
|
45
|
+
placeholderTextColor={theme.text + "88"}
|
|
46
|
+
style={[
|
|
47
|
+
styles.input,
|
|
48
|
+
{ backgroundColor: theme.card, color: theme.text },
|
|
49
|
+
]}
|
|
50
|
+
value={email}
|
|
51
|
+
onChangeText={setEmail}
|
|
52
|
+
keyboardType="email-address"
|
|
53
|
+
autoCapitalize="none"
|
|
54
|
+
/>
|
|
55
|
+
<TextInput
|
|
56
|
+
placeholder="Password"
|
|
57
|
+
placeholderTextColor={theme.text + "88"}
|
|
58
|
+
style={[
|
|
59
|
+
styles.input,
|
|
60
|
+
{ backgroundColor: theme.card, color: theme.text },
|
|
61
|
+
]}
|
|
62
|
+
value={password}
|
|
63
|
+
onChangeText={setPassword}
|
|
64
|
+
secureTextEntry
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
<TouchableOpacity
|
|
68
|
+
style={[styles.button, { backgroundColor: theme.primary }]}
|
|
69
|
+
onPress={onLogin}
|
|
70
|
+
>
|
|
71
|
+
<Text style={{ color: theme.text }}>Sign in</Text>
|
|
72
|
+
</TouchableOpacity>
|
|
73
|
+
</View>
|
|
74
|
+
</SafeAreaView>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default LoginScreen;
|
|
79
|
+
|
|
80
|
+
const styles = StyleSheet.create({
|
|
81
|
+
container: {
|
|
82
|
+
flex: 1,
|
|
83
|
+
justifyContent: "center",
|
|
84
|
+
padding: 24,
|
|
85
|
+
},
|
|
86
|
+
title: {
|
|
87
|
+
fontSize: 28,
|
|
88
|
+
fontWeight: "600",
|
|
89
|
+
marginBottom: 24,
|
|
90
|
+
textAlign: "center",
|
|
91
|
+
},
|
|
92
|
+
input: {
|
|
93
|
+
height: 48,
|
|
94
|
+
borderRadius: 8,
|
|
95
|
+
paddingHorizontal: 12,
|
|
96
|
+
marginBottom: 12,
|
|
97
|
+
},
|
|
98
|
+
button: {
|
|
99
|
+
height: 48,
|
|
100
|
+
borderRadius: 8,
|
|
101
|
+
alignItems: "center",
|
|
102
|
+
justifyContent: "center",
|
|
103
|
+
marginTop: 12,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { Text, View, StyleSheet } from
|
|
3
|
-
import { NativeStackNavigationProp } from
|
|
4
|
-
import { RouteProp } from
|
|
5
|
-
import { AppStackParams } from
|
|
6
|
-
import { useEffect } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Text, View, StyleSheet } from "react-native";
|
|
3
|
+
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
|
|
4
|
+
import { RouteProp } from "@react-navigation/native";
|
|
5
|
+
import { AppStackParams } from "../navigation/AppStackParams";
|
|
6
|
+
import { useEffect } from "react";
|
|
7
|
+
import { useAppSelector } from "../redux/store";
|
|
8
|
+
|
|
9
|
+
import { selectAccessToken } from "../redux/slices/authSlice";
|
|
7
10
|
type Props = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
navigation: NativeStackNavigationProp<
|
|
12
|
+
AppStackParams,
|
|
13
|
+
"SplashScreen",
|
|
14
|
+
"SplashScreen"
|
|
15
|
+
>;
|
|
16
|
+
route: RouteProp<AppStackParams, "SplashScreen">;
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
const SplashScreen = ({ navigation }: Props) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
20
|
+
const accessToken = useAppSelector(selectAccessToken);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
if (accessToken) {
|
|
25
|
+
navigation.reset({ index: 0, routes: [{ name: "HomeScreen" }] });
|
|
26
|
+
} else {
|
|
27
|
+
navigation.reset({ index: 0, routes: [{ name: "LoginScreen" }] });
|
|
28
|
+
}
|
|
29
|
+
}, 800);
|
|
30
|
+
}, [accessToken]);
|
|
31
|
+
return (
|
|
32
|
+
<View style={styles.container}>
|
|
33
|
+
<Text>SplashScreen</Text>
|
|
34
|
+
</View>
|
|
35
|
+
);
|
|
27
36
|
};
|
|
28
37
|
|
|
29
38
|
export default SplashScreen;
|
|
30
39
|
|
|
31
40
|
const styles = StyleSheet.create({
|
|
32
|
-
|
|
41
|
+
container: {},
|
|
33
42
|
});
|