Skip to content

Commit 09fbb2d

Browse files
author
Laurie T. Malau
committed
Adjust login page for prefix visit
1 parent 5837426 commit 09fbb2d

File tree

3 files changed

+64
-14
lines changed

3 files changed

+64
-14
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: '#example.org'
14+
}
15+
});
16+
17+
expect(getURLHash()).toBe('example.org');
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: 45 additions & 13 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,32 @@ 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+
try {
53+
hostFromContext = urlHash.length > 0 ? new URL(urlHash).host : undefined;
54+
} catch (error) {
55+
// Hash is not a valid URL
56+
}
5057

51-
const [ authProviders, setAuthProviders ] = useState<AuthProviderInfo[]>([]);
52-
const [ errorMessage, setErrorMessage ] = useState<string | undefined>(undefined);
58+
const [authProviders, setAuthProviders] = useState<AuthProviderInfo[]>([]);
59+
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
60+
const [providerFromContext, setProviderFromContext] = useState<AuthProviderInfo>();
61+
const showWelcome = !hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore() && !urlHash.startsWith("https://");
5362

5463
useEffect(() => {
5564
(async () => {
5665
setAuthProviders(await getGitpodService().server.getAuthProviders());
5766
})();
5867
}, [])
5968

69+
useEffect(() => {
70+
if (hostFromContext && authProviders) {
71+
const providerFromContext = authProviders.find(provider => provider.host === hostFromContext);
72+
setProviderFromContext(providerFromContext);
73+
}
74+
}, [authProviders])
75+
6076
const authorizeSuccessful = async (payload?: string) => {
6177
updateUser().catch(console.error);
6278
// Check for a valid returnTo in payload
@@ -69,7 +85,7 @@ export function Login() {
6985

7086
const updateUser = async () => {
7187
await getGitpodService().reconnect();
72-
const [ user, teams ] = await Promise.all([
88+
const [user, teams] = await Promise.all([
7389
getGitpodService().server.getLoggedInUser(),
7490
getGitpodService().server.getTeams(),
7591
]);
@@ -138,19 +154,35 @@ export function Login() {
138154
<div className="mx-auto pb-8">
139155
<img src={gitpodIcon} className="h-16 mx-auto" alt="Gitpod's logo" />
140156
</div>
157+
141158
<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>
159+
{providerFromContext
160+
? <>
161+
<h1 className="text-3xl">Log in / Sign up</h1>
162+
<h2 className="text-m text-gray-400">Open a cloud-based environment for</h2>
163+
<h2 className="text-m text-gray-400">{urlHash}</h2>
164+
</>
165+
: <>
166+
<h1 className="text-3xl">Log in{showWelcome ? '' : ' to Gitpod'}</h1>
167+
<h2 className="uppercase text-sm text-gray-400">ALWAYS READY-TO-CODE</h2>
168+
</>}
144169
</div>
170+
171+
145172
<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>
173+
{providerFromContext
174+
?
175+
<button key={"button" + providerFromContext.host} className="btn-login flex-none w-56 h-10 p-0 inline-flex" onClick={() => openLogin(providerFromContext.host)}>
176+
{iconForAuthProvider(providerFromContext.authProviderType)}
177+
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">Continue with {simplifyProviderName(providerFromContext.host)}</span>
151178
</button>
152-
);
153-
})}
179+
:
180+
authProviders.map(ap =>
181+
<button key={"button" + ap.host} className="btn-login flex-none w-56 h-10 p-0 inline-flex" onClick={() => openLogin(ap.host)}>
182+
{iconForAuthProvider(ap.authProviderType)}
183+
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">Continue with {simplifyProviderName(ap.host)}</span>
184+
</button>)
185+
}
154186
</div>
155187

156188
{errorMessage && (

0 commit comments

Comments
 (0)