diff --git a/src/index.ts b/src/index.ts index 686fa5e..99fcef8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); + } }); diff --git a/src/screens/Login/index.tsx b/src/screens/Login/index.tsx new file mode 100644 index 0000000..3304324 --- /dev/null +++ b/src/screens/Login/index.tsx @@ -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 ( + + + Beda EMR + + + + + + ); +} diff --git a/src/screens/Login/navigation.ts b/src/screens/Login/navigation.ts new file mode 100644 index 0000000..448f3b4 --- /dev/null +++ b/src/screens/Login/navigation.ts @@ -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, + }, + }, +}; diff --git a/src/screens/Login/styles.ts b/src/screens/Login/styles.ts new file mode 100644 index 0000000..32467e3 --- /dev/null +++ b/src/screens/Login/styles.ts @@ -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, + }, +}); diff --git a/src/screens/navigation.ts b/src/screens/navigation.ts new file mode 100644 index 0000000..ac038ec --- /dev/null +++ b/src/screens/navigation.ts @@ -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, + }, + }, + }, + }, +}; diff --git a/src/services/auth.ts b/src/services/auth.ts index a1aedc6..effbc77 100644 --- a/src/services/auth.ts +++ b/src/services/auth.ts @@ -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'; @@ -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) { @@ -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;