mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-16 13:21:57 +00:00
UBER-639 Sign Up flow from the app (#3580)
Signed-off-by: Maxim Karmatskikh <mkarmatskih@gmail.com>
This commit is contained in:
parent
16d079bb88
commit
659f3dcd40
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user