Repository navigation
fix(web,mobile): say that removing a T3 Connect environment keeps its account registration #14127
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 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8bba72a
fix(web,mobile): explain that removing a T3 Connect environment keeps…
juliusmarminge b8d5729
fix(mobile): keep remove alert off the features import boundary
juliusmarminge 85780e9
fix(web,mobile): split the T3 Connect remove explanation into two par…
juliusmarminge 858ed83
fix(web,mobile): shorten the T3 Connect remove note and link it inline
juliusmarminge 561bb00
fix(web): use InlineButton for the T3 Connect settings link
juliusmarminge 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
80 changes: 80 additions & 0 deletions
80
apps/web/src/components/clerk/RemoveT3ConnectEnvironmentDialog.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,80 @@ | ||
| import { useState } from "react"; | ||
|
|
||
| import { | ||
| AlertDialog, | ||
| AlertDialogClose, | ||
| AlertDialogDescription, | ||
| AlertDialogFooter, | ||
| AlertDialogHeader, | ||
| AlertDialogPopup, | ||
| AlertDialogTitle, | ||
| } from "../ui/alert-dialog"; | ||
| import { Button } from "../ui/button"; | ||
| import { useT3ConnectAccountPage } from "./T3ConnectAccountPages"; | ||
|
|
||
| /** | ||
| * Confirms removing a T3 Connect environment from this device. Removal here | ||
| * leaves the account registration (and its host space) in place, so the dialog | ||
| * says so and links to the account page where it can be deregistered. | ||
| */ | ||
| export function RemoveT3ConnectEnvironmentDialog({ | ||
| environmentLabel, | ||
| onCancel, | ||
| onConfirm, | ||
| }: { | ||
| /** The environment awaiting confirmation; null keeps the dialog closed. */ | ||
| readonly environmentLabel: string | null; | ||
| readonly onCancel: () => void; | ||
| readonly onConfirm: () => void; | ||
| }) { | ||
| const accountPage = useT3ConnectAccountPage(); | ||
| // Keep the label through the close animation. | ||
| const [shownLabel, setShownLabel] = useState(environmentLabel); | ||
| if (environmentLabel !== null && environmentLabel !== shownLabel) setShownLabel(environmentLabel); | ||
| const openAccountPage = accountPage.open; | ||
|
|
||
| return ( | ||
| <> | ||
| <AlertDialog | ||
| open={environmentLabel !== null} | ||
| onOpenChange={(open) => { | ||
| if (!open) onCancel(); | ||
| }} | ||
| > | ||
| <AlertDialogPopup> | ||
| <AlertDialogHeader> | ||
| <AlertDialogTitle>Remove {shownLabel} from this device?</AlertDialogTitle> | ||
| <AlertDialogDescription> | ||
| This forgets its pairing, credentials, and cached threads here. | ||
| </AlertDialogDescription> | ||
| <AlertDialogDescription> | ||
| It stays on your T3 Connect account and keeps its host space. Deregister it in{" "} | ||
| {openAccountPage ? ( | ||
| <button | ||
| type="button" | ||
| className="cursor-pointer text-foreground underline underline-offset-4" | ||
| onClick={() => { | ||
| onCancel(); | ||
| openAccountPage(); | ||
| }} | ||
| > | ||
| T3 Connect settings | ||
| </button> | ||
| ) : ( | ||
| "T3 Connect settings" | ||
| )}{" "} | ||
| to free it. | ||
| </AlertDialogDescription> | ||
| </AlertDialogHeader> | ||
| <AlertDialogFooter> | ||
| <AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose> | ||
| <Button variant="destructive" onClick={onConfirm}> | ||
| Remove from this device | ||
| </Button> | ||
| </AlertDialogFooter> | ||
| </AlertDialogPopup> | ||
| </AlertDialog> | ||
| {accountPage.portals} | ||
| </> | ||
| ); | ||
| } | ||
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,66 @@ | ||
| import { useAuth, useClerk } from "@clerk/react"; | ||
| import { ServerIcon, SmartphoneIcon } from "lucide-react"; | ||
| import { type ReactNode, useCallback, useState } from "react"; | ||
| import { createPortal } from "react-dom"; | ||
|
|
||
| import { MobileClientsUserProfilePage } from "./MobileClientsUserProfilePage"; | ||
| import { T3ConnectUserProfilePage } from "./T3ConnectUserProfilePage"; | ||
|
|
||
| /** Custom pages in the Clerk account modal, in menu order. */ | ||
| export const T3_CONNECT_ACCOUNT_PAGES = [ | ||
| { | ||
| label: "Mobile clients", | ||
| url: "mobile-clients", | ||
| icon: <SmartphoneIcon className="size-4" />, | ||
| content: <MobileClientsUserProfilePage />, | ||
| }, | ||
| { | ||
| label: "T3 Connect", | ||
| url: "t3-connect", | ||
| icon: <ServerIcon className="size-4" />, | ||
| content: <T3ConnectUserProfilePage />, | ||
| }, | ||
| ] as const; | ||
|
|
||
| type PortalTargets = Readonly<Record<string, HTMLDivElement | undefined>>; | ||
|
|
||
| /** | ||
| * Opens the Clerk account modal on the T3 Connect page from outside the | ||
| * UserButton. Clerk mounts custom pages into DOM nodes it owns, so the caller | ||
| * must keep `portals` rendered for as long as the modal can be open. | ||
| */ | ||
| export function useT3ConnectAccountPage(): { | ||
| readonly open: (() => void) | null; | ||
| readonly portals: ReactNode; | ||
| } { | ||
| const clerk = useClerk(); | ||
| const { isSignedIn } = useAuth(); | ||
| const [targets, setTargets] = useState<PortalTargets>({}); | ||
|
|
||
| const open = useCallback(() => { | ||
| const setTarget = (key: string, element: HTMLDivElement | undefined) => | ||
| setTargets((current) => ({ ...current, [key]: element })); | ||
| clerk.openUserProfile({ | ||
| __experimental_startPath: "/t3-connect", | ||
| customPages: T3_CONNECT_ACCOUNT_PAGES.map((page) => ({ | ||
| label: page.label, | ||
| url: page.url, | ||
| mount: (element: HTMLDivElement) => setTarget(`content:${page.url}`, element), | ||
| unmount: () => setTarget(`content:${page.url}`, undefined), | ||
| mountIcon: (element: HTMLDivElement) => setTarget(`icon:${page.url}`, element), | ||
| unmountIcon: () => setTarget(`icon:${page.url}`, undefined), | ||
| })), | ||
| }); | ||
| }, [clerk]); | ||
|
|
||
| const portals = T3_CONNECT_ACCOUNT_PAGES.flatMap((page) => { | ||
| const content = targets[`content:${page.url}`]; | ||
| const icon = targets[`icon:${page.url}`]; | ||
| return [ | ||
| content ? createPortal(page.content, content, `content:${page.url}`) : null, | ||
| icon ? createPortal(page.icon, icon, `icon:${page.url}`) : null, | ||
| ]; | ||
| }); | ||
|
|
||
| return { open: isSignedIn ? open : null, portals }; | ||
| } |
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
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.