UBER-639 Sign Up flow from the app (#3580)

Signed-off-by: Maxim Karmatskikh <mkarmatskih@gmail.com>
This commit is contained in:
Maksim Karmatskikh 2023-08-11 13:22:15 +06:00 committed by GitHub
parent 16d079bb88
commit 659f3dcd40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 11 deletions

View File

@ -23,6 +23,22 @@
let status: Status<any> = 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()
}
}

View File

@ -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
}
})
</script>

View File

@ -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<Workspace[]> {
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 @@
<div class="status">
<StatusControl {status} />
</div>
{#await _getWorkspaces() then workspaces}
{#await _getWorkspaces() then}
<Scroller padding={'.125rem 0'}>
<div class="form">
{#each workspaces as workspace}