forked from Ivasoft/mattermost-mobile
initial logic for showing/not showing the onboarding
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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<OnboardingItem>) => {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user