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

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