@jescon-technologies/react-native-ui-kit 0.0.12 → 0.0.14

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.
@@ -0,0 +1,189 @@
1
+ import React, {
2
+ createContext,
3
+ useState,
4
+ useRef,
5
+ useEffect,
6
+ useContext,
7
+ ReactNode,
8
+ } from 'react';
9
+
10
+ import { View, Platform } from 'react-native';
11
+ import { NavigationContainer } from '@react-navigation/native';
12
+ import { createNativeStackNavigator } from '@react-navigation/native-stack';
13
+
14
+ type Route = {
15
+ name: string;
16
+ params?: any;
17
+ };
18
+
19
+ type NavigationContextType = {
20
+ navigate: (screenName: string, params?: any) => void;
21
+ replace: (screenName: string, params?: any) => void;
22
+ goBack: () => void;
23
+ addFocusListener: (screenName: string, callback: () => void) => () => void;
24
+ current: Route;
25
+ };
26
+
27
+ const NavigationContext = createContext<NavigationContextType | null>(null);
28
+
29
+ type NavigationScreens = Record<string, React.ComponentType<any>>;
30
+
31
+ type ProviderProps = {
32
+ screens: NavigationScreens;
33
+ children?: ReactNode;
34
+ };
35
+
36
+ export const NavigationProvider: React.FC<ProviderProps> = ({
37
+ screens,
38
+ children,
39
+ }) => {
40
+ const [stack, setStack] = useState<Route[]>([
41
+ { name: Object.keys(screens)[0], params: {} },
42
+ ]);
43
+
44
+ const focusListeners = useRef<Record<string, Array<() => void>>>({});
45
+
46
+ const current = stack[stack.length - 1];
47
+
48
+ const navigate = (screenName: string, params = {}) => {
49
+ setStack(prev => [...prev, { name: screenName, params }]);
50
+ };
51
+
52
+ const replace = (screenName: string, params = {}) => {
53
+ setStack(prev => [
54
+ ...prev.slice(0, -1),
55
+ { name: screenName, params },
56
+ ]);
57
+ };
58
+
59
+ const goBack = () => {
60
+ setStack(prev => (prev.length > 1 ? prev.slice(0, -1) : prev));
61
+ };
62
+
63
+ const addFocusListener = (screenName: string, callback: () => void) => {
64
+ if (!focusListeners.current[screenName]) {
65
+ focusListeners.current[screenName] = [];
66
+ }
67
+
68
+ focusListeners.current[screenName].push(callback);
69
+
70
+ return () => {
71
+ const listeners = focusListeners.current[screenName] || [];
72
+ focusListeners.current[screenName] = listeners.filter(
73
+ cb => cb !== callback
74
+ );
75
+ };
76
+ };
77
+
78
+ useEffect(() => {
79
+ const listeners = focusListeners.current[current.name] || [];
80
+ listeners.forEach(cb => cb());
81
+ }, [current.name]);
82
+
83
+ return (
84
+ <NavigationContext.Provider
85
+ value={{ navigate, goBack, replace, addFocusListener, current }}
86
+ >
87
+ <View style={{ flex: 1 }}>
88
+ {stack.map((route, index) => {
89
+ const ScreenComponent: React.ComponentType<any> = screens[route.name];
90
+ const isFocused = index === stack.length - 1;
91
+
92
+ return (
93
+ <View
94
+ key={index}
95
+ style={{
96
+ flex: 1,
97
+ display: isFocused ? 'flex' : 'none',
98
+ }}
99
+ >
100
+ <ScreenComponent
101
+ navigation={{ navigate, replace, goBack }}
102
+ route={{ params: route.params }}
103
+ />
104
+ </View>
105
+ );
106
+ })}
107
+
108
+ {children}
109
+ </View>
110
+ </NavigationContext.Provider>
111
+ );
112
+ };
113
+
114
+ export const useNavigation = () => {
115
+ const ctx = useContext(NavigationContext);
116
+ if (!ctx) {
117
+ throw new Error('useNavigation must be used inside NavigationProvider');
118
+ }
119
+ return ctx;
120
+ };
121
+
122
+ export const useFocusEffect = (callback: () => void | (() => void)) => {
123
+ const { current, addFocusListener } = useNavigation();
124
+ const cleanupRef = useRef<any>(null);
125
+
126
+ useEffect(() => {
127
+ cleanupRef.current?.();
128
+
129
+ const unsubscribe = addFocusListener(current.name, () => {
130
+ cleanupRef.current?.();
131
+ cleanupRef.current = callback();
132
+ });
133
+
134
+ return () => {
135
+ cleanupRef.current?.();
136
+ unsubscribe?.();
137
+ };
138
+ }, [current.name]);
139
+ };
140
+
141
+ export const useIsFocused = (): boolean => {
142
+ const { current, addFocusListener } = useNavigation();
143
+ const [isFocused, setIsFocused] = useState(true);
144
+
145
+ useEffect(() => {
146
+ setIsFocused(true);
147
+
148
+ const unsubscribe = addFocusListener(current.name, () => {
149
+ setIsFocused(true);
150
+ });
151
+
152
+ return () => {
153
+ setIsFocused(false);
154
+ unsubscribe();
155
+ };
156
+ }, [current.name]);
157
+
158
+ return isFocused;
159
+ };
160
+
161
+ export const ReactNativeNavigation: React.FC<{
162
+ screens: NavigationScreens;
163
+ }> = ({ screens }) => {
164
+ const Stack = createNativeStackNavigator();
165
+
166
+ return (
167
+ <NavigationContainer>
168
+ <Stack.Navigator
169
+ initialRouteName={Object.keys(screens)[0]}
170
+ screenOptions={{
171
+ animation: 'none',
172
+ headerShown: false,
173
+ }}
174
+ >
175
+ {Object.entries(screens).map(([name, component]) => (
176
+ <Stack.Screen key={name} name={name} component={component} />
177
+ ))}
178
+ </Stack.Navigator>
179
+ </NavigationContainer>
180
+ );
181
+ };
182
+
183
+ export default function Navigation({ screens }: { screens: NavigationScreens }) {
184
+ return Platform.OS === 'web' ? (
185
+ <NavigationProvider screens={screens} />
186
+ ) : (
187
+ <ReactNativeNavigation screens={screens} />
188
+ );
189
+ }
@@ -1,2 +1,2 @@
1
1
 
2
- export { useFocusEffect } from '../../../../../src/Navigation/PageNavigation';
2
+ export { useFocusEffect } from './PageNavigation';
@@ -1 +1 @@
1
- export { useFocusEffect } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useFocusEffect } from './PageNavigation';
@@ -1 +1 @@
1
- export { useIsFocused } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useIsFocused } from './PageNavigation';
@@ -1 +1 @@
1
- export { useIsFocused } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useIsFocused } from './PageNavigation';
@@ -1,2 +1,2 @@
1
1
 
2
- export { useNavigation } from '../../../../../src/Navigation/PageNavigation';
2
+ export { useNavigation } from './PageNavigation';
@@ -1 +1 @@
1
- export { useNavigation } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useNavigation } from './PageNavigation';
@@ -0,0 +1,342 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StatusBar,
6
+ Dimensions,
7
+ ImageBackground,
8
+ TouchableOpacity,
9
+ TouchableHighlight,
10
+ TextInput,
11
+ } from 'react-native';
12
+
13
+ import { APIURL } from '../../../../../src/Common/apiConstants';
14
+ import { Global } from '../../../../../src/Common/Global';
15
+ import axios from 'axios';
16
+ import { HIcons, normalize, getLoading, NetworkServiceCall, notifyMessage, ValueCheck, Loader } from '@jescon-technologies/react-native-ui-kit';
17
+
18
+ const image = {
19
+ uri: 'https://t4.ftcdn.net/jpg/05/19/65/81/360_F_519658132_FkvYwAjuJ8q67PGQUgYLrumVymaJtlZj.jpg',
20
+ };
21
+
22
+ /* ---------------- CUSTOM INPUT ---------------- */
23
+ const CustomInput = ({
24
+ value,
25
+ onChangeText,
26
+ placeholder,
27
+ secureTextEntry,
28
+ keyboardType,
29
+ autoFocus,
30
+ leftIcon,
31
+ rightIcon,
32
+ onRightIconPress,
33
+ onEndEditing,
34
+ style,
35
+ }) => {
36
+ return (
37
+ <View
38
+ style={[
39
+ {
40
+ width: Dimensions.get('screen').width * 0.9,
41
+ borderWidth: 1,
42
+ borderColor: '#aaa',
43
+ borderRadius: 6,
44
+ flexDirection: 'row',
45
+ alignItems: 'center',
46
+ paddingHorizontal: 10,
47
+ backgroundColor: '#fff',
48
+ height: normalize(45),
49
+ },
50
+ style,
51
+ ]}
52
+ >
53
+ {leftIcon && <View style={{ marginRight: 8 }}>{leftIcon}</View>}
54
+
55
+ <TextInput
56
+ style={{ flex: 1, color: '#000' }}
57
+ placeholder={placeholder}
58
+ placeholderTextColor="#777"
59
+ value={value}
60
+ onChangeText={onChangeText}
61
+ secureTextEntry={secureTextEntry}
62
+ keyboardType={keyboardType}
63
+ autoFocus={autoFocus}
64
+ onEndEditing={onEndEditing}
65
+ />
66
+
67
+ {rightIcon && (
68
+ <TouchableOpacity onPress={onRightIconPress}>
69
+ {rightIcon}
70
+ </TouchableOpacity>
71
+ )}
72
+ </View>
73
+ );
74
+ };
75
+
76
+ /* ---------------- MAIN COMPONENT ---------------- */
77
+ export default function ForgotPassword({ navigation }) {
78
+ const [stage, setStage] = useState(1);
79
+ const [text, setText] = useState('');
80
+ const [msg, setMsg] = useState('');
81
+ const [isLoading, setIsLoading] = useState(false);
82
+
83
+ const [password, setPassword] = useState({
84
+ oldpass: '',
85
+ newpass: '',
86
+ confirmpass: '',
87
+ });
88
+
89
+ const [isPasswordSecure, setIsPasswordSecure] = useState(true);
90
+ const [isPasswordSecureTwo, setIsPasswordSecureTwo] = useState(true);
91
+
92
+ useEffect(() => {
93
+ setPassword({ oldpass: '', newpass: '', confirmpass: '' });
94
+ setMsg('');
95
+ }, [stage]);
96
+
97
+ /* ---------------- AUTH JWT ---------------- */
98
+ function actionJWT() {
99
+ if (password.oldpass && text) {
100
+ let buttonapi = APIURL + 'auth/authenticate';
101
+ let PostArr = {
102
+ username: text,
103
+ password: password.oldpass,
104
+ };
105
+
106
+ axios
107
+ .post(buttonapi, PostArr)
108
+ .then(res => {
109
+ if (res.status === 200) {
110
+ Global.JWTToken = res.data;
111
+ } else {
112
+ notifyMessage('Please check old password', 2);
113
+ }
114
+ })
115
+ .catch(() => notifyMessage('Authentication failed', 3));
116
+ }
117
+ }
118
+
119
+ /* ---------------- UPDATE PASSWORD ---------------- */
120
+ function getUpdate() {
121
+ if (!password.newpass || !password.confirmpass) {
122
+ notifyMessage('Please fill out passwords', 3);
123
+ return;
124
+ }
125
+
126
+ if (password.newpass !== password.confirmpass) {
127
+ notifyMessage('Passwords do not match', 4);
128
+ return;
129
+ }
130
+
131
+ const ReqJson = {
132
+ groups: {
133
+ procedurename: 'suuserforgetpassword1',
134
+ userid: text,
135
+ ...password,
136
+ },
137
+ };
138
+
139
+ let buttonapi = APIURL + 'commontemplatesave/RnCommonTemplateSave';
140
+ setIsLoading(true);
141
+
142
+ NetworkServiceCall('post', buttonapi, ReqJson, Global.JWTToken).then(res => {
143
+ if (res?.httpstatus === 200 && res?.data?.code > 0) {
144
+ notifyMessage('Password Updated !!!', 1);
145
+ setStage(3);
146
+ } else {
147
+ notifyMessage('Password Not Updated', 2);
148
+ }
149
+ setIsLoading(false);
150
+ });
151
+
152
+ getLoading(() => setIsLoading(false));
153
+ }
154
+
155
+ /* ---------------- PASSWORD STRENGTH ---------------- */
156
+ function checkPasswordStrength(pass) {
157
+ let strength = 0;
158
+ let tips = '';
159
+
160
+ if (pass.length >= 8) { strength++; }
161
+ else { tips += 'Minimum 8 characters. '; }
162
+
163
+ if (/[a-z]/.test(pass) && /[A-Z]/.test(pass)) { strength++; }
164
+ else { tips += 'Use upper & lower case. '; }
165
+
166
+ if (/\d/.test(pass)) { strength++; }
167
+ else { tips += 'Add a number. '; }
168
+
169
+ if (/[^a-zA-Z\d]/.test(pass)) { strength++; }
170
+ else { tips += 'Add a special character. '; }
171
+
172
+ if (strength < 2) { setMsg('Easy'); }
173
+ else if (strength === 2) { setMsg('Medium'); }
174
+ else if (strength === 3) { setMsg('Strong'); }
175
+ else { setMsg('Very Strong'); }
176
+
177
+ tips && notifyMessage(tips, 5);
178
+ }
179
+
180
+ /* ---------------- UI ---------------- */
181
+ return (
182
+ <View style={{ flex: 1, marginTop: StatusBar.currentHeight }}>
183
+ <StatusBar translucent backgroundColor="transparent" barStyle="dark-content" />
184
+
185
+ <ImageBackground source={image} style={{ flex: 1 }}>
186
+ <TouchableOpacity
187
+ style={{ padding: 20 }}
188
+ onPress={() => (stage === 1 ? navigation.goBack() : setStage(stage - 1))}
189
+ >
190
+ <HIcons.FontAwesome5 name="arrow-left" size={normalize(20)} />
191
+ </TouchableOpacity>
192
+
193
+ {/* -------- STAGE 1 -------- */}
194
+ {stage === 1 && (
195
+ <View style={{ alignItems: 'center' }}>
196
+ <HIcons.FontAwesome5 name="lock" size={normalize(50)} />
197
+ <Text style={{ fontSize: normalize(24), fontWeight: 'bold' }}>
198
+ CHANGE PASSWORD
199
+ </Text>
200
+
201
+ <CustomInput
202
+ placeholder="Enter User ID"
203
+ keyboardType="numeric"
204
+ value={text}
205
+ autoFocus
206
+ onChangeText={setText}
207
+ leftIcon={
208
+ <HIcons.MaterialCommunityIcons
209
+ name="clock-time-five-outline"
210
+ size={normalize(20)}
211
+ color="purple"
212
+ />
213
+ }
214
+ style={{ marginTop: normalize(20) }}
215
+ />
216
+
217
+ <TouchableHighlight
218
+ onPress={() =>
219
+ ValueCheck(text)
220
+ ? setStage(2)
221
+ : notifyMessage('Enter User ID', 3)
222
+ }
223
+ style={{
224
+ marginTop: normalize(15),
225
+ width: Dimensions.get('screen').width * 0.9,
226
+ height: normalize(40),
227
+ backgroundColor: '#FADF00',
228
+ alignItems: 'center',
229
+ justifyContent: 'center',
230
+ }}
231
+ >
232
+ <Text style={{ fontWeight: 'bold' }}>NEXT</Text>
233
+ </TouchableHighlight>
234
+ </View>
235
+ )}
236
+
237
+ {/* -------- STAGE 2 -------- */}
238
+ {stage === 2 && (
239
+ <View style={{ alignItems: 'center' }}>
240
+ <Text style={{ fontWeight: 'bold', fontSize: normalize(18) }}>
241
+ New Credentials
242
+ </Text>
243
+
244
+ <CustomInput
245
+ placeholder="Old Password"
246
+ secureTextEntry={isPasswordSecure}
247
+ value={password.oldpass}
248
+ onChangeText={t => setPassword({ ...password, oldpass: t })}
249
+ onEndEditing={actionJWT}
250
+ leftIcon={<HIcons.FontAwesome5 name="lock" size={18} />}
251
+ rightIcon={
252
+ <HIcons.FontAwesome5
253
+ name={isPasswordSecure ? 'eye-slash' : 'eye'}
254
+ size={18}
255
+ />
256
+ }
257
+ onRightIconPress={() => setIsPasswordSecure(!isPasswordSecure)}
258
+ style={{ marginTop: normalize(15) }}
259
+ />
260
+
261
+ <Text style={{ alignSelf: 'flex-end', color: 'red' }}>{msg}</Text>
262
+
263
+ <CustomInput
264
+ placeholder="New Password"
265
+ secureTextEntry={isPasswordSecure}
266
+ value={password.newpass}
267
+ onChangeText={t => setPassword({ ...password, newpass: t })}
268
+ onEndEditing={() => checkPasswordStrength(password.newpass)}
269
+ leftIcon={<HIcons.FontAwesome5 name="lock" size={18} />}
270
+ rightIcon={
271
+ <HIcons.FontAwesome5
272
+ name={isPasswordSecure ? 'eye-slash' : 'eye'}
273
+ size={18}
274
+ />
275
+ }
276
+ onRightIconPress={() => setIsPasswordSecure(!isPasswordSecure)}
277
+ style={{ marginTop: normalize(15) }}
278
+ />
279
+
280
+ <CustomInput
281
+ placeholder="Confirm Password"
282
+ secureTextEntry={isPasswordSecureTwo}
283
+ value={password.confirmpass}
284
+ onChangeText={t => setPassword({ ...password, confirmpass: t })}
285
+ leftIcon={<HIcons.FontAwesome5 name="lock" size={18} />}
286
+ rightIcon={
287
+ <HIcons.FontAwesome5
288
+ name={isPasswordSecureTwo ? 'eye-slash' : 'eye'}
289
+ size={18}
290
+ />
291
+ }
292
+ onRightIconPress={() =>
293
+ setIsPasswordSecureTwo(!isPasswordSecureTwo)
294
+ }
295
+ style={{ marginTop: normalize(15) }}
296
+ />
297
+
298
+ <TouchableHighlight
299
+ onPress={getUpdate}
300
+ style={{
301
+ marginTop: normalize(15),
302
+ width: Dimensions.get('screen').width * 0.9,
303
+ height: normalize(40),
304
+ backgroundColor: '#FADF00',
305
+ alignItems: 'center',
306
+ justifyContent: 'center',
307
+ }}
308
+ >
309
+ <Text style={{ fontWeight: 'bold' }}>UPDATE</Text>
310
+ </TouchableHighlight>
311
+ </View>
312
+ )}
313
+
314
+ {/* -------- STAGE 3 -------- */}
315
+ {stage === 3 && (
316
+ <View style={{ alignItems: 'center' }}>
317
+ <HIcons.EvilIcons name="check" size={normalize(100)} color="green" />
318
+ <Text style={{ color: 'green', fontWeight: 'bold' }}>
319
+ Password Updated
320
+ </Text>
321
+
322
+ <TouchableHighlight
323
+ onPress={() => navigation.goBack()}
324
+ style={{
325
+ marginTop: normalize(15),
326
+ width: Dimensions.get('screen').width * 0.9,
327
+ height: normalize(40),
328
+ backgroundColor: '#FADF00',
329
+ alignItems: 'center',
330
+ justifyContent: 'center',
331
+ }}
332
+ >
333
+ <Text style={{ fontWeight: 'bold' }}>LOGIN</Text>
334
+ </TouchableHighlight>
335
+ </View>
336
+ )}
337
+ </ImageBackground>
338
+
339
+ {isLoading && <Loader displaytext />}
340
+ </View>
341
+ );
342
+ }