Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/user-settings/SelectAccountModal.tsx
2500 views
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 { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth";
8
import { useEffect, useState } from "react";
9
import { gitpodHostUrl } from "../service/service";
10
import InfoBox from "../components/InfoBox";
11
import Modal, { ModalBody, ModalFooter, ModalHeader } from "../components/Modal";
12
import SelectableCard from "../components/SelectableCard";
13
import { Button } from "@podkit/buttons/Button";
14
15
export function SelectAccountModal(
16
props: SelectAccountPayload & {
17
close: () => void;
18
},
19
) {
20
const [useAccount, setUseAccount] = useState<"current" | "other">("current");
21
22
useEffect(() => {}, []);
23
24
const continueWithCurrentAccount = () => {
25
props.close();
26
};
27
28
const continueWithOtherAccount = () => {
29
const accessControlUrl = gitpodHostUrl.asAccessControl().toString();
30
31
const loginUrl = gitpodHostUrl
32
.withApi({
33
pathname: "/login",
34
search: `host=${props.otherUser.authHost}&returnTo=${encodeURIComponent(accessControlUrl)}`,
35
})
36
.toString();
37
38
const logoutUrl = gitpodHostUrl
39
.withApi({
40
pathname: "/logout",
41
search: `returnTo=${encodeURIComponent(loginUrl)}`,
42
})
43
.toString();
44
45
window.location.href = logoutUrl;
46
};
47
48
return (
49
// TODO: Use title and buttons props
50
<Modal visible={true} onClose={props.close}>
51
<ModalHeader>Select Account</ModalHeader>
52
<ModalBody>
53
<p className="pb-2 text-gray-500 text-base">
54
You are trying to authorize a provider that is already connected with another account on Gitpod.
55
</p>
56
57
<InfoBox className="mt-4 w-full mx-auto">
58
Disconnect a provider in one of your accounts, if you would like to continue with the other account.
59
</InfoBox>
60
61
<div className="mt-10 mb-6 flex-grow flex flex-row justify-around align-center">
62
<SelectableCard
63
className="w-2/5 h-56"
64
title="Current Account"
65
selected={useAccount === "current"}
66
onClick={() => setUseAccount("current")}
67
>
68
<div className="flex-grow flex flex-col justify-center align-center">
69
<img
70
className="m-auto rounded-full w-24 h-24 my-4"
71
src={props.currentUser.avatarUrl}
72
alt={props.currentUser.name}
73
/>
74
<span className="m-auto text-gray-700 text-md font-semibold">
75
{props.currentUser.authName}
76
</span>
77
<span className="m-auto text-gray-400 text-md">{props.currentUser.authHost}</span>
78
</div>
79
</SelectableCard>
80
81
<SelectableCard
82
className="w-2/5 h-56"
83
title="Other Account"
84
selected={useAccount === "other"}
85
onClick={() => setUseAccount("other")}
86
>
87
<div className="flex-grow flex flex-col justify-center align-center">
88
<img
89
className="m-auto rounded-full w-24 h-24 my-4"
90
src={props.otherUser.avatarUrl}
91
alt={props.otherUser.name}
92
/>
93
<span className="m-auto text-gray-700 text-md font-semibold">
94
{props.otherUser.authName}
95
</span>
96
<span className="m-auto text-gray-400 text-md">{props.otherUser.authHost}</span>
97
</div>
98
</SelectableCard>
99
</div>
100
</ModalBody>
101
102
<ModalFooter>
103
<Button
104
className={"ml-2"}
105
onClick={() => {
106
if (useAccount === "other") {
107
continueWithOtherAccount();
108
} else {
109
continueWithCurrentAccount();
110
}
111
}}
112
>
113
Continue
114
</Button>
115
</ModalFooter>
116
</Modal>
117
);
118
}
119
120