Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/teams/JoinTeam.tsx
2501 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 { useEffect, useMemo, useState } from "react";
8
import { useHistory, useLocation } from "react-router-dom";
9
import { useOrganizationsInvalidator } from "../data/organizations/orgs-query";
10
import { useDocumentTitle } from "../hooks/use-document-title";
11
import { organizationClient } from "../service/public-api";
12
import { workspacesPathMain } from "../workspaces/workspaces.routes";
13
14
export default function JoinTeamPage() {
15
const orgInvalidator = useOrganizationsInvalidator();
16
const history = useHistory();
17
const location = useLocation();
18
19
const [joinError, setJoinError] = useState<Error>();
20
const inviteId = useMemo(() => new URLSearchParams(location.search).get("inviteId"), [location]);
21
22
useEffect(() => {
23
(async () => {
24
try {
25
if (!inviteId) {
26
throw new Error("This invite URL is incorrect.");
27
}
28
const response = await organizationClient.joinOrganization({ invitationId: inviteId });
29
orgInvalidator();
30
31
history.push(workspacesPathMain + `?org=${response.organizationId}`);
32
} catch (error) {
33
console.error(error);
34
setJoinError(error);
35
}
36
})();
37
}, [history, inviteId, orgInvalidator]);
38
39
useDocumentTitle("Joining Organization");
40
41
return joinError ? <div className="mt-16 text-center text-gitpod-red">{String(joinError)}</div> : <></>;
42
}
43
44