@jescon-technologies/react-native-ui-kit 0.0.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.
@@ -0,0 +1,658 @@
1
+ import React, { useState, useEffect, useContext } from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ Image,
7
+ TouchableOpacity,
8
+ Dimensions,
9
+ StatusBar,
10
+ KeyboardAvoidingView,
11
+ Platform,
12
+ ScrollView,
13
+ Animated,
14
+ TextInput,
15
+ } from 'react-native';
16
+ import { APIURL, BASE_URL, imageURL } from '../Common/apiConstants';
17
+ import { Global } from '../Common/Global';
18
+ import Icons from '../Common/Icons';
19
+ import { normalize } from '../CommonStyle/componentStyle';
20
+ import NotificationContext from '../Handlers/NoticationsContext';
21
+ import moment from 'moment';
22
+ import axios from 'axios';
23
+ import { getLoading, isNU } from '../CommonStyle/ComponentFunctions';
24
+ import NetworkServiceCall from '../Common/NetworkServiceCall';
25
+ import ABlink from '../Alerts/ABlink';
26
+ import { BackHandler } from 'react-native';
27
+ // import BiometricModal from 'react-native-biometric-verifier';
28
+ import { useNavigation } from '../Navigation/useNavigation';
29
+
30
+ export default function INVLoginLayout(props) {
31
+ var clearing;
32
+ const [username, setUsername] = useState('');
33
+ const [password, setPassword] = useState('');
34
+ const [toastMsg, setToastMsg] = useState('');
35
+ const [showAlert, setShowAlert] = useState(false);
36
+ const [secureText, setSecureText] = useState(true);
37
+ const [refresh, setRefresh] = useState(0);
38
+ const [response, setResponse] = useState(false);
39
+ const navigation = useNavigation()
40
+
41
+ // Animation values
42
+ const fadeAnim = useState(new Animated.Value(0))[0];
43
+ const translateY = useState(new Animated.Value(30))[0];
44
+ const inputTranslateX = useState(new Animated.Value(-50))[0];
45
+
46
+ useEffect(() => {
47
+ Animated.parallel([
48
+ Animated.timing(fadeAnim, {
49
+ toValue: 1,
50
+ duration: 800,
51
+ useNativeDriver: true,
52
+ }),
53
+ Animated.timing(translateY, {
54
+ toValue: 0,
55
+ duration: 800,
56
+ useNativeDriver: true,
57
+ }),
58
+ ]).start();
59
+
60
+ // Sequential animation for inputs
61
+ Animated.stagger(200, [
62
+ Animated.timing(inputTranslateX, {
63
+ toValue: 0,
64
+ duration: 600,
65
+ useNativeDriver: true,
66
+ }),
67
+ ]).start();
68
+ }, []);
69
+
70
+ useEffect(() => {
71
+ if (clearing) clearing.clear();
72
+ setPassword('');
73
+ }, [refresh]);
74
+
75
+ const NoticationData = React.useContext(NotificationContext);
76
+
77
+ // Alert animation
78
+ useEffect(() => {
79
+ if (showAlert) {
80
+ Animated.sequence([
81
+ Animated.timing(fadeAnim, {
82
+ toValue: 1,
83
+ duration: 300,
84
+ useNativeDriver: true,
85
+ }),
86
+ ]).start();
87
+ }
88
+ }, [showAlert]);
89
+
90
+ const clearAlert = () => {
91
+ Animated.timing(fadeAnim, {
92
+ toValue: 0,
93
+ duration: 300,
94
+ useNativeDriver: true,
95
+ }).start(() => setShowAlert(false));
96
+ };
97
+
98
+ useEffect(() => {
99
+ const backAction = () => {
100
+ setRefresh(refresh + 1);
101
+ setResponse(false);
102
+ navigation.goBack();
103
+ // Returning true means you handled the back press
104
+ return true;
105
+ };
106
+ const backHandler = BackHandler.addEventListener(
107
+ 'hardwareBackPress',
108
+ backAction,
109
+ );
110
+ return () => backHandler.remove();
111
+ }, [navigation]);
112
+
113
+ return (
114
+ <KeyboardAvoidingView
115
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
116
+ style={{ flex: 1 }}>
117
+ <ScrollView contentContainerStyle={styles.container}>
118
+ <StatusBar barStyle="dark-content" backgroundColor="#ffffff" />
119
+
120
+ <View
121
+ style={{
122
+ width: '100%',
123
+ flexDirection: 'row',
124
+ alignItems: 'center',
125
+ justifyContent: 'space-between',
126
+ }}>
127
+ <View style={{}}>
128
+ <Image
129
+ style={{
130
+ width: normalize(60),
131
+ height: normalize(60),
132
+ resizeMode: 'contain',
133
+ }}
134
+ source={{
135
+ uri:
136
+ Global.hospitallogo != undefined
137
+ ? Global.hospitallogo[1]
138
+ : '',
139
+ }}
140
+ />
141
+ </View>
142
+
143
+ <View>
144
+ {Global.hospitalcode == 2 || Global.hospitalcode == 4 ? (
145
+ <ABlink>
146
+ <Text
147
+ style={{
148
+ fontSize: normalize(12),
149
+ color: '#616161',
150
+ marginTop: normalize(5),
151
+ // width: normalize(150),
152
+ fontWeight: 'bold',
153
+ textAlign: 'center',
154
+ }}>
155
+ {Global.HospitalData != undefined
156
+ ? Global.HospitalData.hospitalname
157
+ : ''}
158
+ </Text>
159
+ </ABlink>
160
+ ) : (
161
+ <Text
162
+ style={{
163
+ fontSize: normalize(12),
164
+ color: '#616161',
165
+ marginTop: normalize(5),
166
+ // width: normalize(150),
167
+ fontWeight: 'bold',
168
+ textAlign: 'center',
169
+ }}>
170
+ {Global.HospitalData != undefined
171
+ ? Global.HospitalData.hospitalname
172
+ : ''}
173
+ </Text>
174
+ )}
175
+ <Text
176
+ style={{
177
+ fontSize: normalize(12),
178
+ marginTop: -2,
179
+ textAlign: 'center',
180
+ }}>
181
+ {Global.HospitalData != undefined
182
+ ? Global.HospitalData.hospitaladdress
183
+ : ''}
184
+ </Text>
185
+ </View>
186
+
187
+ <View style={{}}>
188
+ <Image
189
+ style={{
190
+ width: normalize(50),
191
+ height: normalize(50),
192
+ resizeMode: 'contain',
193
+ }}
194
+ source={{
195
+ uri:
196
+ Global.HospitalData != undefined
197
+ ? Global.HospitalData.hospitallogo2
198
+ : '',
199
+ }}
200
+ />
201
+ </View>
202
+ </View>
203
+
204
+ <Animated.View
205
+ style={[
206
+ styles.formContainer,
207
+ { opacity: fadeAnim, transform: [{ translateY }] },
208
+ ]}>
209
+ <View style={styles.inputView}>
210
+ <Icons.FontAwesome
211
+ name={"user"}
212
+ color='#094485'
213
+ size={normalize(25)}
214
+ />
215
+ <TextInput
216
+ style={styles.input}
217
+ placeholder='User ID'
218
+ placeholderTextColor='#c0c0c0'
219
+ autoCapitalize='none'
220
+ keyboardType={'numeric'}
221
+ onChangeText={username => setUsername(username)}
222
+ />
223
+ </View>
224
+ <View style={styles.inputView}>
225
+ <Icons.FontAwesome
226
+ name={"lock"}
227
+ color='#094485'
228
+ size={normalize(27)}
229
+ />
230
+ <TextInput
231
+ ref={input => { clearing = input }}
232
+ style={styles.input}
233
+ placeholder='Password'
234
+ placeholderTextColor='#c0c0c0'
235
+ secureTextEntry={secureText}
236
+ autoCapitalize='none'
237
+ onChangeText={password => setPassword(password)}
238
+ />
239
+ <Icons.FontAwesome name={secureText ? "eye-slash" : "eye"}
240
+ onPress={() => setSecureText(!secureText)}
241
+ color={'grey'}
242
+ size={normalize(20)}
243
+ style={{ marginRight: normalize(7) }} />
244
+ </View>
245
+
246
+
247
+
248
+ <View
249
+ style={[
250
+ styles.loginButton,
251
+ {
252
+ width: '100%',
253
+ backgroundColor: Global.AppTheme.primary_color,
254
+ justifyContent: 'center',
255
+ alignItems: 'center',
256
+ },
257
+ ]}>
258
+
259
+ <TouchableOpacity
260
+ style={{
261
+ width: '100%',
262
+ ustifyContent: 'center',
263
+ alignItems: 'center',
264
+ }}
265
+
266
+
267
+ onPress={() =>
268
+ Global.InstallationKey != '123@jwt' &&
269
+ Global.InstallationKey != '123@JWT'
270
+ ? actionSubmit()
271
+ : actionJWT()
272
+ }>
273
+
274
+
275
+ <Text style={styles.loginButtonText}>Login</Text>
276
+ </TouchableOpacity>
277
+ {/* {Platform.OS != "web" &&
278
+ <BiometricModal
279
+ data={response?.data?.userdata?.hrenemp}
280
+ apiurl={"http://his.amalaims.org:9090/"}
281
+ onclose={i => { setResponse(i) }}
282
+ qrscan={response?.data?.userdata?.qrscan}
283
+ callback={() => { actionLogin(response) }}
284
+ />} */}
285
+ </View>
286
+ <TouchableOpacity
287
+ style={styles.forgotPasswordContainer}
288
+ onPress={() => navigation.navigate('ForgotPassword')}>
289
+ <Text style={styles.forgotPasswordText}>Change Password?</Text>
290
+ </TouchableOpacity>
291
+ </Animated.View>
292
+
293
+ {showAlert && (
294
+ <Animated.View style={[styles.alertContainer, { opacity: fadeAnim }]}>
295
+ <View style={styles.alertContent}>
296
+ <Icons.FontAwesome
297
+ name={'exclamation-circle'}
298
+ color={'#e74c3c'}
299
+ size={normalize(16)}
300
+ />
301
+ <Text numberOfLines={2} style={styles.alertText}>
302
+ {toastMsg}
303
+ </Text>
304
+ <TouchableOpacity onPress={clearAlert}>
305
+ <Icons.FontAwesome
306
+ name={'times'}
307
+ color={'#7f8c8d'}
308
+ size={normalize(14)}
309
+ />
310
+ </TouchableOpacity>
311
+ </View>
312
+ </Animated.View>
313
+ )}
314
+ </ScrollView>
315
+ </KeyboardAvoidingView>
316
+ );
317
+
318
+ function actionLogin(response) {
319
+ props.loader(true);
320
+ console.log('LOGIN-------------------RESPONSE', JSON.stringify(response));
321
+ Global.userData = { ...response.data.userdata };
322
+ Global.userOptionList = response.data.optionList;
323
+ Global.PatientDetails = null;
324
+ Global.LoginTime = moment();
325
+ props.loader(false);
326
+ NoticationData.length = 0;
327
+ NoticationData.push.apply(NoticationData, response.data.notifications);
328
+ setRefresh(refresh + 1);
329
+ // navigate('HomeScreen');
330
+ navigation.navigate('Dashboard');
331
+ props.loader(false);
332
+ }
333
+
334
+ function actionSubmit() {
335
+ console.log("Hello there2");
336
+ setResponse(false);
337
+ if (
338
+ username != null &&
339
+ username.length > 0 &&
340
+ password != null &&
341
+ password.length > 0
342
+ ) {
343
+ let buttonapi =
344
+ APIURL +
345
+ 'invget/invcommonget/AMAGDBC01.dbo.UserLogin1 ' +
346
+ username +
347
+ ',' +
348
+ "'" +
349
+ password +
350
+ "'" +
351
+ ',' +
352
+ 1;
353
+ console.log('..................Login..............', buttonapi);
354
+ NetworkServiceCall('get', buttonapi, '').then(function (response) {
355
+ console.log('.................RESPONSE..............', JSON.stringify(response));
356
+ if (response.httpstatus == 200) {
357
+ if (
358
+ response.data.userdata != undefined &&
359
+ response.data.userdata.loginstatus == true
360
+ ) {
361
+ if (response.data.userdata.facerecognition && Platform.OS != "web") {
362
+ setResponse(response);
363
+ } else {
364
+ actionLogin(response);
365
+ }
366
+ } else if (
367
+ response.data.userdata != undefined &&
368
+ response.data.userdata.loginstatus == false
369
+ ) {
370
+ if (isNU(response.data.userdata.suuser)) {
371
+ setToastMsg(
372
+ 'Please update the app , For Apple Devices,Please Visit Testflight to update',
373
+ setShowAlert(true, props.loader(false)),
374
+ );
375
+ } else {
376
+ setToastMsg(
377
+ "The UserID or Password doesn't exist",
378
+ setShowAlert(true, props.loader(false)),
379
+ );
380
+ }
381
+
382
+ setTimeout(() => {
383
+ setShowAlert(false);
384
+ }, 8000);
385
+ } else {
386
+ setToastMsg(
387
+ "The UserID or Password doesn't exist",
388
+ setShowAlert(true, props.loader(false)),
389
+ );
390
+ setTimeout(() => {
391
+ setShowAlert(false);
392
+ }, 3000);
393
+ }
394
+ } else {
395
+ setToastMsg('Network Error', setShowAlert(true, props.loader(false)));
396
+ setTimeout(() => {
397
+ setShowAlert(false);
398
+ }, 3000);
399
+ }
400
+ });
401
+ } else {
402
+ setToastMsg(
403
+ 'Enter UserID and Password',
404
+ setShowAlert(true, props.loader(false)),
405
+ );
406
+ setTimeout(() => {
407
+ setShowAlert(false);
408
+ }, 3000);
409
+ }
410
+ }
411
+
412
+ function actionSubmitNew(jwttoken) {
413
+ if (
414
+ username != null &&
415
+ username.length > 0 &&
416
+ password != null &&
417
+ password.length > 0
418
+ ) {
419
+ props.loader(true);
420
+ let jwt = `Bearer ${jwttoken}`;
421
+ let buttonapi =
422
+ APIURL +
423
+ 'emruseroption/option/UserLoginService ' +
424
+ username +
425
+ ',' +
426
+ Global.version;
427
+ console.log('..................Login..............', buttonapi);
428
+ console.log('..................Jwt Key..............', jwt);
429
+ NetworkServiceCall('get', buttonapi, '', jwttoken).then(function (
430
+ response,
431
+ ) {
432
+ console.log('RESPONSEEEEEE JSSOSOOSOSOSNNNN', JSON.stringify(response));
433
+ if (response.httpstatus == 200) {
434
+ if (
435
+ response.data.userdata != undefined &&
436
+ response.data.userdata.loginstatus == true
437
+ ) {
438
+ Global.userData = response.data.userdata;
439
+ Global.userOptionList = response.data.optionList;
440
+ Global.PatientDetails = null;
441
+ Global.LoginTime = moment();
442
+ props.loader(false);
443
+ NoticationData.length = 0;
444
+ NoticationData.push.apply(
445
+ NoticationData,
446
+ response.data.notifications,
447
+ );
448
+ setRefresh(refresh + 1);
449
+ navigation.navigate('Dashboard');
450
+ } else if (
451
+ response.data.userdata != undefined &&
452
+ response.data.userdata.loginstatus == false
453
+ ) {
454
+ setToastMsg(
455
+ 'Please update the app , For Apple Devices,Please Visit Testflight to update',
456
+ setShowAlert(true, props.loader(false)),
457
+ );
458
+ setTimeout(() => {
459
+ setShowAlert(false);
460
+ }, 8000);
461
+ } else {
462
+ setToastMsg(
463
+ "The UserID or Password doesn't exist.",
464
+ setShowAlert(true, props.loader(false)),
465
+ );
466
+ setTimeout(() => {
467
+ setShowAlert(false);
468
+ }, 8000);
469
+ }
470
+ } else {
471
+ setToastMsg(
472
+ 'Network Error 404',
473
+ setShowAlert(true, props.loader(false)),
474
+ );
475
+ setTimeout(() => {
476
+ setShowAlert(false);
477
+ }, 3000);
478
+ }
479
+ });
480
+ } else {
481
+ setToastMsg(
482
+ 'Enter UserID and Password',
483
+ setShowAlert(true, props.loader(false)),
484
+ );
485
+ setTimeout(() => {
486
+ setShowAlert(false);
487
+ }, 3000);
488
+ }
489
+ getLoading(v => props.loader(false));
490
+ }
491
+
492
+ function actionJWT() {
493
+ console.log("Hello there3");
494
+ if (
495
+ username != null &&
496
+ username.length > 0 &&
497
+ password != null &&
498
+ password.length > 0
499
+ ) {
500
+ let buttonapi = APIURL + 'auth/authenticate';
501
+ var PostArr = {
502
+ username: username,
503
+ password: password,
504
+ version: Global.version,
505
+ };
506
+ console.log('BUTTON API', JSON.stringify(buttonapi));
507
+ console.log('OUT', JSON.stringify(PostArr));
508
+ axios
509
+ .post(buttonapi, PostArr)
510
+ .then(function (response) {
511
+ if (response.status == 200) {
512
+ console.log('success', response.data);
513
+ Global.JWTToken = response.data;
514
+ if (response.data && response.data != 'invalid access') {
515
+ actionSubmitNew(response.data);
516
+ } else {
517
+ setToastMsg(
518
+ "The UserID or Password doesn't exist",
519
+ setShowAlert(true),
520
+ );
521
+ setTimeout(() => {
522
+ setShowAlert(false);
523
+ }, 3000);
524
+ }
525
+ } else {
526
+ setToastMsg('Network Error 404', setShowAlert(true));
527
+ setTimeout(() => {
528
+ setShowAlert(false);
529
+ }, 3000);
530
+ }
531
+ })
532
+ .catch(function (error) {
533
+ setToastMsg('Network Error 404', setShowAlert(true));
534
+ setTimeout(() => {
535
+ setShowAlert(false);
536
+ }, 3000);
537
+ });
538
+ } else {
539
+ setToastMsg(
540
+ 'Enter UserID and Password',
541
+ setShowAlert(true, props.loader(false)),
542
+ );
543
+ setTimeout(() => {
544
+ setShowAlert(false);
545
+ }, 3000);
546
+ }
547
+ }
548
+ }
549
+
550
+ const { width, height } = Dimensions.get('window');
551
+
552
+ const styles = StyleSheet.create({
553
+ container: {
554
+ flexGrow: 1,
555
+ backgroundColor: '#ffffff',
556
+ padding: normalize(15),
557
+ },
558
+
559
+ formContainer: {
560
+ marginTop: normalize(25),
561
+ width: '100%',
562
+ },
563
+ iconContainer: {
564
+ width: normalize(40),
565
+ height: '100%',
566
+ justifyContent: 'center',
567
+ alignItems: 'center',
568
+ borderRightWidth: 1,
569
+ borderRightColor: '#e0e0e0',
570
+ },
571
+ eyeIcon: {
572
+ width: normalize(40),
573
+ height: '100%',
574
+ justifyContent: 'center',
575
+ alignItems: 'center',
576
+ },
577
+ loginButton: {
578
+ height: normalize(40),
579
+ borderRadius: normalize(10),
580
+ marginTop: normalize(10),
581
+ shadowColor: '#000',
582
+ shadowOffset: {
583
+ width: 0,
584
+ height: 2,
585
+ },
586
+ shadowOpacity: 0.2,
587
+ shadowRadius: 3,
588
+ elevation: 4,
589
+ width: '80%',
590
+ },
591
+ loginButtonText: {
592
+ color: '#ffffff',
593
+ fontWeight: 'bold',
594
+ fontSize: normalize(14),
595
+ },
596
+ forgotPasswordContainer: {
597
+ alignItems: 'center',
598
+ marginTop: normalize(15),
599
+ },
600
+ forgotPasswordText: {
601
+ color: Global.AppTheme.primary_color,
602
+ fontSize: normalize(12),
603
+ fontWeight: '600',
604
+ },
605
+ alertContainer: {
606
+ position: 'absolute',
607
+ bottom: normalize(15),
608
+ left: normalize(15),
609
+ right: normalize(15),
610
+ backgroundColor: '#fff',
611
+ borderRadius: normalize(8),
612
+ padding: normalize(10),
613
+ shadowColor: '#000',
614
+ shadowOffset: {
615
+ width: 0,
616
+ height: 2,
617
+ },
618
+ shadowOpacity: 0.2,
619
+ shadowRadius: 3,
620
+ elevation: 4,
621
+ borderLeftWidth: 3,
622
+ borderLeftColor: '#e74c3c',
623
+ },
624
+ alertContent: {
625
+ flexDirection: 'row',
626
+ alignItems: 'center',
627
+ },
628
+ alertText: {
629
+ flex: 1,
630
+ color: '#2c3e50',
631
+ fontSize: normalize(12),
632
+ marginLeft: normalize(8),
633
+ marginRight: normalize(8),
634
+ },
635
+ inputView: {
636
+ height: normalize(40),
637
+ borderRadius: 10,
638
+ backgroundColor: '#f1f3f6',
639
+ marginTop: 10,
640
+ display: 'flex',
641
+ flexDirection: 'row',
642
+ alignItems: 'center',
643
+ },
644
+ input: {
645
+ height: normalize(45),
646
+ flex: 1,
647
+ fontSize: normalize(15),
648
+ fontWeight: 'bold',
649
+ color: 'black',
650
+
651
+ paddingHorizontal: 10,
652
+ },
653
+ alert_msg_text: {
654
+ color: 'red',
655
+ fontSize: normalize(14),
656
+ fontWeight: '700',
657
+ },
658
+ });