Skip to content

Commit cd4adf9

Browse files
selfcontainedjankeromnes
authored andcommitted
updating connect with linked-in banner
1 parent b3da8b0 commit cd4adf9

File tree

3 files changed

+79
-35
lines changed

3 files changed

+79
-35
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) 2023 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 { useQuery } from "@tanstack/react-query";
8+
import classNames from "classnames";
9+
import { FC, useEffect, useState } from "react";
10+
import { useLinkedIn } from "react-linkedin-login-oauth2";
11+
import Alert from "../components/Alert";
12+
import { Button } from "../components/Button";
13+
import SignInWithLinkedIn from "../images/sign-in-with-linkedin.svg";
14+
import { getGitpodService } from "../service/service";
15+
16+
type Props = {};
17+
export const LinkedInBanner: FC<Props> = () => {
18+
const {
19+
data: clientID,
20+
isLoading,
21+
isError,
22+
} = useQuery(
23+
["linkedin-clientid"],
24+
async () => {
25+
return (await getGitpodService().server.getLinkedInClientId()) || "";
26+
},
27+
{ enabled: false },
28+
);
29+
30+
const { linkedInLogin } = useLinkedIn({
31+
clientId: clientID || "",
32+
redirectUri: `${window.location.origin}/linkedin`,
33+
onSuccess: (code) => {
34+
console.log("success", code);
35+
},
36+
onError: (error) => {
37+
console.log("error", error);
38+
},
39+
});
40+
41+
return (
42+
<>
43+
<div
44+
className={classNames(
45+
"mt-6 p-6",
46+
"border-2 border-dashed rounded-md space-y-4",
47+
"bg-gray-50 dark:bg-gray-800",
48+
)}
49+
>
50+
<div className="flex items-center justify-center space-x-6">
51+
<span className="text-4xl">🎁</span>
52+
{/* TODO: Shouldn't need a fixed width here, but was hard to center otherwise */}
53+
<p className="w-64 text-base text-gray-500 dark:text-gray-100">
54+
Receive <strong>500 credits</strong> per month by connecting your <strong>LinkedIn</strong>{" "}
55+
account.
56+
</p>
57+
</div>
58+
<Button
59+
className="w-full flex items-center justify-center space-x-2"
60+
onClick={linkedInLogin}
61+
disabled={isLoading || !clientID}
62+
>
63+
<img src={SignInWithLinkedIn} width={20} height={20} alt="Sign in with Linked In" />
64+
<span>Connect with LinkedIn</span>
65+
</Button>
66+
</div>
67+
{/* TODO: Figure out if there's a different way we want to handle an error getting the clientID */}
68+
{isError && (
69+
<Alert className="mt-4" type="error">
70+
We're sorry, there was a problem with the LinkedIn connection.
71+
</Alert>
72+
)}
73+
</>
74+
);
75+
};

components/dashboard/src/onboarding/StepUserInfo.tsx

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import { useUpdateCurrentUserMutation } from "../data/current-user/update-mutati
1313
import { useOnBlurError } from "../hooks/use-onblur-error";
1414
import { OnboardingStep } from "./OnboardingStep";
1515
import SignInWithLinkedIn from "../images/sign-in-with-linkedin.svg";
16+
import { Button } from "../components/Button";
17+
import { LinkedInBanner } from "./LinkedInBanner";
1618

1719
type Props = {
1820
user: User;
19-
linkedInClientId: string;
2021
onComplete(user: User): void;
2122
};
22-
export const StepUserInfo: FC<Props> = ({ user, linkedInClientId, onComplete }) => {
23+
export const StepUserInfo: FC<Props> = ({ user, onComplete }) => {
2324
const updateUser = useUpdateCurrentUserMutation();
2425
// attempt to split provided name for default input values
2526
const { first, last } = getInitialNameParts(user);
@@ -29,17 +30,6 @@ export const StepUserInfo: FC<Props> = ({ user, linkedInClientId, onComplete })
2930
// Email purposefully not pre-filled
3031
const [emailAddress, setEmailAddress] = useState("");
3132

32-
const { linkedInLogin } = useLinkedIn({
33-
clientId: linkedInClientId,
34-
redirectUri: `${window.location.origin}/linkedin`,
35-
onSuccess: (code) => {
36-
console.log("success", code);
37-
},
38-
onError: (error) => {
39-
console.log("error", error);
40-
},
41-
});
42-
4333
const handleSubmit = useCallback(async () => {
4434
const additionalData = user.additionalData || {};
4535
const profile = additionalData.profile || {};
@@ -124,19 +114,7 @@ export const StepUserInfo: FC<Props> = ({ user, linkedInClientId, onComplete })
124114
required
125115
/>
126116

127-
<div>
128-
<p className="text-gray-500 text-sm mt-4">
129-
Verify your account by connecting with LinkedIn and receive 500 credits per month. 🎁
130-
</p>
131-
<button className="primary" onClick={linkedInLogin}>
132-
<img
133-
src={SignInWithLinkedIn}
134-
alt="Sign in with Linked In"
135-
style={{ maxWidth: "180px", cursor: "pointer" }}
136-
/>
137-
Connect with LinkedIn
138-
</button>
139-
</div>
117+
<LinkedInBanner />
140118
</OnboardingStep>
141119
);
142120
};

components/dashboard/src/onboarding/UserOnboarding.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ const UserOnboarding: FunctionComponent<Props> = ({ user }) => {
4040

4141
const [step, setStep] = useState(STEPS.ONE);
4242
const [completingError, setCompletingError] = useState("");
43-
const [linkedInClientId, setLinkedInClientId] = useState("");
44-
45-
useEffect(() => {
46-
(async () => {
47-
const clientId = await getGitpodService().server.getLinkedInClientId();
48-
setLinkedInClientId(clientId);
49-
})();
50-
}, []);
5143

5244
// We track this state here so we can persist it at the end of the flow instead of when it's selected
5345
// This is because setting the ide is how we indicate a user has onboarded, and want to defer that until the end
@@ -142,7 +134,6 @@ const UserOnboarding: FunctionComponent<Props> = ({ user }) => {
142134
{step === STEPS.ONE && (
143135
<StepUserInfo
144136
user={user}
145-
linkedInClientId={linkedInClientId}
146137
onComplete={(updatedUser) => {
147138
setUser(updatedUser);
148139
setStep(STEPS.TWO);

0 commit comments

Comments
 (0)