@truworth/twc-auth 3.0.12 → 3.0.13
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/build/src/screens/SSOLogin/AuthenticationMethods/hooks/internal/useSSOAuthenticationMethods.js +27 -3
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.js +10 -8
- package/build/src/screens/SSOLogin/AuthenticationMethods/index.native.js +20 -5
- package/build/types/screens/SSOLogin/AuthenticationMethods/hooks/internal/useSSOAuthenticationMethods.d.ts +7 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useState, useRef, useEffect } from "react";
|
|
1
|
+
import { useState, useRef, useEffect, useMemo } from "react";
|
|
2
2
|
import { axiosClient } from "../../../../../api/axiosClient";
|
|
3
3
|
import { showMessage } from "../../../../../helpers/show-message";
|
|
4
|
-
const useSSOAuthenticationMethods = () => {
|
|
4
|
+
const useSSOAuthenticationMethods = ({ client }) => {
|
|
5
5
|
const [loading, setLoading] = useState(false);
|
|
6
6
|
const isMountedRef = useRef(true);
|
|
7
7
|
useEffect(() => {
|
|
@@ -34,6 +34,30 @@ const useSSOAuthenticationMethods = () => {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
const headingText = useMemo(() => {
|
|
38
|
+
if (client?.ssoEnabled && client?.mobileLoginEnabled) {
|
|
39
|
+
return `Choose how to sign in`;
|
|
40
|
+
}
|
|
41
|
+
if (client?.ssoEnabled) {
|
|
42
|
+
return `Sign in with your organization account`;
|
|
43
|
+
}
|
|
44
|
+
if (client?.mobileLoginEnabled) {
|
|
45
|
+
return `Sign in with your mobile number`;
|
|
46
|
+
}
|
|
47
|
+
return 'No Single Sign-On methods are available';
|
|
48
|
+
}, [client?.ssoEnabled, client?.mobileLoginEnabled]);
|
|
49
|
+
const subHeadingText = useMemo(() => {
|
|
50
|
+
if (!client?.ssoEnabled && !client?.mobileLoginEnabled) {
|
|
51
|
+
return 'Your organization has not configured any single sign-on methods yet. Please contact your administrator.';
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}, [client?.ssoEnabled, client?.mobileLoginEnabled]);
|
|
55
|
+
return {
|
|
56
|
+
loading,
|
|
57
|
+
initiateSSOLogin,
|
|
58
|
+
headingText,
|
|
59
|
+
subHeadingText,
|
|
60
|
+
hasMultipleLoginOptions: client?.ssoEnabled && client?.mobileLoginEnabled,
|
|
61
|
+
};
|
|
38
62
|
};
|
|
39
63
|
export { useSSOAuthenticationMethods };
|
|
@@ -6,9 +6,9 @@ import { ScreenLayout } from "../../../components/ScreenLayout";
|
|
|
6
6
|
import { CDN_IMAGES_URL } from "../../../constants/cdn-url";
|
|
7
7
|
import { showMessage } from "../../../helpers/show-message";
|
|
8
8
|
import React from "react";
|
|
9
|
-
import { KeyRound,
|
|
9
|
+
import { KeyRound, Smartphone } from "lucide-react";
|
|
10
10
|
const SSOAuthenticationMethods = ({ client, onPressBack, handleMobileLogin }) => {
|
|
11
|
-
const { loading, initiateSSOLogin } = useSSOAuthenticationMethods();
|
|
11
|
+
const { loading, initiateSSOLogin, hasMultipleLoginOptions, headingText, subHeadingText } = useSSOAuthenticationMethods({ client });
|
|
12
12
|
const { LogoComponent } = useAuthPackageContext();
|
|
13
13
|
const renderLogo = () => {
|
|
14
14
|
if (!LogoComponent) {
|
|
@@ -40,11 +40,13 @@ const SSOAuthenticationMethods = ({ client, onPressBack, handleMobileLogin }) =>
|
|
|
40
40
|
};
|
|
41
41
|
return (_jsx(ScreenLayout, { onPressBack: onPressBack, title: _jsxs(Flex, { direction: "column", children: [client?.image ?
|
|
42
42
|
_jsx("img", { src: client?.image, width: 175, height: 117, alt: `${client?.name ?? 'Client'} logo` })
|
|
43
|
-
: renderLogo(), _jsx(Typography, { type: "heading", size: "h5", className: "
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
: renderLogo(), _jsx(Typography, { type: "heading", size: "h5", className: "mb-4 mt-6", children: headingText }), subHeadingText &&
|
|
44
|
+
_jsx(Typography, { type: "body", size: "large", className: "text-gray-600", children: subHeadingText }), client?.ssoEnabled &&
|
|
45
|
+
_jsx(Button, { label: "Login with SSO", isFullWidth: true, variant: "primary", leftIcon: _jsx(KeyRound, {}), onClick: () => initiateSSOLogin({
|
|
46
|
+
clientId: client.id,
|
|
47
|
+
onSSOLoginInitiated
|
|
48
|
+
}), loading: loading }), hasMultipleLoginOptions &&
|
|
49
|
+
_jsxs(_Fragment, { children: [_jsx(Typography, { type: "body", size: "large", className: "mt-6 text-gray-600", children: "Recommended for quick access" }), _jsxs(Flex, { align: "center", className: "my-4", 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" }), _jsx(Flex, { className: "flex-1 border-t border-gray-300" })] })] }), client?.mobileLoginEnabled &&
|
|
50
|
+
_jsx(Button, { label: "Login with Mobile Number", isFullWidth: true, className: "mt-6", leftIcon: _jsx(Smartphone, {}), variant: "secondary", onClick: handleMobileLogin })] }) }));
|
|
49
51
|
};
|
|
50
52
|
export default SSOAuthenticationMethods;
|
|
@@ -13,9 +13,9 @@ const { primary, gray } = Colors;
|
|
|
13
13
|
const SSOAuthenticationMethods = ({ route }) => {
|
|
14
14
|
const { client } = route.params;
|
|
15
15
|
const [aspectRatio, setAspectRatio] = useState(1);
|
|
16
|
-
const { loading, initiateSSOLogin } = useSSOAuthenticationMethods();
|
|
17
|
-
const { LogoComponent } = useAuthPackageContext();
|
|
16
|
+
const { loading, initiateSSOLogin, hasMultipleLoginOptions, headingText, subHeadingText } = useSSOAuthenticationMethods({ client });
|
|
18
17
|
const navigation = useNavigation();
|
|
18
|
+
const { LogoComponent } = useAuthPackageContext();
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
if (client.image) {
|
|
21
21
|
Image.getSize(client.image, (width, height) => {
|
|
@@ -52,8 +52,23 @@ const SSOAuthenticationMethods = ({ route }) => {
|
|
|
52
52
|
};
|
|
53
53
|
return (_jsx(ScreenLayout, { title: "", containerStyle: { flex: 1, backgroundColor: primary.white }, children: _jsxs(View, { style: { flex: 1, justifyContent: 'center' }, children: [client.image ?
|
|
54
54
|
_jsx(FastImage, { source: { uri: client.image }, resizeMode: 'contain', style: { width: 180, aspectRatio: aspectRatio, alignSelf: 'center', marginTop: -150 } })
|
|
55
|
-
: renderLogo(), _jsx(Text, { style: { textAlign: 'center', fontSize:
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
: renderLogo(), _jsx(Text, { style: { textAlign: 'center', fontSize: 18, fontWeight: '600', color: gray.gray_700, marginTop: 30, lineHeight: 32 }, children: headingText }), subHeadingText &&
|
|
56
|
+
_jsx(Text, { style: {
|
|
57
|
+
textAlign: 'center',
|
|
58
|
+
fontSize: 16,
|
|
59
|
+
lineHeight: 22,
|
|
60
|
+
color: gray.gray_600,
|
|
61
|
+
marginTop: 12,
|
|
62
|
+
marginHorizontal: 32,
|
|
63
|
+
}, children: subHeadingText }), client?.ssoEnabled &&
|
|
64
|
+
_jsx(RoundedButton, { loading: loading, type: 'primary', label: 'Login with SSO', size: 'large', containerStyle: { marginTop: 18 }, onPress: () => initiateSSOLogin({
|
|
65
|
+
clientId: client.id,
|
|
66
|
+
onSSOLoginInitiated,
|
|
67
|
+
}), leftIcon: 'key-outline' }), hasMultipleLoginOptions &&
|
|
68
|
+
_jsxs(_Fragment, { children: [_jsx(Text, { style: { textAlign: 'center', fontSize: 14, color: gray.gray_700, marginTop: 20, }, children: "Recommended for quick access" }), _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', marginTop: 30, marginHorizontal: 30 }, children: [_jsx(View, { style: { flex: 1, height: 1, backgroundColor: gray.gray_200, } }), _jsx(Text, { style: { width: 50, textAlign: 'center', color: gray.gray_500, fontSize: 16, }, children: "OR" }), _jsx(View, { style: { flex: 1, height: 1, backgroundColor: gray.gray_200, } })] })] }), client?.mobileLoginEnabled &&
|
|
69
|
+
_jsx(RoundedButton, { type: 'secondary', label: 'Login with Mobile Number', size: 'large', containerStyle: {
|
|
70
|
+
marginHorizontal: 16,
|
|
71
|
+
marginTop: 30
|
|
72
|
+
}, onPress: () => navigation.navigate('EnterMobile'), leftIcon: 'phone-portrait-outline' })] }) }));
|
|
58
73
|
};
|
|
59
74
|
export default SSOAuthenticationMethods;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { SSOInitiationData } from "../../types";
|
|
2
|
-
|
|
2
|
+
import type { Client } from "../../../../../types/types";
|
|
3
|
+
declare const useSSOAuthenticationMethods: ({ client }: {
|
|
4
|
+
client: Client;
|
|
5
|
+
}) => {
|
|
3
6
|
loading: boolean;
|
|
4
7
|
initiateSSOLogin: ({ clientId, onSSOLoginInitiated }: {
|
|
5
8
|
clientId: number;
|
|
6
9
|
onSSOLoginInitiated: (data: SSOInitiationData) => void;
|
|
7
10
|
}) => void;
|
|
11
|
+
headingText: string;
|
|
12
|
+
subHeadingText: string | null;
|
|
13
|
+
hasMultipleLoginOptions: boolean;
|
|
8
14
|
};
|
|
9
15
|
export { useSSOAuthenticationMethods };
|