-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02ef79e
commit e836ee1
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/clerk-js/src/ui/components/PendingTask/PendingTask.tsx
This file contains 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,50 @@ | ||
import { useSessionContext } from '@clerk/shared/react/index'; | ||
import type { SessionTasks } from '@clerk/types'; | ||
import type { ComponentType } from 'react'; | ||
import { withRedirectToAfterSignIn } from 'ui/common'; | ||
|
||
import { Route } from '../../../ui/router'; | ||
import { OrganizationList } from '../OrganizationList'; | ||
|
||
const paths: Record<keyof SessionTasks, string> = { | ||
orgs: 'select-organization', | ||
}; | ||
|
||
const TaskRegistry: Record<keyof SessionTasks, ComponentType> = { | ||
orgs: OrganizationList, | ||
}; | ||
|
||
function usePendingTask() { | ||
const session = useSessionContext(); | ||
|
||
if (!session) { | ||
return null; | ||
} | ||
|
||
const [pendingTask] = Object.entries(session.tasks ?? {}).map(([task, value]) => ({ | ||
task, | ||
...value, | ||
})); | ||
|
||
return pendingTask; | ||
} | ||
|
||
export function _PendingTask() { | ||
const pendingTask = usePendingTask(); | ||
|
||
if (!pendingTask) { | ||
return null; | ||
} | ||
|
||
const Task = TaskRegistry['orgs']; | ||
// @ts-ignore | ||
const path = paths[pendingTask.task]; | ||
|
||
return ( | ||
<Route path={path}> | ||
<Task /> | ||
</Route> | ||
); | ||
} | ||
|
||
export const PendingTask = withRedirectToAfterSignIn(_PendingTask); |
This file contains 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 @@ | ||
export * from './PendingTask'; |
This file contains 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 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