From 659f3dcd40e7191d772ac6508b3c0ad83fb7086f Mon Sep 17 00:00:00 2001 From: Maksim Karmatskikh Date: Fri, 11 Aug 2023 13:22:15 +0600 Subject: [PATCH] UBER-639 Sign Up flow from the app (#3580) Signed-off-by: Maxim Karmatskikh --- .../src/components/Confirmation.svelte | 24 +++++++++--- .../src/components/ConfirmationSend.svelte | 25 +++++++++++- .../src/components/SelectWorkspace.svelte | 38 ++++++++++++++++--- 3 files changed, 76 insertions(+), 11 deletions(-) diff --git a/plugins/login-resources/src/components/Confirmation.svelte b/plugins/login-resources/src/components/Confirmation.svelte index 0677133dee..eacadcb8e0 100644 --- a/plugins/login-resources/src/components/Confirmation.svelte +++ b/plugins/login-resources/src/components/Confirmation.svelte @@ -23,6 +23,22 @@ let status: Status = OK + function goToWorkspaces () { + const loc = getCurrentLocation() + loc.query = undefined + loc.path[1] = 'selectWorkspace' + loc.path.length = 2 + navigate(loc) + } + + function goToLogin () { + const loc = getCurrentLocation() + loc.query = undefined + loc.path[1] = 'login' + loc.path.length = 2 + navigate(loc) + } + async function check () { const location = getCurrentLocation() if (location.query?.id === undefined || location.query?.id === null) return @@ -36,11 +52,9 @@ setMetadata(presentation.metadata.Token, result.token) setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint) setMetadataLocalStorage(login.metadata.LoginEmail, result.email) - const loc = getCurrentLocation() - loc.query = undefined - loc.path[1] = 'selectWorkspace' - loc.path.length = 2 - navigate(loc) + goToWorkspaces() + } else { + goToLogin() } } diff --git a/plugins/login-resources/src/components/ConfirmationSend.svelte b/plugins/login-resources/src/components/ConfirmationSend.svelte index cb1a48215c..c793e52036 100644 --- a/plugins/login-resources/src/components/ConfirmationSend.svelte +++ b/plugins/login-resources/src/components/ConfirmationSend.svelte @@ -18,7 +18,9 @@ import { getAccount } from '../utils' import { onMount } from 'svelte' - onMount(async () => { + const CHECK_INTERVAL = 1000 + + async function checkAccountStatus () { const account = await getAccount() if (account?.confirmed === true) { const loc = getCurrentLocation() @@ -26,6 +28,27 @@ loc.path.length = 2 navigate(loc) } + } + + let weAreHere = false + + async function check () { + try { + await checkAccountStatus() + } catch (e) { + // we should be able to continue from this state + } + if (weAreHere) { + setTimeout(check, CHECK_INTERVAL) + } + } + + onMount(() => { + weAreHere = true + check() + return () => { + weAreHere = false + } }) diff --git a/plugins/login-resources/src/components/SelectWorkspace.svelte b/plugins/login-resources/src/components/SelectWorkspace.svelte index 7dfffe2a09..b0137f4b0e 100644 --- a/plugins/login-resources/src/components/SelectWorkspace.svelte +++ b/plugins/login-resources/src/components/SelectWorkspace.svelte @@ -31,13 +31,38 @@ import { LoginInfo, Workspace } from '@hcengineering/login' import { onMount } from 'svelte' + const CHECK_INTERVAL = 1000 + export let navigateUrl: string | undefined = undefined + let workspaces: Workspace[] = [] + let flagToUpdateWorkspaces = false let status = OK let account: LoginInfo | undefined = undefined - onMount(async () => (account = await getAccount())) + async function loadAccount () { + account = await getAccount() + } + + async function updateWorkspaces () { + try { + workspaces = await getWorkspaces() + } catch (e) { + // we should be able to continue from this state + } + if (flagToUpdateWorkspaces) { + setTimeout(updateWorkspaces, CHECK_INTERVAL) + } + } + + onMount(() => { + loadAccount() + + return () => { + flagToUpdateWorkspaces = false + } + }) async function select (workspace: string) { status = new Status(Severity.INFO, login.status.ConnectingToServer, {}) @@ -48,17 +73,20 @@ navigateToWorkspace(workspace, result, navigateUrl) } - async function _getWorkspaces (): Promise { + async function _getWorkspaces () { try { const res = await getWorkspaces() + if (res.length === 0 && account?.confirmed === false) { const loc = getCurrentLocation() loc.path[1] = 'confirmationSend' loc.path.length = 2 navigate(loc) - return [] } - return res + + workspaces = res + flagToUpdateWorkspaces = true + updateWorkspaces() } catch (err: any) { setMetadataLocalStorage(presentation.metadata.Token, null) setMetadataLocalStorage(login.metadata.LoginEndpoint, null) @@ -89,7 +117,7 @@
- {#await _getWorkspaces() then workspaces} + {#await _getWorkspaces() then}
{#each workspaces as workspace}