Skip to content

Commit 83562fa

Browse files
author
Laurie T. Malau
committed
Adjust login page for prefix visit
1 parent 505263d commit 83562fa

File tree

3 files changed

+81
-18
lines changed

3 files changed

+81
-18
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: 61 additions & 17 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);
49-
const showWelcome = !hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore();
50+
const urlHash = getURLHash();
51+
const URLFromPrefix = urlHash ? new URL(urlHash).host : null;
52+
const showWelcome = !hasLoggedInBefore() && !hasVisitedMarketingWebsiteBefore() && urlHash.length === 0;
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
@@ -69,7 +80,7 @@ export function Login() {
6980

7081
const updateUser = async () => {
7182
await getGitpodService().reconnect();
72-
const [ user, teams ] = await Promise.all([
83+
const [user, teams] = await Promise.all([
7384
getGitpodService().server.getLoggedInUser(),
7485
getGitpodService().server.getTeams(),
7586
]);
@@ -104,6 +115,49 @@ export function Login() {
104115
}
105116
}
106117

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

156200
{errorMessage && (
157201
<div className="mt-16 flex space-x-2 py-6 px-6 w-96 justify-between bg-gitpod-kumquat-light rounded-xl">
@@ -174,5 +218,5 @@ export function Login() {
174218
</div>
175219

176220
</div>
177-
</div>);
221+
</div >);
178222
}

0 commit comments

Comments
 (0)