Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/onboarding/LinkedInBanner.tsx
2500 views
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 } from "react";
10
import { useLinkedIn } from "react-linkedin-login-oauth2";
11
import Alert from "../components/Alert";
12
import { Button } from "@podkit/buttons/Button";
13
import SignInWithLinkedIn from "../images/sign-in-with-linkedin.svg";
14
import { getGitpodService } from "../service/service";
15
import { LinkedInProfile } from "@gitpod/gitpod-protocol";
16
import { useToast } from "../components/toasts/Toasts";
17
18
type Props = {
19
onSuccess(profile: LinkedInProfile): void;
20
};
21
export const LinkedInBanner: FC<Props> = ({ onSuccess }) => {
22
const { toast } = useToast();
23
const {
24
data: clientID,
25
isLoading,
26
isError,
27
} = useQuery(
28
["linkedin-clientid"],
29
async () => {
30
return (await getGitpodService().server.getLinkedInClientId()) || "";
31
},
32
{ enabled: true },
33
);
34
35
const { linkedInLogin } = useLinkedIn({
36
clientId: clientID || "",
37
redirectUri: `${window.location.origin}/linkedin`,
38
scope: "r_liteprofile r_emailaddress",
39
onSuccess: (code) => {
40
getGitpodService()
41
.server.connectWithLinkedIn(code)
42
.then((profile) => {
43
onSuccess(profile);
44
})
45
.catch((error) => {
46
console.error("LinkedIn connection failed", error);
47
48
toast(
49
<>
50
<span>Error connecting with LinkedIn</span>
51
{error.message && <pre className="mt-2 whitespace-normal text-xs">{error.message}</pre>}
52
</>,
53
);
54
});
55
},
56
onError: (error) => {
57
console.error("error", error);
58
},
59
});
60
61
return (
62
<>
63
<div
64
className={classNames(
65
"mt-6 p-6",
66
"border-2 border-dashed rounded-md space-y-4",
67
"bg-pk-surface-secondary dark:border-gray-600",
68
)}
69
>
70
<div className="flex items-center justify-center space-x-6">
71
<span className="text-4xl">🎁</span>
72
{/* TODO: Shouldn't need a fixed width here, but was hard to center otherwise */}
73
<p className="w-64 text-base text-gray-500 dark:text-gray-100">
74
Receive <strong>50 hours</strong> of usage per month by connecting your{" "}
75
<strong>LinkedIn</strong> account.
76
</p>
77
</div>
78
<Button
79
className="gap-2 w-full"
80
onClick={(event) => {
81
event.preventDefault();
82
linkedInLogin();
83
}}
84
disabled={isLoading || !clientID}
85
>
86
<img src={SignInWithLinkedIn} width={20} height={20} alt="" /> Connect with LinkedIn
87
</Button>
88
</div>
89
{/* TODO: Figure out if there's a different way we want to handle an error getting the clientID */}
90
{isError && (
91
<Alert className="mt-4" type="error">
92
We're sorry, there was a problem with the LinkedIn connection.
93
</Alert>
94
)}
95
</>
96
);
97
};
98
99