-
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
573b5d5
commit a1c1c39
Showing
13 changed files
with
78 additions
and
35 deletions.
There are no files selected for viewing
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
Empty file.
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,8 @@ | ||
import type { SessionTask } from '@clerk/types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const sessionTaskRoutePaths: Record<SessionTask['key'], string> = { | ||
org: 'select-organization', | ||
}; |
42 changes: 13 additions & 29 deletions
42
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 |
---|---|---|
@@ -1,46 +1,30 @@ | ||
import { useSessionContext } from '@clerk/shared/react/index'; | ||
import type { SessionTask } from '@clerk/types'; | ||
import type { ComponentType } from 'react'; | ||
import { withRedirectToAfterSignIn } from 'ui/common'; | ||
|
||
import { Route } from '../../../ui/router'; | ||
import { OrganizationListContext } from '../../../ui/contexts'; | ||
import { OrganizationList } from '../OrganizationList'; | ||
|
||
const paths: Record<SessionTask['key'], string> = { | ||
orgs: 'select-organization', | ||
}; | ||
|
||
const TaskRegistry: Record<SessionTask['key'], ComponentType> = { | ||
orgs: OrganizationList, | ||
org: () => ( | ||
<OrganizationListContext.Provider value={{ componentName: 'OrganizationList' }}> | ||
<OrganizationList /> | ||
</OrganizationListContext.Provider> | ||
), | ||
}; | ||
|
||
function usePendingTask() { | ||
/** | ||
* @internal | ||
*/ | ||
export function PendingTask(): React.ReactNode { | ||
const session = useSessionContext(); | ||
|
||
if (!session) { | ||
if (!session?.hasPendingTasks) { | ||
return null; | ||
} | ||
|
||
const [pendingTask] = session.tasks ?? []; | ||
const Task = TaskRegistry[pendingTask.key]; | ||
|
||
return pendingTask; | ||
} | ||
|
||
export function _PendingTask() { | ||
const pendingTask = usePendingTask(); | ||
|
||
if (!pendingTask) { | ||
return null; | ||
} | ||
|
||
const Task = TaskRegistry['orgs']; | ||
const path = paths[pendingTask.key]; | ||
|
||
return ( | ||
<Route path={path}> | ||
<Task /> | ||
</Route> | ||
); | ||
return <Task />; | ||
} | ||
|
||
export const PendingTask = withRedirectToAfterSignIn(_PendingTask); |
1 change: 1 addition & 0 deletions
1
packages/clerk-js/src/ui/components/PendingTask/__tests__/PendingTask.spec.ts
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 @@ | ||
// todo |
1 change: 1 addition & 0 deletions
1
packages/clerk-js/src/ui/components/PendingTask/__tests__/usePendingTaskRoute.spec.ts
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 @@ | ||
// todo |
This file was deleted.
Oops, something went wrong.
Empty file.
25 changes: 25 additions & 0 deletions
25
packages/clerk-js/src/ui/components/PendingTask/usePendingTaskRoute.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,25 @@ | ||
import { useSessionContext } from '@clerk/shared/react/index'; | ||
import type { Route } from '@clerk/shared/router'; | ||
import type { ComponentProps } from 'react'; | ||
|
||
import { sessionTaskRoutePaths } from '../../../ui/common/tasks'; | ||
import { PendingTask } from './PendingTask'; | ||
|
||
/** | ||
* Maps a session task key to routing props and content | ||
* @internal | ||
*/ | ||
export function usePendingTaskRoute(): ComponentProps<typeof Route> | null { | ||
const session = useSessionContext(); | ||
|
||
if (!session?.hasPendingTasks) { | ||
return null; | ||
} | ||
|
||
const [pendingTask] = session.tasks ?? []; | ||
|
||
return { | ||
children: <PendingTask />, | ||
path: sessionTaskRoutePaths[pendingTask.key], | ||
}; | ||
} |
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
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