Skip to content

Commit a5a7d64

Browse files
easyCZroboquat
authored andcommitted
[dashboard] Use Public API when fetching team members
1 parent bdddbb9 commit a5a7d64

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

components/dashboard/src/Menu.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import FeedbackFormModal from "./feedback-form/FeedbackModal";
2727
import { inResource, isGitpodIo } from "./utils";
2828
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
2929
import { FeatureFlagContext } from "./contexts/FeatureFlagContext";
30+
import { publicApiTeamMembersToProtocol, teamsService } from "./service/public-api";
3031

3132
interface Entry {
3233
title: string;
@@ -36,7 +37,7 @@ interface Entry {
3637

3738
export default function Menu() {
3839
const { user } = useContext(UserContext);
39-
const { showUsageView } = useContext(FeatureFlagContext);
40+
const { showUsageView, usePublicApiTeamsService } = useContext(FeatureFlagContext);
4041
const { teams } = useContext(TeamsContext);
4142
const location = useLocation();
4243
const team = getCurrentTeam(location, teams);
@@ -128,7 +129,11 @@ export default function Menu() {
128129
await Promise.all(
129130
teams.map(async (team) => {
130131
try {
131-
members[team.id] = await getGitpodService().server.getTeamMembers(team.id);
132+
members[team.id] = usePublicApiTeamsService
133+
? await publicApiTeamMembersToProtocol(
134+
(await teamsService.getTeam({ teamId: team!.id })).team?.members || [],
135+
)
136+
: await getGitpodService().server.getTeamMembers(team.id);
132137
} catch (error) {
133138
console.error("Could not get members of team", team, error);
134139
}

components/dashboard/src/components/BillingAccountSelector.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ import { UserContext } from "../user-context";
1313
import SelectableCardSolid from "../components/SelectableCardSolid";
1414
import { ReactComponent as Spinner } from "../icons/Spinner.svg";
1515
import Alert from "./Alert";
16+
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
17+
import { publicApiTeamMembersToProtocol, teamsService } from "../service/public-api";
1618

1719
export function BillingAccountSelector(props: { onSelected?: () => void }) {
1820
const { user, setUser } = useContext(UserContext);
1921
const { teams } = useContext(TeamsContext);
2022
const [teamsAvailableForAttribution, setTeamsAvailableForAttribution] = useState<Team[] | undefined>();
2123
const [membersByTeam, setMembersByTeam] = useState<Record<string, TeamMemberInfo[]>>({});
2224
const [errorMessage, setErrorMessage] = useState<string | undefined>();
25+
const { usePublicApiTeamsService } = useContext(FeatureFlagContext);
2326

2427
useEffect(() => {
2528
if (!teams) {
@@ -54,7 +57,11 @@ export function BillingAccountSelector(props: { onSelected?: () => void }) {
5457
Promise.all(
5558
teams.map(async (team) => {
5659
try {
57-
members[team.id] = await getGitpodService().server.getTeamMembers(team.id);
60+
members[team.id] = usePublicApiTeamsService
61+
? await publicApiTeamMembersToProtocol(
62+
(await teamsService.getTeam({ teamId: team!.id })).team?.members || [],
63+
)
64+
: await getGitpodService().server.getTeamMembers(team.id);
5865
} catch (error) {
5966
console.warn("Could not get members of team", team, error);
6067
}

components/dashboard/src/components/UsageBasedBillingConfig.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import Modal from "../components/Modal";
2020
import Alert from "./Alert";
2121
import dayjs from "dayjs";
2222
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
23+
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
24+
import { publicApiTeamMembersToProtocol, teamsService } from "../service/public-api";
2325

2426
const BASE_USAGE_LIMIT_FOR_STRIPE_USERS = 1000;
2527

@@ -32,6 +34,7 @@ interface Props {
3234
export default function UsageBasedBillingConfig({ attributionId }: Props) {
3335
const location = useLocation();
3436
const { currency } = useContext(PaymentContext);
37+
const { usePublicApiTeamsService } = useContext(FeatureFlagContext);
3538
const [showUpdateLimitModal, setShowUpdateLimitModal] = useState<boolean>(false);
3639
const [showBillingSetupModal, setShowBillingSetupModal] = useState<boolean>(false);
3740
const [stripeSubscriptionId, setStripeSubscriptionId] = useState<string | undefined>();
@@ -102,7 +105,11 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
102105
let limit = BASE_USAGE_LIMIT_FOR_STRIPE_USERS;
103106
const attrId = AttributionId.parse(attributionId);
104107
if (attrId?.kind === "team") {
105-
const members = await getGitpodService().server.getTeamMembers(attrId.teamId);
108+
const members = usePublicApiTeamsService
109+
? await publicApiTeamMembersToProtocol(
110+
(await teamsService.getTeam({ teamId: attrId.teamId })).team?.members || [],
111+
)
112+
: await getGitpodService().server.getTeamMembers(attrId.teamId);
106113
limit = BASE_USAGE_LIMIT_FOR_STRIPE_USERS * members.length;
107114
}
108115
const newLimit = await getGitpodService().server.subscribeToStripe(attributionId, setupIntentId, limit);

components/dashboard/src/projects/NewProject.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ import { trackEvent } from "../Analytics";
2121
import exclamation from "../images/exclamation.svg";
2222
import ErrorMessage from "../components/ErrorMessage";
2323
import Spinner from "../icons/Spinner.svg";
24-
import { publicApiTeamsToProtocol, publicApiTeamToProtocol, teamsService } from "../service/public-api";
24+
import {
25+
publicApiTeamMembersToProtocol,
26+
publicApiTeamsToProtocol,
27+
publicApiTeamToProtocol,
28+
teamsService,
29+
} from "../service/public-api";
2530
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
2631
import { ConnectError } from "@bufbuild/connect-web";
2732

2833
export default function NewProject() {
2934
const location = useLocation();
3035
const { teams } = useContext(TeamsContext);
3136
const { user, setUser } = useContext(UserContext);
37+
const { usePublicApiTeamsService } = useContext(FeatureFlagContext);
3238

3339
const [selectedProviderHost, setSelectedProviderHost] = useState<string | undefined>();
3440
const [reposInAccounts, setReposInAccounts] = useState<ProviderRepository[]>([]);
@@ -113,7 +119,11 @@ export default function NewProject() {
113119
await Promise.all(
114120
teams.map(async (team) => {
115121
try {
116-
members[team.id] = await getGitpodService().server.getTeamMembers(team.id);
122+
members[team.id] = usePublicApiTeamsService
123+
? await publicApiTeamMembersToProtocol(
124+
(await teamsService.getTeam({ teamId: team!.id })).team?.members || [],
125+
)
126+
: await getGitpodService().server.getTeamMembers(team.id);
117127
} catch (error) {
118128
console.error("Could not get members of team", team, error);
119129
}

components/dashboard/src/teams/TeamBilling.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { getCurrentTeam, TeamsContext } from "./teams-context";
2424
import { getTeamSettingsMenu } from "./TeamSettings";
2525
import TeamUsageBasedBilling from "./TeamUsageBasedBilling";
2626
import { UserContext } from "../user-context";
27+
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
28+
import { publicApiTeamMembersToProtocol, teamsService } from "../service/public-api";
2729

2830
type PendingPlan = Plan & { pendingSince: number };
2931

@@ -39,14 +41,19 @@ export default function TeamBilling() {
3941
const [teamBillingMode, setTeamBillingMode] = useState<BillingMode | undefined>(undefined);
4042
const [pendingTeamPlan, setPendingTeamPlan] = useState<PendingPlan | undefined>();
4143
const [pollTeamSubscriptionTimeout, setPollTeamSubscriptionTimeout] = useState<NodeJS.Timeout | undefined>();
44+
const { usePublicApiTeamsService } = useContext(FeatureFlagContext);
4245

4346
useEffect(() => {
4447
if (!team) {
4548
return;
4649
}
4750
(async () => {
4851
const [memberInfos, subscription, teamBillingMode] = await Promise.all([
49-
getGitpodService().server.getTeamMembers(team.id),
52+
usePublicApiTeamsService
53+
? teamsService.getTeam({ teamId: team!.id }).then((resp) => {
54+
return publicApiTeamMembersToProtocol(resp.team?.members || []);
55+
})
56+
: getGitpodService().server.getTeamMembers(team.id),
5057
getGitpodService().server.getTeamSubscription(team.id),
5158
getGitpodService().server.getBillingModeForTeam(team.id),
5259
]);

components/dashboard/src/teams/TeamSettings.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Redirect, useLocation } from "react-router";
1111
import ConfirmationModal from "../components/ConfirmationModal";
1212
import { PageWithSubMenu } from "../components/PageWithSubMenu";
1313
import { FeatureFlagContext } from "../contexts/FeatureFlagContext";
14-
import { teamsService } from "../service/public-api";
14+
import { publicApiTeamMembersToProtocol, teamsService } from "../service/public-api";
1515
import { getGitpodService, gitpodHostUrl } from "../service/service";
1616
import { UserContext } from "../user-context";
1717
import { getCurrentTeam, TeamsContext } from "./teams-context";
@@ -51,7 +51,12 @@ export default function TeamSettings() {
5151
useEffect(() => {
5252
(async () => {
5353
if (!team) return;
54-
const members = await getGitpodService().server.getTeamMembers(team.id);
54+
const members = usePublicApiTeamsService
55+
? await publicApiTeamMembersToProtocol(
56+
(await teamsService.getTeam({ teamId: team!.id })).team?.members || [],
57+
)
58+
: await getGitpodService().server.getTeamMembers(team.id);
59+
5560
const currentUserInTeam = members.find((member) => member.userId === user?.id);
5661
setIsUserOwner(currentUserInTeam?.role === "owner");
5762

0 commit comments

Comments
 (0)