Skip to content

Commit cf2f6c5

Browse files
author
Laurie T. Malau
committed
Adjust login page for prefix visit
1 parent 245ba88 commit cf2f6c5

File tree

3 files changed

+70
-15
lines changed

3 files changed

+70
-15
lines changed

components/dashboard/src/App.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { getURLHash } from './App'
8+
9+
test('urlHash', () => {
10+
global.window = Object.create(window);
11+
Object.defineProperty(window, 'location', {
12+
value: {
13+
hash: '#https://example.org/user/repo'
14+
}
15+
});
16+
17+
expect(getURLHash()).toBe('https://example.org/user/repo');
18+
});

components/dashboard/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function isWebsiteSlug(pathName: string) {
8585
return slugs.some(slug => pathName.startsWith('/' + slug + '/') || pathName === ('/' + slug));
8686
}
8787

88-
function getURLHash() {
88+
export function getURLHash() {
8989
return window.location.hash.replace(/^[#/]+/, '');
9090
}
9191

components/dashboard/src/Login.tsx

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import customize from "./images/welcome/customize.svg";
2121
import fresh from "./images/welcome/fresh.svg";
2222
import prebuild from "./images/welcome/prebuild.svg";
2323
import exclamation from "./images/exclamation.svg";
24+
import { getURLHash } from "./App";
2425

2526

2627
function Item(props: { icon: string, iconSize?: string, text: string }) {
@@ -46,17 +47,37 @@ export function hasVisitedMarketingWebsiteBefore() {
4647
export function Login() {
4748
const { setUser } = useContext(UserContext);
4849
const { setTeams } = useContext(TeamsContext);
49-
const showWelcome = !hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore();
50+
const urlHash = getURLHash();
51+
let hostFromContext: string | undefined;
52+
let repoPathname: string | undefined;
53+
try {
54+
if (urlHash.length > 0) {
55+
const url = new URL(urlHash);
56+
hostFromContext = url.host;
57+
repoPathname = url.pathname;
58+
}
59+
} catch (error) {
60+
// Hash is not a valid URL
61+
}
5062

51-
const [ authProviders, setAuthProviders ] = useState<AuthProviderInfo[]>([]);
52-
const [ errorMessage, setErrorMessage ] = useState<string | undefined>(undefined);
63+
const [authProviders, setAuthProviders] = useState<AuthProviderInfo[]>([]);
64+
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
65+
const [providerFromContext, setProviderFromContext] = useState<AuthProviderInfo>();
66+
const showWelcome = !hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore() && !urlHash.startsWith("https://");
5367

5468
useEffect(() => {
5569
(async () => {
5670
setAuthProviders(await getGitpodService().server.getAuthProviders());
5771
})();
5872
}, [])
5973

74+
useEffect(() => {
75+
if (hostFromContext && authProviders) {
76+
const providerFromContext = authProviders.find(provider => provider.host === hostFromContext);
77+
setProviderFromContext(providerFromContext);
78+
}
79+
}, [authProviders])
80+
6081
const authorizeSuccessful = async (payload?: string) => {
6182
updateUser().catch(console.error);
6283
// Check for a valid returnTo in payload
@@ -69,7 +90,7 @@ export function Login() {
6990

7091
const updateUser = async () => {
7192
await getGitpodService().reconnect();
72-
const [ user, teams ] = await Promise.all([
93+
const [user, teams] = await Promise.all([
7394
getGitpodService().server.getLoggedInUser(),
7495
getGitpodService().server.getTeams(),
7596
]);
@@ -136,21 +157,37 @@ export function Login() {
136157
<div className="flex-grow h-100 flex flex-row items-center justify-center" >
137158
<div className="rounded-xl px-10 py-10 mx-auto">
138159
<div className="mx-auto pb-8">
139-
<img src={gitpodIcon} className="h-16 mx-auto" alt="Gitpod's logo" />
160+
<img src={providerFromContext ? gitpod : gitpodIcon} className="h-14 mx-auto block dark:hidden" alt="Gitpod's logo" />
161+
<img src={gitpodDark} className="h-14 hidden dark:block" alt="Gitpod dark theme logo" />
140162
</div>
163+
141164
<div className="mx-auto text-center pb-8 space-y-2">
142-
<h1 className="text-3xl">Log in{showWelcome ? '' : ' to Gitpod'}</h1>
143-
<h2 className="uppercase text-sm text-gray-400">ALWAYS READY-TO-CODE</h2>
165+
{providerFromContext
166+
? <>
167+
<h2 className="text-xl text-black dark:text-gray-50 font-semibold">Open a cloud-based development environment</h2>
168+
<h2 className="text-xl">for the repository {repoPathname?.slice(1)}</h2>
169+
</>
170+
: <>
171+
<h1 className="text-3xl">Log in{showWelcome ? '' : ' to Gitpod'}</h1>
172+
<h2 className="uppercase text-sm text-gray-400">ALWAYS READY-TO-CODE</h2>
173+
</>}
144174
</div>
175+
176+
145177
<div className="flex flex-col space-y-3 items-center">
146-
{authProviders.map(ap => {
147-
return (
148-
<button key={"button" + ap.host} className="btn-login flex-none w-56 h-10 p-0 inline-flex" onClick={() => openLogin(ap.host)}>
149-
{iconForAuthProvider(ap.authProviderType)}
150-
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">Continue with {simplifyProviderName(ap.host)}</span>
178+
{providerFromContext
179+
?
180+
<button key={"button" + providerFromContext.host} className="btn-login flex-none w-56 h-10 p-0 inline-flex" onClick={() => openLogin(providerFromContext.host)}>
181+
{iconForAuthProvider(providerFromContext.authProviderType)}
182+
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">Continue with {simplifyProviderName(providerFromContext.host)}</span>
151183
</button>
152-
);
153-
})}
184+
:
185+
authProviders.map(ap =>
186+
<button key={"button" + ap.host} className="btn-login flex-none w-56 h-10 p-0 inline-flex" onClick={() => openLogin(ap.host)}>
187+
{iconForAuthProvider(ap.authProviderType)}
188+
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">Continue with {simplifyProviderName(ap.host)}</span>
189+
</button>)
190+
}
154191
</div>
155192

156193
{errorMessage && (

0 commit comments

Comments
 (0)