Skip to content

Commit

Permalink
Add login screen
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryashutov committed Nov 21, 2023
1 parent a1c9864 commit 981da0b
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import { Navigation } from 'react-native-navigation';
import { Notifications } from 'react-native-notifications';

import { navigationLayout } from 'screens/ActivityFeed/navigation';
import { attachActivityHistoryDataStream } from 'services/datastream';
import { setupSentryErrorTracking } from 'services/sentry';
import { restoreApplicationState } from 'models';
import { preloadIconsLibraryRegistry } from 'styles/icons-library';
import { loginRoot } from 'screens/Login/navigation';
import { getUserIdentity } from 'services/auth';
import { mainRoot } from 'screens/navigation';

setupSentryErrorTracking();
preloadIconsLibraryRegistry();

Navigation.events().registerAppLaunchedListener(async () => {
await restoreApplicationState();
const identity = await getUserIdentity();

Notifications.registerRemoteNotifications();
Navigation.setRoot({
root: {
bottomTabs: {
id: 'FHIRmHealth',
children: [navigationLayout({})],
options: {
bottomTabs: {
visible: false,
},
},
},
},
});

attachActivityHistoryDataStream();
if (identity) {
Navigation.setRoot(mainRoot);
attachActivityHistoryDataStream();
} else {
Navigation.setRoot(loginRoot);
}
});
18 changes: 18 additions & 0 deletions src/screens/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { View, Text } from 'react-native';

import s from './styles';
import { AuthButton } from 'components/AuthButton';

export function Login() {
return (
<View style={s.container}>
<View style={s.logoContainer}>
<Text style={s.logoText}>Beda EMR</Text>
</View>
<View style={s.buttonContainer}>
<AuthButton />
</View>
</View>
);
}
15 changes: 15 additions & 0 deletions src/screens/Login/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Navigation, LayoutRoot } from 'react-native-navigation';

import { Login } from '.';

export const componentName = 'software.beda.fhirmhealth.screens.Login';

Navigation.registerComponent(componentName, () => Login);

export const loginRoot: LayoutRoot = {
root: {
component: {
name: componentName,
},
},
};
25 changes: 25 additions & 0 deletions src/screens/Login/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { StyleSheet } from 'react-native';
import { palette } from 'styles/theme';

export default StyleSheet.create({
container: {
flex: 1,
backgroundColor: palette.primary.color,
alignItems: 'center',
},
logoContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
logoText: {
fontWeight: 'bold',
fontSize: 38,
lineHeight: 40,
color: palette.secondary.color,
},
buttonContainer: {
marginBottom: 50,
paddingHorizontal: 16,
},
});
16 changes: 16 additions & 0 deletions src/screens/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LayoutRoot } from 'react-native-navigation';
import { navigationLayout } from './ActivityFeed/navigation';

export const mainRoot: LayoutRoot = {
root: {
bottomTabs: {
id: 'FHIRmHealth',
children: [navigationLayout({})],
options: {
bottomTabs: {
visible: false,
},
},
},
},
};
6 changes: 6 additions & 0 deletions src/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { stateTree } from 'models';
import { KeychainStorage } from 'services/storage';
import { signinEMRPatient } from 'services/emr';
import { isSuccess } from 'fhir-react/src/libs/remoteData';
import { Navigation } from 'react-native-navigation';
import { mainRoot } from 'screens/navigation';
import { loginRoot } from 'screens/Login/navigation';

const AUTH_IDENTITY_KEYCHAIN_PATH = 'apple_identity';

Expand Down Expand Up @@ -37,6 +40,7 @@ export async function getUserIdentity() {
export async function signout() {
await KeychainStorage.remove(AUTH_IDENTITY_KEYCHAIN_PATH);
stateTree.user.switchPatient(undefined);
Navigation.setRoot(loginRoot);
}

export async function signin(authenticated: AuthenticatedAppleResponse) {
Expand All @@ -56,10 +60,12 @@ export async function signin(authenticated: AuthenticatedAppleResponse) {

export async function signinWithApple() {
const authentication = await openAppleAuthenticationDialog();

if (authentication.status === AuthStatus.Authenticated) {
const response = await signin(authentication);
if (isSuccess(response)) {
stateTree.user.switchPatient(response.data);
Navigation.setRoot(mainRoot);
}
}
return authentication;
Expand Down

0 comments on commit 981da0b

Please sign in to comment.