Skip to content

feat(site): add an organization switcher to the user menu #13269

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 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🧪
  • Loading branch information
aslilac committed May 14, 2024
commit eea7fd1b47c9481ed58cee1b139b4787ef8a5970
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PopoverTrigger,
} from "components/Popover/Popover";
import { UserAvatar } from "components/UserAvatar/UserAvatar";
import { useDashboard } from "modules/dashboard/useDashboard";
import { BUTTON_SM_HEIGHT, navHeight } from "theme/constants";
import { UserDropdownContent } from "./UserDropdownContent";

Expand All @@ -28,7 +29,11 @@ export const UserDropdown: FC<UserDropdownProps> = ({
onSignOut,
}) => {
const theme = useTheme();
const organizationsQuery = useQuery(myOrganizations());
const organizationsQuery = useQuery({
...myOrganizations(),
enabled: Boolean(localStorage.getItem("enableMultiOrganizationUi")),
});
const { organizationId, setOrganizationId } = useDashboard();

return (
<Popover>
Expand Down Expand Up @@ -67,6 +72,8 @@ export const UserDropdown: FC<UserDropdownProps> = ({
buildInfo={buildInfo}
supportLinks={supportLinks}
organizations={organizationsQuery.data}
organizationId={organizationId}
setOrganizationId={setOrganizationId}
onSignOut={onSignOut}
/>
</PopoverContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { CopyButton } from "components/CopyButton/CopyButton";
import { ExternalImage } from "components/ExternalImage/ExternalImage";
import { usePopover } from "components/Popover/Popover";
import { Stack } from "components/Stack/Stack";
import { useDashboard } from "modules/dashboard/useDashboard";

export const Language = {
accountLabel: "Account",
Expand Down Expand Up @@ -86,6 +85,8 @@ const styles = {
export interface UserDropdownContentProps {
user: TypesGen.User;
organizations?: TypesGen.Organization[];
organizationId?: string;
setOrganizationId?: (id: string) => void;
buildInfo?: TypesGen.BuildInfoResponse;
supportLinks?: readonly TypesGen.LinkConfig[];
onSignOut: () => void;
Expand All @@ -94,12 +95,13 @@ export interface UserDropdownContentProps {
export const UserDropdownContent: FC<UserDropdownContentProps> = ({
user,
organizations,
organizationId,
setOrganizationId,
buildInfo,
supportLinks,
onSignOut,
}) => {
const popover = usePopover();
const { organizationId, setOrganizationId } = useDashboard();

const onPopoverClose = () => {
popover.setIsOpen(false);
Expand Down Expand Up @@ -150,7 +152,7 @@ export const UserDropdownContent: FC<UserDropdownContentProps> = ({
key={org.id}
css={styles.menuItem}
onClick={() => {
setOrganizationId(org.id);
setOrganizationId?.(org.id);
popover.setIsOpen(false);
}}
>
Expand Down
Loading