@@ -6,27 +6,25 @@ import { useCallback, useContext, useEffect } from 'react';
6
6
import { SESSION_TASK_ROUTE_BY_KEY } from '../../../core/sessionTasks' ;
7
7
import { OrganizationListContext , SignInContext , SignUpContext } from '../../../ui/contexts' ;
8
8
import { Card , LoadingCardContainer , withCardStateProvider } from '../../../ui/elements' ;
9
- import { SessionTasksContext as SessionTasksContext } from '../../contexts/components/SessionTasks' ;
9
+ import {
10
+ SessionTasksContext as SessionTasksContext ,
11
+ useSessionTasksContext ,
12
+ } from '../../contexts/components/SessionTasks' ;
10
13
import { Route , Switch , useRouter } from '../../router' ;
11
14
import { OrganizationList } from '../OrganizationList' ;
12
15
13
16
const SessionTasksStart = withCardStateProvider ( ( ) => {
14
17
const clerk = useClerk ( ) ;
15
18
const { navigate } = useRouter ( ) ;
19
+ const { redirectUrlComplete } = useSessionTasksContext ( ) ;
16
20
17
21
useEffect ( ( ) => {
22
+ // Simulates additional latency to avoid a abrupt UI transition when navigating to the next task
18
23
const timeoutId = setTimeout ( ( ) => {
19
- void clerk . session ?. reload ( ) . then ( session => {
20
- if ( ! session . currentTask ?. key ) {
21
- void navigate ( clerk . buildAfterSignInUrl ( ) ) ;
22
- return ;
23
- }
24
-
25
- void navigate ( SESSION_TASK_ROUTE_BY_KEY [ session . currentTask ?. key ] ) ;
26
- } ) ;
27
- } , 1000 ) ;
24
+ void clerk . __experimental_nextTask ( { redirectUrlComplete } ) ;
25
+ } , 500 ) ;
28
26
return ( ) => clearTimeout ( timeoutId ) ;
29
- } , [ navigate , clerk ] ) ;
27
+ } , [ navigate , clerk , redirectUrlComplete ] ) ;
30
28
31
29
return (
32
30
< Card . Root >
@@ -82,12 +80,12 @@ export function SessionTask(): JSX.Element {
82
80
} , [ clerk , navigate , redirectUrlComplete ] ) ;
83
81
84
82
const nextTask = useCallback (
85
- ( ) => clerk . __experimental_nextTask ( { redirectUrlComplete : redirectUrlComplete } ) ,
83
+ ( ) => clerk . __experimental_nextTask ( { redirectUrlComplete } ) ,
86
84
[ clerk , redirectUrlComplete ] ,
87
85
) ;
88
86
89
87
return (
90
- < SessionTasksContext . Provider value = { { nextTask } } >
88
+ < SessionTasksContext . Provider value = { { nextTask, redirectUrlComplete } } >
91
89
< SessionTaskRoutes />
92
90
</ SessionTasksContext . Provider >
93
91
) ;
0 commit comments