Skip to content

Commit

Permalink
Merge pull request #550 from etn-ccis/bug/546-registration-not-working
Browse files Browse the repository at this point in the history
fixed the content collapsing in registration workflow
  • Loading branch information
shubham-eaton authored Dec 16, 2024
2 parents 7ca70cc + 1824581 commit 2bc5f57
Show file tree
Hide file tree
Showing 20 changed files with 1,293 additions and 3,336 deletions.
5 changes: 2 additions & 3 deletions login-workflow/example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ export const App = (): JSX.Element => {
getAccessToken() // eslint-disable-next-line
.then((res) => console.log(res.access_token)) // eslint-disable-next-line
.catch((err) => console.log(err));
} catch (error) { // eslint-disable-next-line
} catch (error) {
// eslint-disable-next-line
console.error('Okta error for access token', error);
}
};

useEffect(() => {


EventEmitter.addListener('signInSuccess', handleSignInSuccess);

return () => {
Expand Down
6 changes: 3 additions & 3 deletions login-workflow/example/okta.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default {
oidc: {
oidc: {
clientId: process.env.OKTA_CLIENT_ID,
redirectUri: process.env.OKTA_REDIRECT_URI,
endSessionRedirectUri: process.env.OKTA_LOGOUT_REDIRECT_URI,
discoveryUri: process.env.OKTA_ISSUER,
scopes: ['openid', 'profile', 'offline_access', 'groups'],
requireHardwareBackedKeyStore: false,
}
};
},
};
8 changes: 4 additions & 4 deletions login-workflow/example/src/components/UserMenuComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export const UserMenuComponent: React.FC<UserMenuExampleProps> = (props) => {
const logout = async (): Promise<void> => {
LocalStorage.clearAuthCredentials();
try {
await signOut();
await revokeAccessToken();
await clearTokens();
await signOut();
await revokeAccessToken();
await clearTokens();
} catch (_error) {
// eslint-disable-next-line no-console
console.log(_error as Error);
}
}
app.onUserNotAuthenticated();
};
const handleLogout = (): void => {
Expand Down
8 changes: 4 additions & 4 deletions login-workflow/example/src/screens/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const ChangePassword = (): JSX.Element => {
try {
await revokeAccessToken();
await clearTokens();
} catch (_error) {
// eslint-disable-next-line no-console
console.log(_error as Error);
}
} catch (_error) {
// eslint-disable-next-line no-console
console.log(_error as Error);
}
app.onUserNotAuthenticated();
// below line is not need for okta workflow
// app.setLoginData({ email: '', rememberMe: false });
Expand Down
78 changes: 41 additions & 37 deletions login-workflow/example/src/screens/OktaLogin.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
import { Image } from 'react-native';
import { OktaAuthContextProvider, OktaLoginScreenProps, OktaRedirectLoginScreen } from '@brightlayer-ui/react-native-auth-workflow';
import {
OktaAuthContextProvider,
OktaLoginScreenProps,
OktaRedirectLoginScreen,
} from '@brightlayer-ui/react-native-auth-workflow';
import { useApp } from '../contexts/AppContextProvider';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
Expand All @@ -13,43 +17,43 @@ export const OktaLogin: React.FC<React.PropsWithChildren<OktaLoginScreenProps>>

return (
<OktaAuthContextProvider
language={app.language}
i18n={i18nAppInstance}
navigate={(destination: -1 | string) => {
if (typeof destination === 'string') {
switch (destination) {
case 'SelfRegister':
case 'RegisterInvite':
navigation.navigate('RegistrationProviderExample', { screen: destination });
break;
default:
navigation.navigate(destination);
break;
}
} else if (destination === -1) {
navigation.goBack();
language={app.language}
i18n={i18nAppInstance}
navigate={(destination: -1 | string) => {
if (typeof destination === 'string') {
switch (destination) {
case 'SelfRegister':
case 'RegisterInvite':
navigation.navigate('RegistrationProviderExample', { screen: destination });
break;
default:
navigation.navigate(destination);
break;
}
}}
routeConfig={{
LOGIN: 'Login',
FORGOT_PASSWORD: 'ForgotPassword',
RESET_PASSWORD: 'ResetPassword',
REGISTER_INVITE: 'RegisterInvite',
REGISTER_SELF: 'SelfRegister',
SUPPORT: 'ContactSupport',
}}
>
<OktaRedirectLoginScreen
projectImage={
<Image
style={{ width: '100%' }}
resizeMode="contain"
source={require('../assets/images/eaton_stacked_logo.png')}
/>
}
// eslint-disable-next-line
oktaConfigObject={oktaConfig.oidc}
} else if (destination === -1) {
navigation.goBack();
}
}}
routeConfig={{
LOGIN: 'Login',
FORGOT_PASSWORD: 'ForgotPassword',
RESET_PASSWORD: 'ResetPassword',
REGISTER_INVITE: 'RegisterInvite',
REGISTER_SELF: 'SelfRegister',
SUPPORT: 'ContactSupport',
}}
>
<OktaRedirectLoginScreen
projectImage={
<Image
style={{ width: '100%' }}
resizeMode="contain"
source={require('../assets/images/eaton_stacked_logo.png')}
/>
}
// eslint-disable-next-line
oktaConfigObject={oktaConfig.oidc}
/>
</OktaAuthContextProvider>
</OktaAuthContextProvider>
);
};
4 changes: 1 addition & 3 deletions login-workflow/jestSetupFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ jest.mock('react-i18next', () => ({
...jest.requireActual('react-i18next'),
}));
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
jest.mock('@brightlayer-ui/react-native-components/node_modules/react-native-reanimated', () =>
require('react-native-reanimated/mock')
);

jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
jest.mock('react-native-webview', () => {
const { View } = require('react-native');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ describe('OktaRedirectLoginScreen', () => {
jest.clearAllMocks();
});


it('should call navigate with FORGOT_PASSWORD route when forgot password is clicked', () => {
render(<OktaRedirectLoginScreen />);
fireEvent.press(screen.getByText('bluiCommon:LABELS.FORGOT_PASSWORD'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ describe('OktaRedirectLoginScreenBase', () => {

test('calls handleContactSupport when contact support label is pressed', () => {
const handleContactSupport = jest.fn();
const { getByTestId } = render(<OktaRedirectLoginScreenBase showContactSupport={true} onContactSupport={handleContactSupport} />);
const { getByTestId } = render(
<OktaRedirectLoginScreenBase showContactSupport={true} onContactSupport={handleContactSupport} />
);
const contactSupportLabel = getByTestId('blui-okta-login-contact-support-label');
fireEvent.press(contactSupportLabel);
expect(handleContactSupport).toHaveBeenCalled();
Expand Down Expand Up @@ -108,4 +110,4 @@ describe('OktaRedirectLoginScreenBase', () => {
fireEvent.press(getByTestId('blui-okta-login-contact-support-label'));
expect(defaultProps.onContactSupport).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export const RegistrationWorkflow: React.FC<React.PropsWithChildren<Registration
initialPage={currentScreen ?? initialScreenIndex}
ref={viewPagerRef}
scrollEnabled={false}
collapsable={false}
key={viewPagerIndex}
onPageSelected={(e) => {
selectedPage.current = e.nativeEvent.position;
Expand All @@ -263,7 +264,9 @@ export const RegistrationWorkflow: React.FC<React.PropsWithChildren<Registration
}}
>
{screens.map((screen, index) => (
<View key={index + 1}>{screen}</View>
<View style={{ flex: 1 }} key={index + 1}>
{screen}
</View>
))}
</PagerView>
)}
Expand Down
2 changes: 1 addition & 1 deletion login-workflow/src/contexts/OktaAuthContext/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import { OktaAuthContextProviderProps } from './types';
/**
* Okta Auth Context is used to access context in the okta authentication workflow
*/
export const OktaAuthContext = createContext<OktaAuthContextProviderProps | null>(null);
export const OktaAuthContext = createContext<OktaAuthContextProviderProps | null>(null);
2 changes: 1 addition & 1 deletion login-workflow/src/contexts/OktaAuthContext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export const useOktaAuthContext = (): OktaAuthContextProviderProps => {

export type { OktaAuthContextProviderProps };

export { OktaAuthContext, OktaAuthContextProvider };
export { OktaAuthContext, OktaAuthContextProvider };
13 changes: 5 additions & 8 deletions login-workflow/src/contexts/OktaAuthContext/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import React, { useEffect } from 'react';
import { OktaAuthContextProviderProps } from './types';
import { OktaAuthContext } from './context';
Expand All @@ -9,9 +8,9 @@ import { SharedDictionaries } from '../SharedDictionaries';
import { ErrorManagerProps } from '../../components/Error/types';
import { i18nAuthInstance } from '../AuthContext/i18nAuthInstance';

const OktaAuthContextProviderContent: React.FC<
React.PropsWithChildren<Omit<OktaAuthContextProviderProps, 'i18n'>>
> = (props) => {
const OktaAuthContextProviderContent: React.FC<React.PropsWithChildren<Omit<OktaAuthContextProviderProps, 'i18n'>>> = (
props
) => {
const { children, errorConfig, ...oktaAuthContextProps } = props;
const { t } = useTranslation();
const mergedErrorConfig: ErrorManagerProps = {
Expand All @@ -32,9 +31,7 @@ const OktaAuthContextProviderContent: React.FC<
);
};

export const OktaAuthContextProvider: React.FC<
React.PropsWithChildren<OktaAuthContextProviderProps>
> = (props) => {
export const OktaAuthContextProvider: React.FC<React.PropsWithChildren<OktaAuthContextProviderProps>> = (props) => {
const i18nInstance = props.i18n ?? i18nAuthInstance;
const { language, i18n = i18nInstance, children, ...other } = props;

Expand Down Expand Up @@ -62,4 +59,4 @@ export const OktaAuthContextProvider: React.FC<
</OktaAuthContextProviderContent>
</I18nextProvider>
);
};
};
2 changes: 1 addition & 1 deletion login-workflow/src/contexts/OktaAuthContext/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export type OktaAuthContextProviderProps = {
* An error config for error context provider
*/
errorConfig?: ErrorContextProviderProps;
};
};
2 changes: 1 addition & 1 deletion login-workflow/src/contexts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export * from './RegistrationContext';
export * from './SharedDictionaries';
export * from './ErrorContext';
export * from './AuthContext';
export * from './OktaAuthContext';
export * from './OktaAuthContext';
2 changes: 1 addition & 1 deletion login-workflow/src/screens/LoginScreen/LoginScreenBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export const LoginScreenBase: React.FC<React.PropsWithChildren<LoginScreenProps>
testID={'blui-login-cyber-security-badge-wrapper'}
>
<Image
style={{...cyberSecurityBadgeSize}}
style={{ ...cyberSecurityBadgeSize }}
resizeMode="contain"
source={require('../../assets/images/cybersecurity_certified.png')}
/>
Expand Down
2 changes: 1 addition & 1 deletion login-workflow/src/screens/LoginScreen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ export type LoginScreenProps = WorkflowCardBaseProps & {
/**
* The size of the cyber security image
*/
cyberSecurityBadgeSize?: {height?: number | string, width?: number | string};
cyberSecurityBadgeSize?: { height?: number | string; width?: number | string };
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const OktaRedirectLoginScreen: React.FC<React.PropsWithChildren<OktaLogin
void createOktaConfig();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<OktaRedirectLoginScreenBase
loginButtonLabel={loginButtonLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ export const OktaRedirectLoginScreenBase: React.FC<React.PropsWithChildren<OktaL
{projectImage}
</View>

<View
style={[defaultStyles.loginButtonWrapper, { width: '100%' }]}
testID={'blui-okta-login-login-button-wrapper'}
<View
style={[defaultStyles.loginButtonWrapper, { width: '100%' }]}
testID={'blui-okta-login-login-button-wrapper'}
>
<Button
testID={'blui-okta-login-login-button'}
onPress={handleLogin}
disabled={!onLogin}
mode="contained"
style={defaultStyles.loginButton}
>
<Button
testID={'blui-okta-login-login-button'}
onPress={handleLogin}
disabled={!onLogin}
mode="contained"
style={defaultStyles.loginButton}
>
{loginButtonLabel || 'Sign In with Okta'}
</Button>
</View>
{loginButtonLabel || 'Sign In with Okta'}
</Button>
</View>

<View style={defaultStyles.bottomBodyWrapper} testID={'blui-okta-login-bottom-body-wrapper'}>
{showForgotPassword && (
Expand Down Expand Up @@ -214,7 +214,9 @@ export const OktaRedirectLoginScreenBase: React.FC<React.PropsWithChildren<OktaL
</View>
)}

<View testID={'blui-okta-login-footer'} style={defaultStyles.footerWrapper}>{footer}</View>
<View testID={'blui-okta-login-footer'} style={defaultStyles.footerWrapper}>
{footer}
</View>

{showCyberSecurityBadge && (
<View
Expand Down
9 changes: 8 additions & 1 deletion login-workflow/src/screens/OktaRedirectLoginScreen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,12 @@ export type OktaLoginScreenProps = WorkflowCardBaseProps & {
/**
* oktaConfigObject is an object containing configuration settings required for integrating with Okta.
*/
oktaConfigObject?: {clientId: string; redirectUri: string; endSessionRedirectUri: string; discoveryUri: string; scopes: string[]; requireHardwareBackedKeyStore: boolean}
oktaConfigObject?: {
clientId: string;
redirectUri: string;
endSessionRedirectUri: string;
discoveryUri: string;
scopes: string[];
requireHardwareBackedKeyStore: boolean;
};
};
Loading

0 comments on commit 2bc5f57

Please sign in to comment.