-
Notifications
You must be signed in to change notification settings - Fork 62
🚩 fix: Non-Admin Org Recovery Follow-Ups (loader gate, switch completion, switcher UX) #107
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
Closed
dustinhealy
wants to merge
4
commits into
agent/admin-org-access-recovery
from
agent/admin-org-access-recovery-fixes
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a4687bb
fix(admin): resolve recovery gate in loader and smooth org switching
dustinhealy 85dbd17
test(admin): align verifyAdminTokenFn 403 test with recovery behavior
dustinhealy d436d43
refactor(admin): drop artificial switch delay, remove narration comme…
dustinhealy 7208a01
fix(admin): make org recovery resilient to bot-flagged switch edge cases
dustinhealy 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 |
|---|---|---|
| @@ -1,57 +1,103 @@ | ||
| import { useState } from 'react'; | ||
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||
| import { useRouter } from '@tanstack/react-router'; | ||
| import { Select } from '@clickhouse/click-ui'; | ||
| import { useLocalize } from '@/hooks'; | ||
| import { Button, Icon, Select } from '@clickhouse/click-ui'; | ||
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||
| import { adminOrganizationsQueryOptions, switchAdminOrganizationFn } from '@/server'; | ||
| import { useLocalize } from '@/hooks'; | ||
|
|
||
| export function OrganizationSwitcher() { | ||
| const localize = useLocalize(); | ||
| const router = useRouter(); | ||
| const queryClient = useQueryClient(); | ||
| const [selectedOrgId, setSelectedOrgId] = useState(''); | ||
| const [switchingTo, setSwitchingTo] = useState<string | null>(null); | ||
| const organizationsQuery = useQuery(adminOrganizationsQueryOptions); | ||
| const switchMutation = useMutation({ | ||
| mutationFn: (targetOrgId: string) => switchAdminOrganizationFn({ data: { targetOrgId } }), | ||
| onSuccess: async () => { | ||
| await queryClient.invalidateQueries({ queryKey: ['adminOrganizations'] }); | ||
| await router.invalidate(); | ||
| await router.navigate({ to: '/' }); | ||
| try { | ||
| await queryClient.invalidateQueries(); | ||
| await router.invalidate(); | ||
| await router.navigate({ to: '/' }); | ||
| } catch { | ||
| setSwitchingTo(null); | ||
| } | ||
| }, | ||
| onError: () => { | ||
| setSwitchingTo(null); | ||
| setSelectedOrgId(''); | ||
| }, | ||
| onError: () => setSelectedOrgId(''), | ||
| }); | ||
|
|
||
| if (switchingTo) { | ||
| return ( | ||
| <div | ||
| role="status" | ||
| className="fixed inset-0 z-50 flex items-center justify-center gap-2 bg-(--cui-color-background-default) text-(--cui-color-text-muted)" | ||
| > | ||
| <Icon name="loading-animated" size="sm" /> | ||
| <span className="text-sm"> | ||
| {localize('com_admin_org_switcher_switching_to', { org: switchingTo })} | ||
| </span> | ||
| </div> | ||
| ); | ||
|
dustinhealy marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const organizations = organizationsQuery.data ?? []; | ||
| if (organizations.length === 0) return null; | ||
|
|
||
| const startSwitch = (organization: { id: string; name: string }) => { | ||
| setSwitchingTo(organization.name); | ||
| switchMutation.mutate(organization.id); | ||
| }; | ||
|
|
||
| const error = switchMutation.isError && ( | ||
| <p role="alert" className="text-sm text-(--cui-color-text-danger)"> | ||
| {localize('com_admin_org_switcher_error')} | ||
| </p> | ||
| ); | ||
|
|
||
| if (organizations.length === 1) { | ||
| const organization = organizations[0]; | ||
| return ( | ||
| <div className="flex w-full max-w-sm flex-col gap-2"> | ||
| <Button | ||
| type="primary" | ||
| label={localize('com_admin_org_switcher_continue', { org: organization.name })} | ||
| onClick={() => startSwitch(organization)} | ||
| disabled={switchMutation.isPending} | ||
| /> | ||
|
dustinhealy marked this conversation as resolved.
|
||
| {error} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const selected = organizations.find((organization) => organization.id === selectedOrgId); | ||
| return ( | ||
| <div className="flex w-full max-w-sm flex-col gap-2"> | ||
| <Select | ||
| label={localize('com_admin_org_switcher_label')} | ||
| placeholder={localize('com_admin_org_switcher_placeholder')} | ||
| value={selectedOrgId} | ||
| onSelect={(value) => { | ||
| setSelectedOrgId(value); | ||
| switchMutation.mutate(value); | ||
| }} | ||
| disabled={switchMutation.isPending || organizationsQuery.isLoading} | ||
| value={selectedOrgId || undefined} | ||
| onSelect={(value) => setSelectedOrgId(value)} | ||
| > | ||
| {organizations.map((organization) => ( | ||
| <Select.Item key={organization.id} value={organization.id}> | ||
| {organization.name} | ||
| </Select.Item> | ||
| ))} | ||
| </Select> | ||
| {switchMutation.isPending && ( | ||
| <p className="text-sm text-(--cui-color-text-muted)"> | ||
| {localize('com_admin_org_switcher_switching')} | ||
| </p> | ||
| )} | ||
| {switchMutation.isError && ( | ||
| <p role="alert" className="text-sm text-(--cui-color-text-danger)"> | ||
| {localize('com_admin_org_switcher_error')} | ||
| </p> | ||
| )} | ||
| <Button | ||
| type="primary" | ||
| label={ | ||
| selected | ||
| ? localize('com_admin_org_switcher_switch_to', { org: selected.name }) | ||
| : localize('com_admin_org_switcher_switch') | ||
| } | ||
| onClick={() => selected && startSwitch(selected)} | ||
| disabled={!selected || switchMutation.isPending} | ||
| /> | ||
| {error} | ||
| </div> | ||
| ); | ||
| } | ||
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
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.