Skip to content

Commit c0e95ce

Browse files
committed
[dashboard] introduce "/?orgSlug=", which allows to pre-select an org in a "create workspace" URL (e.g. "/?orgSlug=org1#github.com/my/repo")
1 parent 02e3241 commit c0e95ce

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

components/dashboard/src/data/organizations/orgs-query.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,31 @@ export function useCurrentOrg(): { data?: Organization; isLoading: boolean } {
6161
return { data: undefined, isLoading: true };
6262
}
6363
let orgId = localStorage.getItem("active-org");
64+
let org: Organization | undefined = undefined;
65+
if (orgId) {
66+
org = orgs.data.find((org) => org.id === orgId);
67+
}
68+
69+
// 1. Check for org slug
70+
const orgSlugParam = getOrgSlugFromQuery(location.search);
71+
if (orgSlugParam) {
72+
org = orgs.data.find((org) => org.slug === orgSlugParam);
73+
}
74+
75+
// 2. Check for org id
76+
// id is more speficic than slug, so it takes precedence
6477
const orgIdParam = new URLSearchParams(location.search).get("org");
6578
if (orgIdParam) {
6679
orgId = orgIdParam;
80+
org = orgs.data.find((org) => org.id === orgId);
6781
}
68-
let org = orgs.data.find((org) => org.id === orgId);
82+
83+
// 3. Fallback: pick the first org
6984
if (!org) {
7085
org = orgs.data[0];
7186
}
87+
88+
// Persist the selected org
7289
if (org) {
7390
localStorage.setItem("active-org", org.id);
7491
} else if (orgId && (orgs.isLoading || orgs.isStale)) {
@@ -79,3 +96,7 @@ export function useCurrentOrg(): { data?: Organization; isLoading: boolean } {
7996
}
8097
return { data: org, isLoading: false };
8198
}
99+
100+
export function getOrgSlugFromQuery(search: string): string | undefined {
101+
return new URLSearchParams(search).get("orgSlug") || undefined;
102+
}

components/dashboard/src/login/SSOLoginForm.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { openOIDCStartWindow } from "../provider-utils";
1313
import { useFeatureFlag } from "../data/featureflag-query";
1414
import { useLocation } from "react-router";
1515
import { useOnboardingState } from "../dedicated-setup/use-needs-setup";
16+
import { getOrgSlugFromQuery } from "../data/organizations/orgs-query";
1617

1718
type Props = {
1819
onSuccess: () => void;
@@ -33,7 +34,10 @@ export const SSOLoginForm: FC<Props> = ({ onSuccess }) => {
3334
const singleOrgMode = (onboardingState?.organizationCountTotal || 0) < 2;
3435

3536
const [orgSlug, setOrgSlug] = useState(
36-
getOrgSlugFromPath(location.pathname) || window.localStorage.getItem("sso-org-slug") || "",
37+
getOrgSlugFromPath(location.pathname) ||
38+
window.localStorage.getItem("sso-org-slug") ||
39+
getOrgSlugFromQuery(location.search) ||
40+
"",
3741
);
3842
const [error, setError] = useState("");
3943

@@ -80,7 +84,7 @@ export const SSOLoginForm: FC<Props> = ({ onSuccess }) => {
8084
<div className="mt-10 space-y-2 w-56">
8185
{!singleOrgMode && (
8286
<TextInputField
83-
label="Organization Slug"
87+
label="Organization"
8488
placeholder="my-organization"
8589
value={orgSlug}
8690
onChange={setOrgSlug}

0 commit comments

Comments
 (0)