Path: blob/main/components/dashboard/src/user-settings/SelectAccountModal.tsx
2500 views
/**1* Copyright (c) 2021 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 { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth";7import { useEffect, useState } from "react";8import { gitpodHostUrl } from "../service/service";9import InfoBox from "../components/InfoBox";10import Modal, { ModalBody, ModalFooter, ModalHeader } from "../components/Modal";11import SelectableCard from "../components/SelectableCard";12import { Button } from "@podkit/buttons/Button";1314export function SelectAccountModal(15props: SelectAccountPayload & {16close: () => void;17},18) {19const [useAccount, setUseAccount] = useState<"current" | "other">("current");2021useEffect(() => {}, []);2223const continueWithCurrentAccount = () => {24props.close();25};2627const continueWithOtherAccount = () => {28const accessControlUrl = gitpodHostUrl.asAccessControl().toString();2930const loginUrl = gitpodHostUrl31.withApi({32pathname: "/login",33search: `host=${props.otherUser.authHost}&returnTo=${encodeURIComponent(accessControlUrl)}`,34})35.toString();3637const logoutUrl = gitpodHostUrl38.withApi({39pathname: "/logout",40search: `returnTo=${encodeURIComponent(loginUrl)}`,41})42.toString();4344window.location.href = logoutUrl;45};4647return (48// TODO: Use title and buttons props49<Modal visible={true} onClose={props.close}>50<ModalHeader>Select Account</ModalHeader>51<ModalBody>52<p className="pb-2 text-gray-500 text-base">53You are trying to authorize a provider that is already connected with another account on Gitpod.54</p>5556<InfoBox className="mt-4 w-full mx-auto">57Disconnect a provider in one of your accounts, if you would like to continue with the other account.58</InfoBox>5960<div className="mt-10 mb-6 flex-grow flex flex-row justify-around align-center">61<SelectableCard62className="w-2/5 h-56"63title="Current Account"64selected={useAccount === "current"}65onClick={() => setUseAccount("current")}66>67<div className="flex-grow flex flex-col justify-center align-center">68<img69className="m-auto rounded-full w-24 h-24 my-4"70src={props.currentUser.avatarUrl}71alt={props.currentUser.name}72/>73<span className="m-auto text-gray-700 text-md font-semibold">74{props.currentUser.authName}75</span>76<span className="m-auto text-gray-400 text-md">{props.currentUser.authHost}</span>77</div>78</SelectableCard>7980<SelectableCard81className="w-2/5 h-56"82title="Other Account"83selected={useAccount === "other"}84onClick={() => setUseAccount("other")}85>86<div className="flex-grow flex flex-col justify-center align-center">87<img88className="m-auto rounded-full w-24 h-24 my-4"89src={props.otherUser.avatarUrl}90alt={props.otherUser.name}91/>92<span className="m-auto text-gray-700 text-md font-semibold">93{props.otherUser.authName}94</span>95<span className="m-auto text-gray-400 text-md">{props.otherUser.authHost}</span>96</div>97</SelectableCard>98</div>99</ModalBody>100101<ModalFooter>102<Button103className={"ml-2"}104onClick={() => {105if (useAccount === "other") {106continueWithOtherAccount();107} else {108continueWithCurrentAccount();109}110}}111>112Continue113</Button>114</ModalFooter>115</Modal>116);117}118119120