Skip to content

Commit eb2c3de

Browse files
Fix & Refactor Git Integration settings modal (#19345)
* Fix integration settings URL and improve copy functionality * Add InputWithCopy component to GitIntegrationModal & code cleanup
1 parent e4faf2b commit eb2c3de

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

components/dashboard/src/user-settings/Integrations.tsx

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { ItemsList } from "../components/ItemsList";
1717
import { SpinnerLoader } from "../components/Loader";
1818
import Modal, { ModalBody, ModalHeader, ModalFooter } from "../components/Modal";
1919
import { Heading2, Subheading } from "../components/typography/headings";
20-
import copy from "../images/copy.svg";
2120
import exclamation from "../images/exclamation.svg";
2221
import { openAuthorizeWindow, toAuthProviderLabel } from "../provider-utils";
2322
import { gitpodHostUrl } from "../service/service";
@@ -41,6 +40,7 @@ import { useUpdateUserAuthProviderMutation } from "../data/auth-providers/update
4140
import { useDeleteUserAuthProviderMutation } from "../data/auth-providers/delete-user-auth-provider-mutation";
4241
import { Button } from "@podkit/buttons/Button";
4342
import { isOrganizationOwned } from "@gitpod/public-api-common/lib/user-utils";
43+
import { InputWithCopy } from "../components/InputWithCopy";
4444

4545
export default function Integrations() {
4646
return (
@@ -699,10 +699,20 @@ export function GitIntegrationModal(
699699
let settingsUrl = ``;
700700
switch (type) {
701701
case AuthProviderType.GITHUB:
702-
settingsUrl = `${host}/settings/developers`;
702+
// if host is empty or untouched by user, use the default value
703+
if (host === "") {
704+
settingsUrl = "github.com/settings/developers";
705+
} else {
706+
settingsUrl = `${host}/settings/developers`;
707+
}
703708
break;
704709
case AuthProviderType.GITLAB:
705-
settingsUrl = `${host}/-/profile/applications`;
710+
// if host is empty or untouched by user, use the default value
711+
if (host === "") {
712+
settingsUrl = "gitlab.com/-/profile/applications";
713+
} else {
714+
settingsUrl = `${host}/-/profile/applications`;
715+
}
706716
break;
707717
default:
708718
return undefined;
@@ -749,18 +759,6 @@ export function GitIntegrationModal(
749759
}
750760
};
751761

752-
const copyRedirectURI = () => {
753-
const el = document.createElement("textarea");
754-
el.value = callbackUrl;
755-
document.body.appendChild(el);
756-
el.select();
757-
try {
758-
document.execCommand("copy");
759-
} finally {
760-
document.body.removeChild(el);
761-
}
762-
};
763-
764762
const getNumber = (paramValue: string | null) => {
765763
if (!paramValue) {
766764
return 0;
@@ -793,7 +791,7 @@ export function GitIntegrationModal(
793791
</span>
794792
</div>
795793

796-
<div className="overscroll-contain max-h-96 overflow-y-auto pr-2">
794+
<div className="overscroll-contain max-h-96 space-y-4 overflow-y-auto pr-2">
797795
{mode === "new" && (
798796
<div className="flex flex-col space-y-2">
799797
<label htmlFor="type" className="font-medium">
@@ -843,24 +841,7 @@ export function GitIntegrationModal(
843841
<label htmlFor="redirectURI" className="font-medium">
844842
Redirect URI
845843
</label>
846-
<div className="w-full relative">
847-
<input
848-
id="redirectURI"
849-
disabled={true}
850-
readOnly={true}
851-
type="text"
852-
value={callbackUrl}
853-
className="w-full pr-8"
854-
/>
855-
<div className="cursor-pointer" onClick={() => copyRedirectURI()}>
856-
<img
857-
src={copy}
858-
title="Copy the redirect URI to clipboard"
859-
className="absolute top-1/3 right-3"
860-
alt="copy icon"
861-
/>
862-
</div>
863-
</div>
844+
<InputWithCopy value={callbackUrl} tip="Copy the redirect URI to clipboard" />
864845
<span className="text-gray-500 text-sm">{getRedirectUrlDescription(type, host)}</span>
865846
</div>
866847
<div className="flex flex-col space-y-2">

0 commit comments

Comments
 (0)