-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Select Account Modal #3897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Select Account Modal #3897
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License-AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth"; | ||
import { useEffect, useState } from "react"; | ||
import { gitpodHostUrl } from "../service/service"; | ||
import Modal from "../components/Modal"; | ||
import SelectableCard from "../components/SelectableCard"; | ||
import info from '../images/info.svg'; | ||
|
||
export function SelectAccountModal(props: SelectAccountPayload & { | ||
close: () => void | ||
}) { | ||
|
||
const [useAccount, setUseAccount] = useState<"current" | "other">("current"); | ||
|
||
useEffect(() => { | ||
}, []); | ||
|
||
const continueWithCurrentAccount = () => { | ||
props.close(); | ||
}; | ||
|
||
const continueWithOtherAccount = () => { | ||
const accessControlUrl = gitpodHostUrl.asAccessControl().toString(); | ||
|
||
const loginUrl = gitpodHostUrl.withApi({ | ||
pathname: '/login', | ||
search: `host=${props.otherUser.authHost}&returnTo=${encodeURIComponent(accessControlUrl)}` | ||
}).toString(); | ||
|
||
const logoutUrl = gitpodHostUrl.withApi({ | ||
pathname: "/logout", | ||
search: `returnTo=${encodeURIComponent(loginUrl)}` | ||
}).toString(); | ||
|
||
window.location.href = logoutUrl; | ||
}; | ||
|
||
return (<Modal visible={true} onClose={props.close}> | ||
<h3 className="pb-2">Select Account</h3> | ||
<div className="border-t border-b border-gray-200 mt-2 -mx-6 px-6 py-4"> | ||
<p className="pb-2 text-gray-500 text-base">You are trying to authorize a provider that is already connected with another account on Gitpod.</p> | ||
|
||
<div className="mt-4 flex rounded-md w-full bg-gray-200 p-4 mx-auto"> | ||
<img className="w-4 h-4 m-1 ml-2 mr-4" src={info} /> | ||
<span> | ||
Disconnect a provider in one of you accounts, if you like to continue with the other account. | ||
</span> | ||
</div> | ||
|
||
<div className="mt-10 mb-6 flex-grow flex flex-row justify-around align-center"> | ||
<SelectableCard className="w-2/5 h-56" title="Current Account" selected={useAccount === 'current'} onClick={() => setUseAccount('current')}> | ||
<div className="flex-grow flex flex-col justify-center align-center"> | ||
<img className="m-auto rounded-full w-24 h-24 py-4" src={props.currentUser.avatarUrl} alt={props.currentUser.name}/> | ||
<span className="m-auto text-gray-700 text-md font-semibold">{props.currentUser.authName}</span> | ||
<span className="m-auto text-gray-400 text-md">{props.currentUser.authHost}</span> | ||
</div> | ||
</SelectableCard> | ||
|
||
<SelectableCard className="w-2/5 h-56" title="Other Account" selected={useAccount === 'other'} onClick={() => setUseAccount('other')}> | ||
<div className="flex-grow flex flex-col justify-center align-center"> | ||
<img className="m-auto rounded-full w-24 h-24 py-4" src={props.otherUser.avatarUrl} alt={props.otherUser.name}/> | ||
<span className="m-auto text-gray-700 text-md font-semibold">{props.otherUser.authName}</span> | ||
<span className="m-auto text-gray-400 text-md">{props.otherUser.authHost}</span> | ||
</div> | ||
</SelectableCard> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
<div className="flex justify-end mt-6"> | ||
<button className={"ml-2"} onClick={() => { | ||
if (useAccount === "other") { | ||
continueWithOtherAccount(); | ||
} else { | ||
continueWithCurrentAccount(); | ||
} | ||
}}>Continue</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Shall we also offer a secondary option to go back to user settings, Integrations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
please verify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a good MVC. Let's do it. |
||
</div> | ||
</Modal>); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: WDYT of the following? Alternatively, we could split the following into two alert components, one for information (gray) and one for warning (red).