mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Problem The OAuth apps consent screen does not allow users to change the selected org. If the calling app didn't provide the org slug, we select the first available org from the users orgs. ## Solution Add an organization selector: <img width="436" height="570" alt="image" src="https://github.com/user-attachments/assets/a5579f2c-ff54-4d02-9d4a-ac75ed245719" /> ## Review instructions Requirements: - have multiple orgs - have a published app that needs projects selection and at least one authorization already granted - have the oauth example app ready Tests: - authorizing the app again on the same org it was before should preselect the projects - you should be able to select another org and if you do, that should clear the selected projects and you should see only this org projects in the options - reselecting the initially granted org should reselect the projects it had in the existing grant
87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
import { ChevronDownIcon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import {
|
|
Button,
|
|
CheckIcon,
|
|
cn,
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
Label,
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from 'ui'
|
|
|
|
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
|
|
import { Organization } from '@/types'
|
|
|
|
export const OrganizationSelect = ({
|
|
organization: selectedOrganization,
|
|
onOrganizationChange,
|
|
}: {
|
|
organization: Organization
|
|
onOrganizationChange: (slug: string) => void
|
|
}) => {
|
|
const [open, setOpen] = useState(false)
|
|
const { data } = useOrganizationsQuery()
|
|
|
|
return (
|
|
<div className="flex flex-col gap-2">
|
|
<Label htmlFor="organization" className="text-foreground text-sm">
|
|
Organization
|
|
</Label>
|
|
<Popover open={open} onOpenChange={(open) => setOpen(open)}>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
id="organization"
|
|
aria-expanded={open}
|
|
data-state={open ? 'open' : 'closed'}
|
|
type="button"
|
|
role="combobox"
|
|
className="justify-between"
|
|
size="small"
|
|
iconRight={<ChevronDownIcon />}
|
|
>
|
|
{selectedOrganization.name}
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent align="end" className="w-(--radix-popover-trigger-width) p-0">
|
|
<Command>
|
|
<CommandInput placeholder="Search organization..." />
|
|
<CommandList>
|
|
<CommandEmpty>No organization found.</CommandEmpty>
|
|
<CommandGroup>
|
|
{(data ?? []).map((organization) => (
|
|
<CommandItem
|
|
key={organization.id}
|
|
value={organization.slug}
|
|
keywords={[organization.name]}
|
|
onSelect={() => {
|
|
onOrganizationChange(organization.slug)
|
|
setOpen(false)
|
|
}}
|
|
>
|
|
<CheckIcon
|
|
className={cn(
|
|
'mr-2 h-4 w-4',
|
|
selectedOrganization.slug === organization.slug
|
|
? 'opacity-100'
|
|
: 'opacity-0'
|
|
)}
|
|
/>
|
|
{organization.name}
|
|
</CommandItem>
|
|
))}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
</div>
|
|
)
|
|
}
|