Skip to content

Commit

Permalink
Merge pull request #457 from etn-ccis/feat/create-example-app
Browse files Browse the repository at this point in the history
Feat/create example app
  • Loading branch information
ektaghag-eaton authored Apr 26, 2024
2 parents c9aa09f + f6e6dc0 commit 392711f
Show file tree
Hide file tree
Showing 24 changed files with 630 additions and 621 deletions.
9 changes: 5 additions & 4 deletions login-workflow/example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage';

export const App = (): JSX.Element => {
const [theme, setTheme] = useState<ThemeType>('light');
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [language, setLanguage] = useState('en');
const [isAuthenticated, setAuthenticated] = useState<AppContextType['isAuthenticated']>(false);
const [loginData, setLoginData] = useState<AppContextType['loginData']>({
email: '',
rememberMe: false,
Expand All @@ -46,7 +46,7 @@ export const App = (): JSX.Element => {
try {
const userData = await LocalStorage.readAuthData();
setLoginData({ email: userData.rememberMeData.user, rememberMe: userData.rememberMeData.rememberMe });
setIsAuthenticated(Boolean(userData.userId));
setAuthenticated(Boolean(userData.userId));
await getLanguage();
} catch (e) {
// handle any error state, rejected promises, etc..
Expand All @@ -68,17 +68,18 @@ export const App = (): JSX.Element => {
value={{
isAuthenticated,
onUserAuthenticated: (userData): void => {
setIsAuthenticated(true);
setAuthenticated(true);
setLoginData(userData);
},
// eslint-disable-next-line
onUserNotAuthenticated: (userData): void => {
setIsAuthenticated(false);
setAuthenticated(false);
},
loginData,
setLoginData,
language,
setLanguage,
setAuthenticated,
}}
>
<ThemeProvider theme={theme === 'light' ? blue : blueDark}>
Expand Down
12 changes: 6 additions & 6 deletions login-workflow/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1376,9 +1376,9 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
boost: d211fef46701a9df276bef51f7e86992e22929eb
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: b50f832cfe4030d3500ef82f095f609c8c0668f3
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
FBLazyVector: fbc4957d9aa695250b55d879c1d86f79d7e69ab4
FBReactNativeSpec: 86de768f89901ef6ed3207cd686362189d64ac88
Flipper: c7a0093234c4bdd456e363f2f19b2e4b27652d44
Expand All @@ -1390,11 +1390,11 @@ SPEC CHECKSUMS:
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
FlipperKit: 37525a5d056ef9b93d1578e04bc3ea1de940094f
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: e519f94633ae20b610529d26c963d713c678b0b6
hermes-engine: ef490160118aea4fd2ee0a625a388642c204d901
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: b361c9ef5ef3cda53f66e195599b47e1f84ffa35
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
RCT-Folly: e6540a6bc74fdcd89a210fcb7775d50ef41b301b
RCT-Folly: 7169b2b1c44399c76a47b5deaaba715eeeb476c0
RCTRequired: 9b1e7e262745fb671e33c51c1078d093bd30e322
RCTTypeSafety: a759e3b086eccf3e2cbf2493d22f28e082f958e6
React: 805f5dd55bbdb92c36b4914c64aaae4c97d358dc
Expand Down Expand Up @@ -1452,4 +1452,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 0102c6fabdf4b18c8262ef30a5501363fc491918

COCOAPODS: 1.15.2
COCOAPODS: 1.14.3
12 changes: 2 additions & 10 deletions login-workflow/example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,7 @@
"-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down Expand Up @@ -688,11 +684,7 @@
"-DFOLLY_USE_LIBCPP=1",
"-DFOLLY_CFG_NO_COROUTINES=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
OTHER_LDFLAGS = "$(inherited)";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
49 changes: 49 additions & 0 deletions login-workflow/example/src/components/DebugComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Spacer } from '@brightlayer-ui/react-native-components';
import { useNavigation } from '@react-navigation/native';
import React, { useState } from 'react';
import { View } from 'react-native';
import { Button, Text } from 'react-native-paper';

export const DebugComponent = (): JSX.Element => {
const [debugMode, setDebugMode] = useState(false);
const navigation = useNavigation();
return (
<>
<View style={{ flexDirection: 'row' }}>
{debugMode && <Text variant="headlineSmall">DEBUG MODE</Text>}
<Spacer />
<Button
mode="contained"
onPress={(): void => {
setDebugMode(!debugMode);
}}
>
DEBUG
</Button>
</View>
{debugMode && (
<View style={{ paddingBottom: 2 }}>
<Button
mode={'text'}
labelStyle={{ fontSize: 16 }}
uppercase={false}
onPress={(): void => {
navigation.navigate('RegistrationProviderExample', { screen: 'RegisterInvite' });
}}
>
[Test Invite Register]
</Button>

<Button
mode={'text'}
labelStyle={{ fontSize: 16 }}
uppercase={false}
onPress={(): void => navigation.navigate('ResetPassword')}
>
[Test Reset Password]
</Button>
</View>
)}
</>
);
};
23 changes: 20 additions & 3 deletions login-workflow/example/src/components/UserMenuExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { useTranslation } from 'react-i18next';
import { useExtendedTheme } from '@brightlayer-ui/react-native-themes';
import { useApp } from '../contexts/AppContextProvider';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { LocalStorage } from '../store/local-storage';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';

const SwapIcon: IconFamily = {
family: 'material',
Expand All @@ -19,9 +22,14 @@ const InvertColorsIcon: IconFamily = {
name: 'invert-colors',
direction: 'ltr',
};
const CancelIcon: IconFamily = {
const ExitToAppIcon: IconFamily = {
family: 'material',
name: 'cancel',
name: 'exit-to-app',
direction: 'ltr',
};
const LockIcon: IconFamily = {
family: 'material',
name: 'lock',
direction: 'ltr',
};

Expand All @@ -34,6 +42,7 @@ export const UserMenuExample: React.FC<UserMenuExampleProps> = (props) => {
const { onToggleRTL, onToggleTheme } = props;
const theme = useExtendedTheme();
const { i18n } = useTranslation();
const navigation = useNavigation<NativeStackNavigationProp<any>>();
const app = useApp();
const handleLanguageChange = async (newLanguage: string): Promise<any> => {
app.setLanguage(newLanguage);
Expand All @@ -45,6 +54,13 @@ export const UserMenuExample: React.FC<UserMenuExampleProps> = (props) => {
console.error('Error setting new language:', error);
}
};
const logout = (): void => {
LocalStorage.clearAuthCredentials();
app.onUserNotAuthenticated();
};
const changePassword = (): void => {
navigation.navigate('ChangePassword');
};
const languageOptions = [
{ label: 'English', value: 'en' },
{ label: 'Spanish', value: 'es' },
Expand Down Expand Up @@ -79,7 +95,8 @@ export const UserMenuExample: React.FC<UserMenuExampleProps> = (props) => {
/>
),
},
{ title: 'Cancel', icon: CancelIcon },
{ title: 'Change Password', icon: LockIcon, onPress: (): void => changePassword() },
{ title: 'Logout', icon: ExitToAppIcon, onPress: (): void => logout() },
];

return (
Expand Down
1 change: 1 addition & 0 deletions login-workflow/example/src/contexts/AppContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type AppContextType = {
language: string;
setLanguage: (language: string) => void;
setLoginData: (args: LoginData) => void;
setAuthenticated: (isAuthenticated: boolean) => void;
};

export const AppContext = createContext<AppContextType | null>(null);
Expand Down
Loading

0 comments on commit 392711f

Please sign in to comment.