-
Notifications
You must be signed in to change notification settings - Fork 361
chore(clerk-js,types): Load tasks based on environment settings #5422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9fc30a8
Remove `experimental` flag with routing refactoring
LauraBeatris cd1f130
Extract tasks under `/tasks` root path
LauraBeatris 0ca95f9
Introduce bundle on `bundlewatch`
LauraBeatris 4abb96d
Introduce root route to resolve tasks
LauraBeatris 6e7d003
Add changeset
LauraBeatris 3f7f80b
Rename `SessionTasks` imports to `LazySessionTasks`
LauraBeatris d772acf
Update bundle max size
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Load tasks based on environment settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 0 additions & 58 deletions
58
packages/clerk-js/src/ui/components/SessionTask/SessionTask.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
packages/clerk-js/src/ui/components/SessionTasks/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useClerk } from '@clerk/shared/react'; | ||
import { eventComponentMounted } from '@clerk/shared/telemetry'; | ||
import type { SessionTask } from '@clerk/types'; | ||
import { useCallback, useContext, useEffect } from 'react'; | ||
|
||
import { SESSION_TASK_ROUTE_BY_KEY } from '../../../core/sessionTasks'; | ||
import { OrganizationListContext, SignInContext, SignUpContext } from '../../../ui/contexts'; | ||
import { Card, LoadingCardContainer, withCardStateProvider } from '../../../ui/elements'; | ||
import { | ||
SessionTasksContext as SessionTasksContext, | ||
useSessionTasksContext, | ||
} from '../../contexts/components/SessionTasks'; | ||
import { Route, Switch, useRouter } from '../../router'; | ||
import { OrganizationList } from '../OrganizationList'; | ||
|
||
const SessionTasksStart = withCardStateProvider(() => { | ||
const clerk = useClerk(); | ||
const { navigate } = useRouter(); | ||
const { redirectUrlComplete } = useSessionTasksContext(); | ||
|
||
useEffect(() => { | ||
// Simulates additional latency to avoid a abrupt UI transition when navigating to the next task | ||
const timeoutId = setTimeout(() => { | ||
void clerk.__experimental_nextTask({ redirectUrlComplete }); | ||
}, 500); | ||
return () => clearTimeout(timeoutId); | ||
}, [navigate, clerk, redirectUrlComplete]); | ||
|
||
return ( | ||
<Card.Root> | ||
<Card.Content> | ||
<LoadingCardContainer /> | ||
</Card.Content> | ||
<Card.Footer /> | ||
</Card.Root> | ||
); | ||
}); | ||
|
||
function SessionTaskRoutes(): JSX.Element { | ||
return ( | ||
<Switch> | ||
<Route path={SESSION_TASK_ROUTE_BY_KEY['org']}> | ||
<OrganizationListContext.Provider | ||
value={{ | ||
componentName: 'OrganizationList', | ||
skipInvitationScreen: true, | ||
}} | ||
> | ||
<OrganizationList /> | ||
</OrganizationListContext.Provider> | ||
</Route> | ||
<Route index> | ||
<SessionTasksStart /> | ||
</Route> | ||
</Switch> | ||
); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function SessionTask(): JSX.Element { | ||
const clerk = useClerk(); | ||
const { navigate } = useRouter(); | ||
const signInContext = useContext(SignInContext); | ||
const signUpContext = useContext(SignUpContext); | ||
|
||
const redirectUrlComplete = | ||
signInContext?.afterSignInUrl ?? signUpContext?.afterSignUpUrl ?? clerk?.buildAfterSignInUrl(); | ||
LauraBeatris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
useEffect(() => { | ||
const task = clerk.session?.currentTask; | ||
|
||
if (!task) { | ||
void navigate(redirectUrlComplete); | ||
return; | ||
} | ||
|
||
clerk.telemetry?.record(eventComponentMounted('SessionTask', { task: task.key })); | ||
}, [clerk, navigate, redirectUrlComplete]); | ||
|
||
const nextTask = useCallback( | ||
() => clerk.__experimental_nextTask({ redirectUrlComplete }), | ||
[clerk, redirectUrlComplete], | ||
); | ||
|
||
return ( | ||
<SessionTasksContext.Provider value={{ nextTask, redirectUrlComplete }}> | ||
<SessionTaskRoutes /> | ||
</SessionTasksContext.Provider> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.