From 46b66a5baf748b3ffaf4d016797d3ff0dbf32e14 Mon Sep 17 00:00:00 2001 From: Pablo Velez Vidal Date: Wed, 9 Nov 2022 22:47:26 +0100 Subject: [PATCH] initial logic for showing/not showing the onboarding --- app/init/launch.ts | 28 +++++++++++++- app/screens/navigation.ts | 3 +- app/screens/onboarding/index.tsx | 64 ++++++++++++++++++++++++++++++-- 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/app/init/launch.ts b/app/init/launch.ts index 54a0ef6750..52326aa13e 100644 --- a/app/init/launch.ts +++ b/app/init/launch.ts @@ -19,6 +19,7 @@ import {convertToNotificationData} from '@utils/notification'; import {parseDeepLink} from '@utils/url'; import type {DeepLinkChannel, DeepLinkDM, DeepLinkGM, DeepLinkPermalink, DeepLinkWithData, LaunchProps} from '@typings/launch'; +import { fetchConfigAndLicense } from '@actions/remote/systems'; const initialNotificationTypes = [PushNotification.NOTIFICATION_TYPE.MESSAGE, PushNotification.NOTIFICATION_TYPE.SESSION]; @@ -98,6 +99,14 @@ const launchApp = async (props: LaunchProps, resetNavigation = true) => { hasCurrentUser = Boolean(currentUserId); } + // if (!onboardingAlreadyShown) { + // here, check if there is not an active session and redirect to onboarding with a flag, so the sign in button will + // redirect to the sign in + // return launchToOnboarding(props, goToLoginPage); + // } + + return launchToOnboarding(props, resetNavigation, false, false, true, serverUrl); + let launchType = props.launchType; if (!hasCurrentUser) { // migrating from v1 @@ -127,6 +136,10 @@ const launchApp = async (props: LaunchProps, resetNavigation = true) => { } } + // if (onboardingAlreadyShown) { + // // launchToServer(props, resetNavigation); + // } + return launchToOnboarding(props, resetNavigation); }; @@ -181,11 +194,22 @@ const launchToServer = (props: LaunchProps, resetNavigation: Boolean) => { return goToScreen(Screens.SERVER, title, {...props}); }; -const launchToOnboarding = (props: LaunchProps, resetNavigation = true) => { +const launchToOnboarding = ( + props: LaunchProps, + resetNavigation = true, + notActiveSession = true, + whiteLabeledApp = false, + goToLogIn = true, + serverUrl = '', +) => { + // here, if there is an active session, redirect to home + // if there is a whitelabeled app, redirect to either SERVER or LOGIN but don't show the onboarding if (resetNavigation) { launchToServer(props, resetNavigation); } - return resetToOnboarding(props); + + // if there is not an active session, pass the prop and redirect to the LOGIN page (keep in mind all the redirection login to check for SSO stuff) + return resetToOnboarding(props, goToLogIn); }; export const relaunchApp = (props: LaunchProps, resetNavigation = false) => { diff --git a/app/screens/navigation.ts b/app/screens/navigation.ts index b985754207..2bb7cd916d 100644 --- a/app/screens/navigation.ts +++ b/app/screens/navigation.ts @@ -281,7 +281,7 @@ export function resetToSelectServer(passProps: LaunchProps) { }); } -export function resetToOnboarding(passProps: LaunchProps) { +export function resetToOnboarding(passProps: LaunchProps, goToLogIn: boolean) { const theme = getDefaultThemeByAppearance(); const isDark = tinyColor(theme.sidebarBg).isDark(); StatusBar.setBarStyle(isDark ? 'light-content' : 'dark-content'); @@ -295,6 +295,7 @@ export function resetToOnboarding(passProps: LaunchProps) { passProps: { ...passProps, theme, + goToLogIn, }, options: { layout: { diff --git a/app/screens/onboarding/index.tsx b/app/screens/onboarding/index.tsx index 089cd31978..a1611ede43 100644 --- a/app/screens/onboarding/index.tsx +++ b/app/screens/onboarding/index.tsx @@ -7,7 +7,7 @@ import Animated, {Easing, useAnimatedRef, useAnimatedScrollHandler, useDerivedVa import {Screens} from '@app/constants'; import Background from '@screens/background'; -import {goToScreen} from '@screens/navigation'; +import {goToScreen, loginAnimationOptions} from '@screens/navigation'; import {makeStyleSheetFromTheme} from '@utils/theme'; import FooterButtons from './footer_buttons'; @@ -16,15 +16,22 @@ import SlideItem from './slide'; import useSlidesData, {OnboardingItem} from './slides_data'; import type {LaunchProps} from '@typings/launch'; +import { loginOptions } from '@app/utils/server'; +import { fetchConfigAndLicense } from '@actions/remote/systems'; +import { queryServerByIdentifier } from '@app/queries/app/servers'; interface OnboardingProps extends LaunchProps { theme: Theme; + goToLogIn: boolean; + serverUrl: string; } const AnimatedSafeArea = Animated.createAnimatedComponent(SafeAreaView); const Onboarding = ({ theme, + goToLogIn, + serverUrl, }: OnboardingProps) => { const {width} = useWindowDimensions(); const styles = getStyleSheet(theme); @@ -65,9 +72,60 @@ const Onboarding = ({ } }, [currentIndex.value, slidesRef.current, moveToSlide]); + const initLogin = async () => { + const data = await fetchConfigAndLicense(serverUrl, true); + if (data.error) { + console.log('Error getting the config and license information'); + return; + } + + displayLogin(data.config!, data.license!); + }; + + const displayLogin = (config: ClientConfig, license: ClientLicense) => { + const {enabledSSOs, hasLoginForm, numberSSOs, ssoOptions} = loginOptions(config, license); + const passProps = { + config, + extra, + hasLoginForm, + launchError, + launchType, + license, + serverDisplayName: displayName, + serverUrl, + ssoOptions, + theme, + }; + + const redirectSSO = !hasLoginForm && numberSSOs === 1; + const screen = redirectSSO ? Screens.SSO : Screens.LOGIN; + if (redirectSSO) { + // @ts-expect-error ssoType not in definition + passProps.ssoType = enabledSSOs[0]; + } + + goToScreen(screen, '', passProps, loginAnimationOptions()); + }; + const signInHandler = useCallback(() => { - goToScreen(Screens.SERVER, '', {theme}); - }, []); + if (goToLogIn) { + initLogin(); + } + const topBar = { + visible: true, + drawBehind: true, + noBorder: true, + elevation: 0, + background: { + color: 'transparent', + }, + backButton: { + color: theme.centerChannelColor, + title: '', + }, + }; + goToScreen(Screens.SERVER, '', {theme}, {topBar}); + }, [goToLogIn]); const renderSlide = useCallback(({item, index}: ListRenderItemInfo) => { return (