@truworth/twc-auth 1.2.4 → 1.2.6
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 +1 -4
- package/build/assets/email_icon.svg +6 -0
- package/build/src/api/axiosClient/index.js +1 -1
- package/build/src/api/axiosClient/index.native.js +1 -1
- package/build/src/components/VerifyMobileOTP/index.js +8 -6
- package/build/src/components/VerifyMobileOTP/index.native.js +6 -11
- package/build/src/constants/base-url/index.js +5 -0
- package/build/src/constants/base-url/index.native.js +1 -0
- package/build/src/constants/cdn-url/index.js +2 -1
- package/build/src/constants/social-login-options.js +16 -0
- package/build/src/contexts/AuthContext.js +6 -2
- package/build/src/enums/index.js +1 -0
- package/build/src/enums/loginMethod.enum.js +1 -1
- package/build/src/enums/socialLogins.enum.js +6 -0
- package/build/src/helpers/{Network.js → network.js} +1 -1
- package/build/src/hooks/useRequest.js +1 -1
- package/build/src/navigator/index.native.js +5 -1
- package/build/src/screens/EnterEmail/hooks/internal/useEnterEmail.js +50 -41
- package/build/src/screens/EnterEmail/index.js +37 -11
- package/build/src/screens/EnterEmail/index.native.js +6 -9
- package/build/src/screens/EnterMobile/components/ExistingAccountsSheet/hooks/internal/useExistingAccountsSheet.js +36 -0
- package/build/src/screens/EnterMobile/components/ExistingAccountsSheet/index.js +33 -0
- package/build/src/screens/EnterMobile/components/ExistingAccountsSheet/index.native.js +73 -0
- package/build/src/screens/EnterMobile/components/ExistingAccountsSheet/types.js +1 -0
- package/build/src/screens/EnterMobile/hooks/internal/useEnterMobile.js +67 -0
- package/build/src/screens/EnterMobile/index.js +82 -0
- package/build/src/screens/EnterMobile/index.native.js +56 -0
- package/build/src/screens/EnterMobile/types.js +1 -0
- package/build/src/screens/EnterPassword/hooks/internal/useEnterPassword.js +42 -31
- package/build/src/screens/EnterPassword/index.js +6 -6
- package/build/src/screens/EnterPassword/index.native.js +5 -10
- package/build/src/screens/Login/components/LoginWebComponent/index.js +4 -1
- package/build/src/screens/LoginWithEmailOTP/hooks/internal/useLoginWithEmailOTP.js +8 -5
- package/build/src/screens/LoginWithMobileOTP/hooks/internal/useLoginWithMobileOTP.js +71 -0
- package/build/src/screens/LoginWithMobileOTP/index.js +8 -0
- package/build/src/screens/LoginWithMobileOTP/index.native.js +10 -0
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.js +9 -8
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.native.js +2 -6
- package/build/src/screens/SignUp/components/SignUpForm/index.js +20 -5
- package/build/src/screens/SignUp/components/SignUpWebComponent/index.js +12 -2
- package/build/src/screens/SignUp/hooks/internal/useSignUp.js +1 -1
- package/build/src/screens/SignUp/index.native.js +17 -13
- package/build/src/screens/UserConsent/hooks/internal/useConsent.js +10 -1
- package/build/src/screens/UserConsent/index.js +1 -1
- package/build/src/screens/VerifyLinkPrimaryAccountEmailOTP/hooks/internal/useVerifyLinkPrimaryAccountEmailOTP.js +73 -0
- package/build/src/screens/VerifyLinkPrimaryAccountEmailOTP/index.js +8 -0
- package/build/src/screens/VerifyLinkPrimaryAccountEmailOTP/index.native.js +14 -0
- package/build/src/screens/VerifyLinkPrimaryAccountEmailOTP/types.js +1 -0
- package/build/src/screens/VerifyLinkPrimaryAccountMobileOTP/hooks/internal/useVerifyLinkPrimaryAccountMobileOTP.js +82 -0
- package/build/src/screens/VerifyLinkPrimaryAccountMobileOTP/index.js +8 -0
- package/build/src/screens/VerifyLinkPrimaryAccountMobileOTP/index.native.js +10 -0
- package/build/src/screens/VerifyLinkPrimaryAccountMobileOTP/types.js +1 -0
- package/build/src/screens/Welcome/SocialAuth/commonSocialAuth.js +127 -0
- package/build/src/screens/Welcome/SocialAuth/hooks/useSocialAuth.native.js +192 -0
- package/build/src/screens/Welcome/SocialAuth/hooks/useSocialAuth.web.js +13 -0
- package/build/src/screens/Welcome/SocialAuth/hooks/web/useFacebookAuth.web.js +118 -0
- package/build/src/screens/Welcome/SocialAuth/hooks/web/useGoogleAuth.web.js +75 -0
- package/build/src/screens/Welcome/components/SocialLoginModal/index.js +9 -0
- package/build/src/screens/Welcome/components/SocialLoginModal/index.native.js +21 -0
- package/build/src/screens/Welcome/components/SocialLoginModal/types.js +1 -0
- package/build/src/screens/Welcome/hooks/internal/useWelcome.js +10 -5
- package/build/src/screens/Welcome/index.js +3 -2
- package/build/src/screens/Welcome/index.native.js +41 -4
- package/build/types/components/VerifyMobileOTP/index.d.ts +1 -1
- package/build/types/components/VerifyMobileOTP/types.d.ts +0 -1
- package/build/types/constants/base-url/index.d.ts +1 -0
- package/build/types/constants/base-url/index.native.d.ts +1 -0
- package/build/types/constants/cdn-url/index.d.ts +2 -1
- package/build/types/constants/social-login-options.d.ts +3 -0
- package/build/types/contexts/AuthContext.d.ts +3 -1
- package/build/types/contexts/type.d.ts +12 -0
- package/build/types/enums/index.d.ts +1 -0
- package/build/types/enums/loginMethod.enum.d.ts +1 -1
- package/build/types/enums/socialLogins.enum.d.ts +5 -0
- package/build/types/helpers/types.d.ts +7 -1
- package/build/types/navigator/index.native.d.ts +17 -0
- package/build/types/screens/EnterEmail/hooks/internal/useEnterEmail.d.ts +11 -15
- package/build/types/screens/EnterEmail/types.d.ts +6 -1
- package/build/types/screens/EnterMobile/components/ExistingAccountsSheet/hooks/internal/useExistingAccountsSheet.d.ts +13 -0
- package/build/types/screens/EnterMobile/components/ExistingAccountsSheet/index.d.ts +3 -0
- package/build/types/screens/EnterMobile/components/ExistingAccountsSheet/index.native.d.ts +3 -0
- package/build/types/screens/EnterMobile/components/ExistingAccountsSheet/types.d.ts +28 -0
- package/build/types/screens/EnterMobile/hooks/internal/useEnterMobile.d.ts +15 -0
- package/build/types/screens/EnterMobile/index.d.ts +4 -0
- package/build/types/screens/EnterMobile/index.native.d.ts +4 -0
- package/build/types/screens/EnterMobile/types.d.ts +44 -0
- package/build/types/screens/EnterPassword/hooks/internal/useEnterPassword.d.ts +8 -8
- package/build/types/screens/LoginWithEmailOTP/hooks/internal/useLoginWithEmailOTP.d.ts +1 -1
- package/build/types/screens/LoginWithMobileOTP/hooks/internal/useLoginWithMobileOTP.d.ts +11 -0
- package/build/types/screens/LoginWithMobileOTP/index.d.ts +5 -0
- package/build/types/screens/LoginWithMobileOTP/index.native.d.ts +4 -0
- package/build/types/screens/SSOLogin/AuthenticationMethods/index.d.ts +1 -1
- package/build/types/screens/SSOLogin/AuthenticationMethods/types.d.ts +1 -0
- package/build/types/screens/VerifyLinkPrimaryAccountEmailOTP/hooks/internal/useVerifyLinkPrimaryAccountEmailOTP.d.ts +15 -0
- package/build/types/screens/VerifyLinkPrimaryAccountEmailOTP/index.d.ts +3 -0
- package/build/types/screens/VerifyLinkPrimaryAccountEmailOTP/index.native.d.ts +4 -0
- package/build/types/screens/VerifyLinkPrimaryAccountEmailOTP/types.d.ts +14 -0
- package/build/types/screens/VerifyLinkPrimaryAccountMobileOTP/hooks/internal/useVerifyLinkPrimaryAccountMobileOTP.d.ts +17 -0
- package/build/types/screens/VerifyLinkPrimaryAccountMobileOTP/index.d.ts +3 -0
- package/build/types/screens/VerifyLinkPrimaryAccountMobileOTP/index.native.d.ts +4 -0
- package/build/types/screens/VerifyLinkPrimaryAccountMobileOTP/types.d.ts +5 -0
- package/build/types/screens/Welcome/SocialAuth/commonSocialAuth.d.ts +50 -0
- package/build/types/screens/Welcome/SocialAuth/hooks/useSocialAuth.native.d.ts +7 -0
- package/build/types/screens/Welcome/SocialAuth/hooks/useSocialAuth.web.d.ts +7 -0
- package/build/types/screens/Welcome/SocialAuth/hooks/web/useFacebookAuth.web.d.ts +5 -0
- package/build/types/screens/Welcome/SocialAuth/hooks/web/useGoogleAuth.web.d.ts +4 -0
- package/build/types/screens/Welcome/components/SocialLoginModal/index.d.ts +3 -0
- package/build/types/screens/Welcome/components/SocialLoginModal/index.native.d.ts +3 -0
- package/build/types/screens/Welcome/components/SocialLoginModal/types.d.ts +8 -0
- package/build/types/screens/Welcome/hooks/internal/useWelcome.d.ts +8 -0
- package/build/types/types/types.d.ts +3 -0
- package/package.json +3 -5
- package/build/assets/okay_icon copy.svg +0 -3
- /package/build/src/helpers/{Validation.js → validation.js} +0 -0
- /package/build/types/helpers/{Network.d.ts → network.d.ts} +0 -0
- /package/build/types/helpers/{Validation.d.ts → validation.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -70,7 +70,6 @@ Truworth Auth Module - A comprehensive authentication solution for React Native
|
|
|
70
70
|
| react | >=18.2.0 |
|
|
71
71
|
| react-native | >=0.74.5 |
|
|
72
72
|
| react-native-fast-image | >=8.6.3 |
|
|
73
|
-
| react-native-freshchat-sdk | >=4.6.6 |
|
|
74
73
|
| react-native-gesture-handler | >=2.16.0 |
|
|
75
74
|
| react-native-linear-gradient | >=2.8.3 |
|
|
76
75
|
| react-native-modalize | >=2.1.1 |
|
|
@@ -80,13 +79,12 @@ Truworth Auth Module - A comprehensive authentication solution for React Native
|
|
|
80
79
|
| react-native-svg | >=15.8.0 |
|
|
81
80
|
| react-native-vector-icons | >=9.2.0 |
|
|
82
81
|
|
|
83
|
-
> Note: lottie-react-native, react-native-fast-image
|
|
82
|
+
> Note: lottie-react-native, react-native-fast-image are optional and only needed if your app uses features that depend on them.
|
|
84
83
|
|
|
85
84
|
#### Web Dependencies
|
|
86
85
|
|
|
87
86
|
| Package | Version |
|
|
88
87
|
| ------------------------ | -------- |
|
|
89
|
-
| @truworth/twc-web-common | ^1.0.11 |
|
|
90
88
|
| @truworth/twc-web-design | ^1.9.0 |
|
|
91
89
|
| antd | ^5.6.3 |
|
|
92
90
|
| framer-motion | ^12.6.2 |
|
|
@@ -108,7 +106,6 @@ Truworth Auth Module - A comprehensive authentication solution for React Native
|
|
|
108
106
|
```bash
|
|
109
107
|
npm install \
|
|
110
108
|
next@^15.0.4 \
|
|
111
|
-
@truworth/twc-web-common@^1.0.11 \
|
|
112
109
|
@truworth/twc-web-design@^1.9.0 \
|
|
113
110
|
antd@^5.6.3 \
|
|
114
111
|
framer-motion@^12.6.2 \
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="18" viewBox="0 0 22 18">
|
|
2
|
+
<g fill="#ACD7D3">
|
|
3
|
+
<path d="M6.058 5.341c0 .568-.462 1.031-1.032 1.031H2.62c-.57 0-1.032-.463-1.032-1.03 0-.57.463-1.033 1.032-1.033h2.406c.57 0 1.032.463 1.032 1.032zM8.78 8.97c0 .568-.462 1.031-1.033 1.031H5.341c-.569 0-1.032-.463-1.032-1.03 0-.57.463-1.033 1.032-1.033h2.406c.57 0 1.032.463 1.032 1.032zM11.274 12.6c0 .567-.462 1.03-1.032 1.03H7.836c-.569 0-1.032-.463-1.032-1.03 0-.57.463-1.033 1.032-1.033h2.406c.57 0 1.032.463 1.032 1.032z"/>
|
|
4
|
+
<path d="M18.448.005H3.462C3.454.005 3.447 0 3.438 0H1.032C.462 0 0 .463 0 1.032 0 1.6.463 2.063 1.032 2.063h4.126l5.277 5.347c1.375 1.392 3.623 1.407 5.016.033l4.406-4.349c.048.145.08.297.08.457v10.361c0 .82-.668 1.488-1.489 1.488h-6.232c-.016 0-.03-.01-.047-.01H9.763c-.57 0-1.032.464-1.032 1.033 0 .568.463 1.03 1.032 1.03h.595v.006h8.09c1.956 0 3.547-1.59 3.547-3.547V3.552c0-1.957-1.59-3.547-3.547-3.547zm-4.443 5.973c-.584.576-1.529.57-2.105-.014L8.05 2.063h9.92l-3.965 3.915z"/>
|
|
5
|
+
</g>
|
|
6
|
+
</svg>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useEffect } from "react";
|
|
3
3
|
import { Button, Flex, OTPInput, Typography } from "@truworth/twc-web-design";
|
|
4
|
-
const VerifyMobileOTP = ({ validateOTP, timer, resendOTP, phone, status
|
|
4
|
+
const VerifyMobileOTP = ({ validateOTP, timer, resendOTP, phone, status }) => {
|
|
5
5
|
const [otp, setOtp] = useState('');
|
|
6
6
|
const [otpError, setOtpError] = useState(false);
|
|
7
7
|
useEffect(() => {
|
|
@@ -10,14 +10,16 @@ const VerifyMobileOTP = ({ validateOTP, timer, resendOTP, phone, status, resendT
|
|
|
10
10
|
setOtp('');
|
|
11
11
|
}
|
|
12
12
|
}, [status]);
|
|
13
|
-
|
|
14
|
-
return (_jsxs(_Fragment, { children: [defaultPhoneDisplayText, _jsx(OTPInput, { value: otp, onChange: (code) => {
|
|
13
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Typography, { type: 'body', size: 'large', className: 'mb-6 text-gray-400 text-center', children: ["OTP sent to", _jsx("span", { className: 'pl-2 text-secondary-dark', children: phone ? `XXXXXXX${phone.slice(-3)}` : 'your registered mobile number' })] }), _jsx(OTPInput, { value: otp, onChange: (code) => {
|
|
15
14
|
setOtp(code);
|
|
16
15
|
setOtpError(false);
|
|
17
16
|
}, error: otpError, maxLength: 6, className: `!w-auto ${otpError ? '!border-destructive' : ''}` }), otpError &&
|
|
18
|
-
_jsx(Typography, { type: "utility", size: "medium", className: "mt-4", color: "text-utility-danger-main", children: "Please enter the correct OTP." }),
|
|
19
|
-
_jsxs(Flex, { justify: 'between', align: 'center', className: 'mt-4', children: [_jsx(Typography, { type: 'utility', size: 'medium',
|
|
17
|
+
_jsx(Typography, { type: "utility", size: "medium", className: "mt-4", color: "text-utility-danger-main", children: "Please enter the correct OTP." }), timer <= 0 ?
|
|
18
|
+
_jsxs(Flex, { justify: 'between', align: 'center', className: 'mt-4', children: [_jsx(Typography, { type: 'utility', size: 'medium', children: "Didn't receive OTP?" }), _jsx(Button, { label: 'Re-send OTP', size: 'small', variant: 'link', onClick: () => {
|
|
19
|
+
setOtp('');
|
|
20
|
+
resendOTP();
|
|
21
|
+
} })] })
|
|
20
22
|
:
|
|
21
|
-
_jsxs(Typography, { type: 'utility', size: 'medium', className:
|
|
23
|
+
_jsxs(Typography, { type: 'utility', size: 'medium', className: 'mt-3', children: ["Resend Code in ", timer, " seconds"] }), _jsx(Button, { label: "Continue", isFullWidth: true, onClick: () => validateOTP?.(otp), disabled: otp ? otp?.length < 6 : true, className: "mt-6" })] }));
|
|
22
24
|
};
|
|
23
25
|
export { VerifyMobileOTP };
|
|
@@ -8,30 +8,25 @@ import { OTPStatusLabel } from '../OTPStatusLabel/index.native';
|
|
|
8
8
|
import OTPInputView from '@twotalltotems/react-native-otp-input';
|
|
9
9
|
const { gray } = Colors;
|
|
10
10
|
const VerifyMobileOTP = ({ validateOTP, timer, status, resendOTP, phone }) => {
|
|
11
|
-
const [otp,
|
|
11
|
+
const [otp, setOtp] = useState('');
|
|
12
12
|
const { otpValue } = useAuthPackageContext();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (otp?.length === 6) {
|
|
15
|
-
validateOTP(otp);
|
|
16
|
-
}
|
|
17
|
-
}, [otp]);
|
|
18
13
|
useEffect(() => {
|
|
19
14
|
if (otpValue && otpValue.length == 6) {
|
|
20
|
-
|
|
15
|
+
setOtp(otpValue);
|
|
21
16
|
}
|
|
22
17
|
}, [otpValue]);
|
|
23
18
|
return (_jsxs(Layout, { style: { flex: 1, backgroundColor: '#FFFFFF' }, children: [_jsx(Header, {}), _jsxs(CustomKeyboardAvoidingView, { behavior: Platform.OS === 'ios' ? 'padding' : undefined, keyboardVerticalOffset: 0, children: [_jsxs(ScrollView, { style: { paddingHorizontal: 20, paddingTop: 32, flex: 1 }, children: [_jsxs(Text, { textBreakStrategy: 'simple', style: {
|
|
24
19
|
fontSize: 20, fontWeight: '600', color: gray.gray_900,
|
|
25
20
|
lineHeight: 32, marginBottom: 32,
|
|
26
|
-
}, children: ["OTP sent to ", '\n', phone ? phone.replace(/\d(?=\d{4})/g, 'x') : ''] }), _jsx(View, { style: { justifyContent: 'center', flexDirection: 'row', marginBottom: 30, position: 'relative' }, children: _jsx(OTPInputView, { pinCount: 6, autoFocusOnLoad: false, onCodeChanged: text =>
|
|
21
|
+
}, children: ["OTP sent to ", '\n', phone ? phone.replace(/\d(?=\d{4})/g, 'x') : ''] }), _jsx(View, { style: { justifyContent: 'center', flexDirection: 'row', marginBottom: 30, position: 'relative' }, children: _jsx(OTPInputView, { pinCount: 6, autoFocusOnLoad: false, onCodeChanged: text => setOtp(text), codeInputFieldStyle: {
|
|
27
22
|
fontSize: 20, color: 'black', width: 30,
|
|
28
23
|
height: 45, borderWidth: 0, borderBottomWidth: 1,
|
|
29
24
|
}, codeInputHighlightStyle: { borderColor: '#03DAC6' }, style: {
|
|
30
25
|
height: 50,
|
|
31
26
|
width: Dimensions.get('window').width - 100,
|
|
32
|
-
}, code: otp ?? '', onCodeFilled: code =>
|
|
33
|
-
_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center' }, children: [
|
|
34
|
-
|
|
27
|
+
}, code: otp ?? '', onCodeFilled: code => validateOTP(code) }) }), timer <= 0 &&
|
|
28
|
+
_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center' }, children: [_jsx(Text, { style: { fontSize: 12, color: '#000', fontWeight: '400', opacity: 0.5 }, children: "Did not receive OTP?" }), _jsx(TouchableOpacity, { disabled: timer > 0, onPress: () => {
|
|
29
|
+
setOtp('');
|
|
35
30
|
resendOTP();
|
|
36
31
|
}, children: _jsx(Text, { style: { fontSize: 14, color: '#2cbaa4', fontWeight: '400', opacity: 1 }, children: "Re-send OTP" }) })] })] }), _jsx(View, { style: { width: '100%' }, children: _jsx(OTPStatusLabel, { status: status, timer: timer }) })] })] }));
|
|
37
32
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BASE_URL = process.env.BASE_URL;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const MEMBER_IMAGES_URL = process.env.NEXT_PUBLIC_MEMBER_IMAGES_URL;
|
|
2
|
+
export const CDN_IMAGES_URL = process.env.NEXT_PUBLIC_CDN_IMAGES_URL;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SocialLoginsEnum } from "../enums";
|
|
2
|
+
const socialLoginOptions = [
|
|
3
|
+
{
|
|
4
|
+
type: SocialLoginsEnum.Google,
|
|
5
|
+
iconImageUrl: `https://cdn-thewellnesscorner.s3.amazonaws.com/twc-web-images/template/google-icon.png`,
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
type: SocialLoginsEnum.Facebook,
|
|
9
|
+
iconImageUrl: `https://cdn-thewellnesscorner.s3.amazonaws.com/twc-web-images/template/facebook-icon.png`,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
type: SocialLoginsEnum.Apple,
|
|
13
|
+
iconImageUrl: `https://cdn-thewellnesscorner.s3.amazonaws.com/twc-web-images/template/apple-icon.png`,
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
export { socialLoginOptions };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useEffect, useState, useMemo, useCallback } from 'react';
|
|
3
3
|
import { MEMBER_IMAGES_URL } from '../constants/cdn-url';
|
|
4
|
-
import { createHttpClient } from '../helpers/
|
|
4
|
+
import { createHttpClient } from '../helpers/network';
|
|
5
5
|
/**
|
|
6
6
|
* Public Auth Authentication Context
|
|
7
7
|
*
|
|
@@ -31,8 +31,10 @@ const AuthPackageContext = React.createContext(null);
|
|
|
31
31
|
* @param onLogout - Optional callback after successful logout
|
|
32
32
|
* @param onLaunchAuthSession - Optional callback after successfully launching the auth session. For example, it can be used to set the Firebase notification token or request Android permissions.
|
|
33
33
|
* @param onRefreshSession - Optional handler for refreshing user session
|
|
34
|
+
* @param openChatSupport - Optional callback to open chat support
|
|
35
|
+
* @param socialLoginConfig - Optional social login configuration
|
|
34
36
|
*/
|
|
35
|
-
const AuthProvider = ({ children, LogoComponent, session, appConfig, onLogin, onLogout, onLaunchAuthSession, onRefreshSession }) => {
|
|
37
|
+
const AuthProvider = ({ children, LogoComponent, session, appConfig, onLogin, onLogout, onLaunchAuthSession, onRefreshSession, openChatSupport, socialLoginConfig }) => {
|
|
36
38
|
const [isLoadingProfile, setIsLoadingProfile] = useState(false);
|
|
37
39
|
const [profile, setProfile] = useState(null);
|
|
38
40
|
const [client, setClient] = useState(null);
|
|
@@ -170,6 +172,7 @@ const AuthProvider = ({ children, LogoComponent, session, appConfig, onLogin, on
|
|
|
170
172
|
LogoComponent,
|
|
171
173
|
appConfig: appConfigValue,
|
|
172
174
|
registrationMethod,
|
|
175
|
+
socialLoginConfig,
|
|
173
176
|
onLaunchAuthSession,
|
|
174
177
|
onLogin,
|
|
175
178
|
logout,
|
|
@@ -177,6 +180,7 @@ const AuthProvider = ({ children, LogoComponent, session, appConfig, onLogin, on
|
|
|
177
180
|
onTokenChange: (token) => setToken(token),
|
|
178
181
|
onRegistrationMethodChange: (method) => setRegistrationMethod(method),
|
|
179
182
|
otpValue,
|
|
183
|
+
openChatSupport
|
|
180
184
|
};
|
|
181
185
|
return (_jsx(AuthContext.Provider, { value: AuthContextValues, children: _jsx(AuthPackageContext.Provider, { value: AuthPackageContextValues, children: children }) }));
|
|
182
186
|
};
|
package/build/src/enums/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export var LoginMethodCode;
|
|
2
2
|
(function (LoginMethodCode) {
|
|
3
|
-
LoginMethodCode[LoginMethodCode["
|
|
3
|
+
LoginMethodCode[LoginMethodCode["Email"] = 1] = "Email";
|
|
4
4
|
LoginMethodCode[LoginMethodCode["Facebook"] = 2] = "Facebook";
|
|
5
5
|
LoginMethodCode[LoginMethodCode["Google"] = 3] = "Google";
|
|
6
6
|
LoginMethodCode[LoginMethodCode["Apple"] = 4] = "Apple";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { axiosClient } from '../api/axiosClient';
|
|
2
|
-
import { showMessage } from '
|
|
2
|
+
import { showMessage } from './show-message';
|
|
3
3
|
import {} from 'axios';
|
|
4
4
|
export const createHttpClient = ({ token, onRefreshSession, onLogout }) => {
|
|
5
5
|
let currentToken = token;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { showMessage } from '../helpers/show-message';
|
|
3
3
|
import { useAuthPackageContext } from './internal/useAuthPackageContext';
|
|
4
|
-
import { createHttpClient } from '../helpers/
|
|
4
|
+
import { createHttpClient } from '../helpers/network';
|
|
5
5
|
const useRequest = () => {
|
|
6
6
|
const { token: sessionToken, logout, refreshSession } = useAuthPackageContext();
|
|
7
7
|
const [token, setToken] = useState(sessionToken);
|
|
@@ -16,8 +16,12 @@ import SSOSearchOrganization from '../screens/SSOLogin/SearchOrganization/index.
|
|
|
16
16
|
import SSOAuthenticationMethods from '../screens/SSOLogin/AuthenticationMethods/index.native';
|
|
17
17
|
import SSOAuthWebView from '../screens/SSOLogin/AuthWebView/index.native';
|
|
18
18
|
import SSOCallback from '../screens/SSOLogin/SSOCallback/index.native';
|
|
19
|
+
import LoginWithMobileOTP from '../screens/LoginWithMobileOTP/index.native';
|
|
20
|
+
import EnterMobile from '../screens/EnterMobile/index.native';
|
|
21
|
+
import VerifyLinkPrimaryAccountEmailOTP from '../screens/VerifyLinkPrimaryAccountEmailOTP/index.native';
|
|
22
|
+
import VerifyLinkPrimaryAccountMobileOTP from '../screens/VerifyLinkPrimaryAccountMobileOTP/index.native';
|
|
19
23
|
const { Navigator, Screen } = createNativeStackNavigator();
|
|
20
24
|
const AuthNavigator = () => {
|
|
21
|
-
return (_jsxs(Navigator, { screenOptions: { headerShown: false }, children: [_jsx(Screen, { name: "Welcome", component: Welcome }), _jsx(Screen, { name: "EnterEmail", component: EnterEmail }), _jsx(Screen, { name: "EnterPassword", component: EnterPassword }), _jsx(Screen, { name: "SignUp", component: SignUp }), _jsx(Screen, { name: "CountryCode", component: CountryCode }), _jsx(Screen, { name: "CreatePassword", component: CreatePassword }), _jsx(Screen, { name: "UserConsent", component: UserConsent }), _jsx(Screen, { name: "VerifyMobile", component: VerifyMobile }), _jsx(Screen, { name: "VerifyEmail", component: VerifyEmail }), _jsx(Screen, { name: "LoginWithEmailOTP", component: LoginWithEmailOTP }), _jsx(Screen, { name: "VerifyResetPasswordOTP", component: VerifyResetPasswordOTP }), _jsx(Screen, { name: "ResetPassword", component: ResetPassword }), _jsx(Screen, { name: "SSOSearchOrganization", component: SSOSearchOrganization }), _jsx(Screen, { name: "SSOAuthenticationMethods", component: SSOAuthenticationMethods }), _jsx(Screen, { name: "SSOAuthWebView", component: SSOAuthWebView }), _jsx(Screen, { name: "SSOCallback", component: SSOCallback })] }));
|
|
25
|
+
return (_jsxs(Navigator, { screenOptions: { headerShown: false }, children: [_jsx(Screen, { name: "Welcome", component: Welcome }), _jsx(Screen, { name: "EnterEmail", component: EnterEmail }), _jsx(Screen, { name: "EnterPassword", component: EnterPassword }), _jsx(Screen, { name: "SignUp", component: SignUp }), _jsx(Screen, { name: "CountryCode", component: CountryCode }), _jsx(Screen, { name: "CreatePassword", component: CreatePassword }), _jsx(Screen, { name: "UserConsent", component: UserConsent }), _jsx(Screen, { name: "VerifyMobile", component: VerifyMobile }), _jsx(Screen, { name: "VerifyEmail", component: VerifyEmail }), _jsx(Screen, { name: "LoginWithEmailOTP", component: LoginWithEmailOTP }), _jsx(Screen, { name: "VerifyResetPasswordOTP", component: VerifyResetPasswordOTP }), _jsx(Screen, { name: "ResetPassword", component: ResetPassword }), _jsx(Screen, { name: "LoginWithMobileOTP", component: LoginWithMobileOTP }), _jsx(Screen, { name: "EnterMobile", component: EnterMobile }), _jsx(Screen, { name: "VerifyLinkPrimaryAccountEmailOTP", component: VerifyLinkPrimaryAccountEmailOTP }), _jsx(Screen, { name: "VerifyLinkPrimaryAccountMobileOTP", component: VerifyLinkPrimaryAccountMobileOTP }), _jsx(Screen, { name: "SSOSearchOrganization", component: SSOSearchOrganization }), _jsx(Screen, { name: "SSOAuthenticationMethods", component: SSOAuthenticationMethods }), _jsx(Screen, { name: "SSOAuthWebView", component: SSOAuthWebView }), _jsx(Screen, { name: "SSOCallback", component: SSOCallback })] }));
|
|
22
26
|
};
|
|
23
27
|
export { AuthNavigator };
|
|
@@ -1,68 +1,77 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
2
|
import { showMessage } from "../../../../helpers/show-message";
|
|
3
3
|
import { useAuthPackageContext } from "../../../../hooks/internal/useAuthPackageContext";
|
|
4
4
|
import { checkEmailExists } from "../../../../api/auth";
|
|
5
|
-
import { LoginMethodCode } from "../../../../enums";
|
|
6
|
-
const
|
|
5
|
+
import { LoginMethodCode, RegistrationMethod } from "../../../../enums";
|
|
6
|
+
const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
|
-
*
|
|
9
|
+
* Hook for managing Enter Email screen logic and authentication integration.
|
|
10
10
|
*/
|
|
11
11
|
const useEnterEmail = () => {
|
|
12
|
+
const [email, setEmail] = useState("");
|
|
13
|
+
const [loginType, setLoginType] = useState("");
|
|
12
14
|
const [loading, setLoading] = useState(false);
|
|
13
|
-
const [
|
|
14
|
-
const [
|
|
15
|
-
const [loginType, setLoginType] = useState('');
|
|
16
|
-
const [email, setEmail] = useState('');
|
|
15
|
+
const [isEmailValid, setIsEmailValid] = useState(false);
|
|
16
|
+
const [isLoginConflictModalVisible, setIsLoginConflictModalVisible] = useState(false);
|
|
17
17
|
const { appConfig, onRegistrationMethodChange } = useAuthPackageContext();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Handles email input change with validation
|
|
20
|
+
*/
|
|
21
|
+
const handleEmailChange = useCallback((value) => {
|
|
22
|
+
const normalizedEmail = value.toLowerCase().trim();
|
|
23
|
+
setEmail(normalizedEmail);
|
|
24
|
+
setIsEmailValid(EMAIL_REGEX.test(normalizedEmail));
|
|
25
|
+
}, []);
|
|
26
|
+
/**
|
|
27
|
+
* Validates email existence and handles login conflicts
|
|
28
|
+
*/
|
|
29
|
+
const handleEmailExists = useCallback(async ({ onValidate }) => {
|
|
24
30
|
setLoading(true);
|
|
25
31
|
try {
|
|
26
32
|
const { emailExist, loginType } = await checkEmailExists(email);
|
|
27
|
-
const
|
|
28
|
-
if (emailExist &&
|
|
29
|
-
const
|
|
30
|
-
[LoginMethodCode.Facebook]:
|
|
31
|
-
[LoginMethodCode.Google]:
|
|
32
|
-
[LoginMethodCode.Apple]:
|
|
33
|
-
[LoginMethodCode.SSO]:
|
|
33
|
+
const loginCode = Number(loginType);
|
|
34
|
+
if (emailExist && loginCode !== LoginMethodCode.Email) {
|
|
35
|
+
const loginMethodMap = {
|
|
36
|
+
[LoginMethodCode.Facebook]: "Facebook",
|
|
37
|
+
[LoginMethodCode.Google]: "Google",
|
|
38
|
+
[LoginMethodCode.Apple]: "Apple",
|
|
39
|
+
[LoginMethodCode.SSO]: "SSO",
|
|
34
40
|
};
|
|
35
|
-
setLoginType(
|
|
36
|
-
|
|
41
|
+
setLoginType(loginMethodMap[loginCode] || "your social account");
|
|
42
|
+
setIsLoginConflictModalVisible(true);
|
|
37
43
|
return;
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
onRegistrationMethodChange(RegistrationMethod.EMAIL);
|
|
46
|
+
onValidate({ emailExist });
|
|
40
47
|
}
|
|
41
|
-
catch (
|
|
42
|
-
const
|
|
43
|
-
showMessage({ message
|
|
48
|
+
catch (error) {
|
|
49
|
+
const message = error?.response?.data?.errors?.[0]?.message ?? "Something went wrong";
|
|
50
|
+
showMessage({ message });
|
|
44
51
|
}
|
|
45
52
|
finally {
|
|
46
53
|
setLoading(false);
|
|
47
54
|
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
}, [email]);
|
|
56
|
+
/**
|
|
57
|
+
* Clears email input field
|
|
58
|
+
*/
|
|
59
|
+
const handleClearEmail = useCallback(() => {
|
|
60
|
+
setEmail("");
|
|
61
|
+
setIsEmailValid(false);
|
|
52
62
|
}, []);
|
|
53
63
|
return {
|
|
54
64
|
email,
|
|
55
|
-
|
|
56
|
-
isInvalidEmail,
|
|
65
|
+
isEmailValid,
|
|
57
66
|
loading,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
handleEmailChange,
|
|
68
|
+
handleEmailExists,
|
|
69
|
+
handleClearEmail,
|
|
70
|
+
isLoginConflictModalVisible,
|
|
71
|
+
setIsLoginConflictModalVisible,
|
|
72
|
+
appName: appConfig.appName,
|
|
73
|
+
loginConflictTitle: `Sign in with ${loginType}`,
|
|
74
|
+
loginConflictDescription: `Looks like you previously registered using ${loginType}. Please go back and sign in with ${loginType}.`,
|
|
66
75
|
};
|
|
67
76
|
};
|
|
68
77
|
export { useEnterEmail };
|
|
@@ -1,28 +1,54 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Button, Form, TextInput, useForm } from '@truworth/twc-web-design';
|
|
2
|
+
import { Button, Flex, Form, TextInput, Typography, useForm } from '@truworth/twc-web-design';
|
|
3
3
|
import { ConfirmationModal as LoginConflictModal } from '../../components/ConfirmationModal';
|
|
4
4
|
import { ScreenLayout } from "../../components/ScreenLayout";
|
|
5
5
|
import { useEnterEmail } from "./hooks/internal/useEnterEmail";
|
|
6
6
|
import { SupportDetails } from '../../components/SupportDetails';
|
|
7
|
+
import { useWelcome } from '../Welcome/hooks/internal/useWelcome';
|
|
8
|
+
import { socialLoginOptions } from '../../constants/social-login-options';
|
|
9
|
+
import { SocialLoginModal } from '../Welcome/components/SocialLoginModal';
|
|
10
|
+
import { useSocialAuth } from '../Welcome/SocialAuth/hooks/useSocialAuth.web';
|
|
11
|
+
import { SocialLoginsEnum } from '../../enums';
|
|
12
|
+
import _ from 'lodash';
|
|
7
13
|
const EnterEmail = ({ onContinue, onPressSignInWithSSO }) => {
|
|
8
|
-
const {
|
|
14
|
+
const { loginWithGoogle, loginWithFacebook } = useSocialAuth();
|
|
15
|
+
const { email, isEmailValid, handleEmailChange, appName, handleEmailExists, loading, loginConflictTitle, loginConflictDescription, isLoginConflictModalVisible, setIsLoginConflictModalVisible, } = useEnterEmail();
|
|
16
|
+
const { showSocialLoginModal, setShowSocialLoginModal, socialLoginType, setSocialLoginType, isSocialLoginEnabled, socialLoginConfig, } = useWelcome();
|
|
9
17
|
const form = useForm({ defaultValues: { email } });
|
|
18
|
+
const handleLogin = () => {
|
|
19
|
+
setShowSocialLoginModal(false);
|
|
20
|
+
switch (socialLoginType) {
|
|
21
|
+
case SocialLoginsEnum.Google:
|
|
22
|
+
return loginWithGoogle();
|
|
23
|
+
case SocialLoginsEnum.Facebook:
|
|
24
|
+
return loginWithFacebook();
|
|
25
|
+
default:
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
10
29
|
return (_jsxs(_Fragment, { children: [_jsxs(ScreenLayout, { title: `Hi, Welcome To ${appName}!`, subTitle: "Please enter email to get started.", buttonProps: {
|
|
11
30
|
loading,
|
|
12
31
|
label: 'Continue',
|
|
13
32
|
onClick: () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
}
|
|
33
|
+
handleEmailExists({
|
|
34
|
+
onValidate: ({ emailExist }) => onContinue({ email, emailExist })
|
|
35
|
+
});
|
|
19
36
|
},
|
|
20
|
-
disabled:
|
|
37
|
+
disabled: !isEmailValid,
|
|
21
38
|
}, children: [_jsx(Form, { className: "w-full", form: form, children: _jsx(Form.Item, { name: "email", label: "Email", children: _jsx(TextInput, { type: "email", value: email, size: "medium", placeholder: "example@domain", ...form.register('email', {
|
|
22
39
|
onChange: (e) => {
|
|
23
|
-
|
|
40
|
+
handleEmailChange(e.target.value);
|
|
24
41
|
}
|
|
25
|
-
}) }) }) }),
|
|
26
|
-
_jsx(LoginConflictModal, { title:
|
|
42
|
+
}) }) }) }), isLoginConflictModalVisible &&
|
|
43
|
+
_jsx(LoginConflictModal, { title: loginConflictTitle, description: loginConflictDescription, visible: isLoginConflictModalVisible, onProceed: () => setIsLoginConflictModalVisible(false), onClose: () => setIsLoginConflictModalVisible(false), primaryLabel: 'Okay' })] }), _jsx(Button, { isFullWidth: true, type: "button", label: 'Sign In with SSO', variant: 'secondary', className: 'flex-none mt-6', onClick: onPressSignInWithSSO }), isSocialLoginEnabled && (_jsxs(_Fragment, { children: [_jsxs(Flex, { align: "center", className: "my-6", children: [_jsx(Flex, { className: "flex-1 border-t border-gray-300" }), _jsx(Typography, { type: 'body', size: 'small', className: "text-gray-500 px-4", children: "or continue with" }), _jsx(Flex, { className: "flex-1 border-t border-gray-300" })] }), _jsx(Flex, { justify: 'center', align: 'center', className: "gap-4", children: socialLoginOptions.map(({ type, iconImageUrl }) => {
|
|
44
|
+
if (type === SocialLoginsEnum.Apple) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return socialLoginConfig?.[type]?.enabled && (_jsxs("button", { type: "button", className: "flex justify-center p-3 gap-2 items-center\n rounded-[50px] flex-1 border text-gray-800 hover:text-gray-800\n border-gray-100 bg-gray-100 hover:border-gray-300 transition-all duration-300 cursor-pointer", onClick: () => {
|
|
48
|
+
setSocialLoginType(type);
|
|
49
|
+
setShowSocialLoginModal(true);
|
|
50
|
+
}, children: [_jsx("img", { src: iconImageUrl, style: { width: 20, height: 20 } }), _jsx(Typography, { type: 'utility', size: 'medium', children: _.startCase(type) })] }, type));
|
|
51
|
+
}) })] })), showSocialLoginModal &&
|
|
52
|
+
_jsx(SocialLoginModal, { visible: showSocialLoginModal, hide: () => setShowSocialLoginModal(false), socialLoginType: socialLoginType, onClick: handleLogin }), _jsx(SupportDetails, {})] }));
|
|
27
53
|
};
|
|
28
54
|
export default EnterEmail;
|
|
@@ -8,13 +8,12 @@ import { ConfirmationModal as LoginConflictModal } from '../../components/Confir
|
|
|
8
8
|
import { RegistrationMethod } from '../../enums';
|
|
9
9
|
const { utility } = Colors;
|
|
10
10
|
const EnterEmail = ({ navigation }) => {
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
11
|
+
const { email, isEmailValid, handleEmailChange, handleClearEmail, handleEmailExists, loading, loginConflictTitle, loginConflictDescription, isLoginConflictModalVisible, setIsLoginConflictModalVisible } = useEnterEmail();
|
|
12
|
+
const onValidate = (params) => {
|
|
13
13
|
if (params.emailExist) {
|
|
14
14
|
navigation.navigate('EnterPassword', { email });
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
onRegistrationMethodChange(RegistrationMethod.EMAIL);
|
|
18
17
|
navigation.navigate('SignUp', { email });
|
|
19
18
|
}
|
|
20
19
|
};
|
|
@@ -23,12 +22,10 @@ const EnterEmail = ({ navigation }) => {
|
|
|
23
22
|
label: 'Continue',
|
|
24
23
|
onPress: () => {
|
|
25
24
|
Keyboard.dismiss();
|
|
26
|
-
|
|
27
|
-
handleValidateEmail({ onContinue });
|
|
28
|
-
}
|
|
25
|
+
handleEmailExists({ onValidate });
|
|
29
26
|
},
|
|
30
|
-
disabled:
|
|
31
|
-
}, children: _jsx(TextInputField, { value: email, placeholder: 'Enter here...', onChangeValue:
|
|
32
|
-
_jsx(LoginConflictModal, { title:
|
|
27
|
+
disabled: !isEmailValid,
|
|
28
|
+
}, children: _jsx(TextInputField, { value: email, placeholder: 'Enter here...', onChangeValue: handleEmailChange, rightIcon2: email.length > 0 ? 'close' : '', onPressRightIcon2: handleClearEmail, autoFocus: true, autoCapitalize: 'none', keyboardType: 'email-address' }) }), isLoginConflictModalVisible &&
|
|
29
|
+
_jsx(LoginConflictModal, { title: loginConflictTitle, description: loginConflictDescription, visible: isLoginConflictModalVisible, onProceed: () => setIsLoginConflictModalVisible(false), onClose: () => setIsLoginConflictModalVisible(false), iconColor: utility.warning_main, primaryLabel: 'Okay' })] }));
|
|
33
30
|
};
|
|
34
31
|
export default EnterEmail;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
import { axiosClient } from '../../../../../../api/axiosClient';
|
|
3
|
+
import { showMessage } from "../../../../../../helpers/show-message";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* Internal hook for managing useExistingAccountsSheet hook state and auth context integration. Not exposed to package consumers.
|
|
7
|
+
*/
|
|
8
|
+
const useExistingAccountsSheet = () => {
|
|
9
|
+
const [loading, setLoading] = useState(false);
|
|
10
|
+
const [selectedAccount, setSelectedAccount] = useState(null);
|
|
11
|
+
const linkPrimaryAccount = useCallback(({ phone, onInitiateLinking }) => {
|
|
12
|
+
setLoading(true);
|
|
13
|
+
axiosClient({
|
|
14
|
+
url: '/auth/mobile/link-primary-account/initiate',
|
|
15
|
+
method: 'POST',
|
|
16
|
+
data: {
|
|
17
|
+
phone,
|
|
18
|
+
memberId: selectedAccount?.memberId,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
.then((res) => onInitiateLinking(res.data))
|
|
22
|
+
.catch((error) => {
|
|
23
|
+
console.log(error);
|
|
24
|
+
const message = error?.response?.data?.errors?.[0]?.message ?? 'Unable to initiate linking. Please try again.';
|
|
25
|
+
showMessage({ message });
|
|
26
|
+
})
|
|
27
|
+
.finally(() => setLoading(false));
|
|
28
|
+
}, [selectedAccount]);
|
|
29
|
+
return {
|
|
30
|
+
loading,
|
|
31
|
+
linkPrimaryAccount,
|
|
32
|
+
selectedAccount,
|
|
33
|
+
setSelectedAccount
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export { useExistingAccountsSheet };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useExistingAccountsSheet } from './hooks/internal/useExistingAccountsSheet';
|
|
3
|
+
import { ResponsiveModal, Typography, Flex, Button, Card, Radio } from '@truworth/twc-web-design';
|
|
4
|
+
import { SupportDetails } from '../../../../components/SupportDetails';
|
|
5
|
+
import { IonIcon } from '../../../../components/IonIcon';
|
|
6
|
+
import { LoginMethodCode } from '../../../../enums';
|
|
7
|
+
import moment from 'moment';
|
|
8
|
+
const ExistingAccountsSheet = ({ visible, hide, phone, existingAccounts, onInitiateAccountLinking }) => {
|
|
9
|
+
const { loading, linkPrimaryAccount, selectedAccount, setSelectedAccount, } = useExistingAccountsSheet();
|
|
10
|
+
const onContinue = () => {
|
|
11
|
+
if (!phone || !selectedAccount?.email) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
linkPrimaryAccount({
|
|
15
|
+
phone,
|
|
16
|
+
onInitiateLinking: ({ sessionToken }) => {
|
|
17
|
+
onInitiateAccountLinking?.({
|
|
18
|
+
sessionToken,
|
|
19
|
+
email: selectedAccount?.email
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
const displayPhone = phone ? `+91${phone.replace(/^.{8}/, 'XXXXXXXX')}` : '+91**********';
|
|
25
|
+
return (_jsxs(ResponsiveModal, { open: visible, onClose: hide, onOpenChange: hide, maskClosable: false, title: _jsxs(_Fragment, { children: [_jsx(Typography, { type: "heading", size: "h6", children: "Multiple Accounts Found" }), _jsxs(Typography, { type: "utility", size: "medium", color: "gray-600", className: "mt-2 mb-3", children: ["The phone number ", displayPhone, " is linked to the following accounts."] }), _jsx("hr", {})] }), centered: true, showCloseButton: false, className: "px-0", footer: _jsxs(Flex, { direction: "column", className: 'pt-1', children: [_jsx(Flex, { className: "flex-1 border-t border-gray-300 mb-2" }), selectedAccount &&
|
|
26
|
+
_jsxs(Flex, { align: 'center', className: 'bg-utility-warning-bg p-2 rounded-lg gap-1', children: [_jsx(IonIcon, { name: "information-circle-outline", style: { color: "hsl(var(--tw-ui-utility---warning--main))", fontSize: 24 } }), _jsxs(Typography, { type: "utility", size: "small", children: [_jsx("span", { className: "text-gray-500 text-[12px]", children: "Once you proceed, this phone number will be removed" }), " from other accounts."] })] }), _jsx(Button, { isFullWidth: true, loading: loading, variant: "primary", label: "Link and Continue", className: 'mt-4 mb-[-16px]', onClick: onContinue, disabled: !selectedAccount }), _jsx(SupportDetails, {})] }), children: [_jsx(Typography, { type: "utility", size: "medium", className: "mb-4", children: "Select account you want to continue with." }), existingAccounts.map((item) => {
|
|
27
|
+
return (_jsx(OptionCard, { item: item, onClick: () => setSelectedAccount(item), selectedItem: selectedAccount }, item.memberId));
|
|
28
|
+
})] }));
|
|
29
|
+
};
|
|
30
|
+
const OptionCard = ({ item, onClick, selectedItem }) => {
|
|
31
|
+
return (_jsx(Card, { containerStyle: `p-4 mb-2 ${item.memberId === selectedItem?.memberId ? 'border-primary' : 'border-gray-200'}`, children: _jsxs(Flex, { className: 'gap-2', onClick: onClick, children: [_jsx(Radio, { selectedValue: selectedItem?.memberId, options: [{ label: '', value: item.memberId }] }), _jsx(Flex, { direction: 'column', className: 'mt-[-2px]', children: _jsxs(_Fragment, { children: [_jsxs(Flex, { direction: "column", className: "border-b-2 pb-2 w-full", children: [_jsx(Typography, { type: "utility", size: "large", className: "break-words w-full mb-1", children: item.name }), _jsx(Typography, { type: "utility", size: "medium", color: "primary", className: "truncate w-full", children: item.email })] }), _jsxs(_Fragment, { children: [_jsxs(Flex, { justify: "between", className: "mt-3", children: [_jsx(Typography, { type: "utility", size: "medium", color: "gray-700", children: "Registration Source" }), _jsx(Typography, { type: "utility", size: "medium", color: "gray-800", children: item.loginType ? LoginMethodCode[item.loginType] : '—' })] }), _jsxs(Flex, { justify: "between", className: "mt-3", children: [_jsx(Typography, { type: "utility", size: "medium", color: "gray-700", children: "Registration Date" }), _jsx(Typography, { type: "utility", size: "medium", color: "gray-800", children: item.createdOn ? moment(item.createdOn).format('DD/MM/YYYY') : '—' })] })] })] }) })] }) }));
|
|
32
|
+
};
|
|
33
|
+
export { ExistingAccountsSheet };
|