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