Skip to content

Commit 8d44662

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

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

components/dashboard/src/App.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
href: '#http://example.org/',
14+
hash: '#examples'
15+
}
16+
});
17+
18+
expect(getURLHash()).toBe('examples');
19+
});

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: 56 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,27 @@ export function hasVisitedMarketingWebsiteBefore() {
4647
export function Login() {
4748
const { setUser } = useContext(UserContext);
4849
const { setTeams } = useContext(TeamsContext);
50+
const urlHash = getURLHash();
51+
const URLFromPrefix = urlHash.length > 0 ? new URL(urlHash).host : null;
4952
const showWelcome = !hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore();
5053

5154
const [ authProviders, setAuthProviders ] = useState<AuthProviderInfo[]>([]);
5255
const [ errorMessage, setErrorMessage ] = useState<string | undefined>(undefined);
56+
const [ providerFromPrefix, setProviderFromPrefix ] = useState<AuthProviderInfo>();
5357

5458
useEffect(() => {
5559
(async () => {
5660
setAuthProviders(await getGitpodService().server.getAuthProviders());
5761
})();
5862
}, [])
5963

64+
useEffect(() => {
65+
if (URLFromPrefix) {
66+
const providerFromPrefix = authProviders.find(provider => provider.host === URLFromPrefix);
67+
setProviderFromPrefix(providerFromPrefix);
68+
}
69+
}, [authProviders])
70+
6071
const authorizeSuccessful = async (payload?: string) => {
6172
updateUser().catch(console.error);
6273
// Check for a valid returnTo in payload
@@ -104,6 +115,47 @@ export function Login() {
104115
}
105116
}
106117

118+
const renderWelcomeText = () => {
119+
if (providerFromPrefix) {
120+
return (<div className="mx-auto text-center pb-8 space-y-2">
121+
<h1 className="text-3xl">Log in / Sign up</h1>
122+
<h2 className="text-m text-gray-400">Open a cloud-based environment for</h2>
123+
<h2 className="text-m text-gray-400">{urlHash}</h2>
124+
</div>)
125+
}
126+
return (
127+
<div className="mx-auto text-center pb-8 space-y-2">
128+
<h1 className="text-3xl">Log in{showWelcome ? '' : ' to Gitpod'}</h1>
129+
<h2 className="uppercase text-sm text-gray-400">ALWAYS READY-TO-CODE</h2>
130+
</div>
131+
)
132+
}
133+
134+
const renderAuthProviders = () => {
135+
if (providerFromPrefix) {
136+
return (
137+
<div className="flex flex-col space-y-3 items-center">
138+
<button key={"button" + providerFromPrefix.host} className="btn-login flex-none w-56 h-10 p-0 inline-flex" onClick={() => openLogin(providerFromPrefix.host)}>
139+
{iconForAuthProvider(providerFromPrefix.authProviderType)}
140+
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">Continue with {simplifyProviderName(providerFromPrefix.host)}</span>
141+
</button>
142+
</div>
143+
)
144+
}
145+
return (
146+
<div className="flex flex-col space-y-3 items-center">
147+
{authProviders.map(ap => {
148+
return (
149+
<button key={"button" + ap.host} className="btn-login flex-none w-56 h-10 p-0 inline-flex" onClick={() => openLogin(ap.host)}>
150+
{iconForAuthProvider(ap.authProviderType)}
151+
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">Continue with {simplifyProviderName(ap.host)}</span>
152+
</button>
153+
);
154+
})}
155+
</div>
156+
)
157+
}
158+
107159
return (<div id="login-container" className="z-50 flex w-screen h-screen">
108160
{showWelcome ? <div id="feature-section" className="flex-grow bg-gray-100 dark:bg-gray-800 w-1/2 hidden lg:block">
109161
<div id="feature-section-column" className="flex max-w-xl h-full mx-auto pt-6">
@@ -138,20 +190,10 @@ export function Login() {
138190
<div className="mx-auto pb-8">
139191
<img src={gitpodIcon} className="h-16 mx-auto" alt="Gitpod's logo" />
140192
</div>
141-
<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>
144-
</div>
145-
<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>
151-
</button>
152-
);
153-
})}
154-
</div>
193+
194+
{renderWelcomeText()}
195+
196+
{renderAuthProviders()}
155197

156198
{errorMessage && (
157199
<div className="mt-16 flex space-x-2 py-6 px-6 w-96 justify-between bg-gitpod-kumquat-light rounded-xl">

0 commit comments

Comments
 (0)