Skip to content

Commit 56462b5

Browse files
committed
enable team invites
1 parent a258e7e commit 56462b5

File tree

246 files changed

+372
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+372
-150
lines changed

apps/dashboard/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"use server";
2+
import "server-only";
3+
import { redirect } from "next/navigation";
4+
import { getAuthToken } from "../../app/api/lib/getAuthToken";
5+
import type { Team } from "../api/team";
6+
import { API_SERVER_URL } from "../constants/env";
7+
8+
export async function acceptInvite(options: {
9+
teamId: string;
10+
inviteId: string;
11+
}) {
12+
const token = await getAuthToken();
13+
14+
if (!token) {
15+
return {
16+
errorMessage: "You are not authorized to perform this action",
17+
};
18+
}
19+
20+
const res = await fetch(
21+
`${API_SERVER_URL}/v1/teams/${options.teamId}/invites/${options.inviteId}/accept`,
22+
{
23+
method: "POST",
24+
headers: {
25+
"Content-Type": "application/json",
26+
Authorization: `Bearer ${token}`,
27+
},
28+
body: JSON.stringify({}),
29+
},
30+
);
31+
32+
if (!res.ok) {
33+
let errorMessage = "Failed to accept invite";
34+
try {
35+
const result = (await res.json()) as {
36+
error: {
37+
code: string;
38+
message: string;
39+
statusCode: number;
40+
};
41+
};
42+
errorMessage = result.error.message;
43+
} catch {}
44+
throw new Error(errorMessage);
45+
}
46+
47+
const { team } = (await res.json()).result as { team: Team };
48+
49+
// redirect to the team page
50+
redirect(`/team/${team.slug}`);
51+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"use server";
2+
import "server-only";
3+
import { getAuthToken } from "../../app/api/lib/getAuthToken";
4+
import { API_SERVER_URL } from "../constants/env";
5+
6+
export async function sendTeamInvite(options: {
7+
teamId: string;
8+
email: string;
9+
role: "OWNER" | "MEMBER";
10+
}) {
11+
const token = await getAuthToken();
12+
13+
if (!token) {
14+
throw new Error("You are not authorized to perform this action");
15+
}
16+
17+
const res = await fetch(
18+
`${API_SERVER_URL}/v1/teams/${options.teamId}/invites`,
19+
{
20+
method: "POST",
21+
headers: {
22+
Authorization: `Bearer ${token}`,
23+
"Content-Type": "application/json",
24+
},
25+
body: JSON.stringify({
26+
inviteEmail: options.email,
27+
inviteRole: options.role,
28+
}),
29+
},
30+
);
31+
32+
if (!res.ok) {
33+
throw new Error("Failed to send invite");
34+
}
35+
36+
return true;
37+
}

apps/dashboard/src/@/api/team.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "server-only";
2-
import { API_SERVER_URL } from "@/constants/env";
2+
import { API_SERVER_URL, THIRDWEB_API_SECRET } from "@/constants/env";
33
import { getAuthToken } from "../../app/api/lib/getAuthToken";
44

55
type EnabledTeamScope =
@@ -30,6 +30,23 @@ export type Team = {
3030
enabledScopes: EnabledTeamScope[];
3131
};
3232

33+
export async function service_getTeamBySlug(slug: string) {
34+
if (!THIRDWEB_API_SECRET) {
35+
throw new Error("API_SERVER_SECRET is not set");
36+
}
37+
38+
const teamRes = await fetch(`${API_SERVER_URL}/v1/teams/${slug}`, {
39+
headers: {
40+
"x-service-api-key": THIRDWEB_API_SECRET,
41+
},
42+
});
43+
44+
if (teamRes.ok) {
45+
return (await teamRes.json())?.result as Team;
46+
}
47+
return null;
48+
}
49+
3350
export async function getTeamBySlug(slug: string) {
3451
const token = await getAuthToken();
3552

apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
useQuery,
88
useQueryClient,
99
} from "@tanstack/react-query";
10-
import type { ResultItem } from "app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/metrics/components/StatusCodes";
10+
import type { ResultItem } from "app/team/[team_slug]/(internal)/(team)/~/engine/(instance)/[engineId]/metrics/components/StatusCodes";
11+
import type { EngineStatus } from "app/team/[team_slug]/(internal)/(team)/~/engine/(instance)/[engineId]/overview/components/transactions-table";
1112
import type { EngineBackendWalletType } from "lib/engine";
1213
import { useState } from "react";
1314
import { useActiveAccount } from "thirdweb/react";
1415
import invariant from "tiny-invariant";
15-
import type { EngineStatus } from "../../../app/team/[team_slug]/(team)/~/engine/(instance)/[engineId]/overview/components/transactions-table";
1616
import { engineKeys } from "../cache-keys";
1717

1818
export type EngineTier = "STARTER" | "PREMIUM" | "ENTERPRISE";

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/_layout/primary-dashboard-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
AddToProjectSelector,
2626
type MinimalTeamsAndProjects,
2727
} from "../../../../../../components/contract-components/contract-deploy-form/add-to-project-card";
28-
import { useAddContractToProject } from "../../../../../team/[team_slug]/[project_slug]/hooks/project-contracts";
28+
import { useAddContractToProject } from "../../../../../team/[team_slug]/(internal)/[project_slug]/hooks/project-contracts";
2929

3030
const TRACKING_CATEGORY = "add_to_dashboard_upsell";
3131

apps/dashboard/src/app/nebula-app/(app)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getAuthTokenWalletAddress,
99
} from "../../api/lib/getAuthToken";
1010
import { loginRedirect } from "../../login/loginRedirect";
11-
import { NebulaWaitListPage } from "../../team/[team_slug]/[project_slug]/nebula/components/nebula-waitlist-page";
11+
import { NebulaWaitListPage } from "../../team/[team_slug]/(internal)/[project_slug]/nebula/components/nebula-waitlist-page";
1212
import { getSessions } from "./api/session";
1313
import { ChatPageLayout } from "./components/ChatPageLayout";
1414
import { NebulaAccountButton } from "./components/NebulaAccountButton";

apps/dashboard/src/app/team/[team_slug]/(team)/_components/TotalSponsoredCard.tsx renamed to apps/dashboard/src/app/team/[team_slug]/(internal)/(team)/_components/TotalSponsoredCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { cn } from "@/lib/utils";
2+
import { EmptyAccountAbstractionChartContent } from "components/smart-wallets/AccountAbstractionAnalytics/SponsoredTransactionsChartCard";
23
import { defineChain } from "thirdweb";
34
import { type ChainMetadata, getChainMetadata } from "thirdweb/chains";
45
import type { UserOpStats } from "types/analytics";
5-
import { EmptyAccountAbstractionChartContent } from "../../../../../components/smart-wallets/AccountAbstractionAnalytics/SponsoredTransactionsChartCard";
6-
import { BarChart } from "../../../components/Analytics/BarChart";
7-
import { CombinedBarChartCard } from "../../../components/Analytics/CombinedBarChartCard";
6+
import { BarChart } from "../../../../components/Analytics/BarChart";
7+
import { CombinedBarChartCard } from "../../../../components/Analytics/CombinedBarChartCard";
88

99
export async function TotalSponsoredChartCardUI({
1010
data,

apps/dashboard/src/app/team/[team_slug]/(team)/_components/TransactionsCard.tsx renamed to apps/dashboard/src/app/team/[team_slug]/(internal)/(team)/_components/TransactionsCard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { cn } from "@/lib/utils";
2+
import { EmptyAccountAbstractionChartContent } from "components/smart-wallets/AccountAbstractionAnalytics/SponsoredTransactionsChartCard";
23
import { defineChain } from "thirdweb";
34
import { type ChainMetadata, getChainMetadata } from "thirdweb/chains";
45
import type { TransactionStats } from "types/analytics";
5-
import { EmptyAccountAbstractionChartContent } from "../../../../../components/smart-wallets/AccountAbstractionAnalytics/SponsoredTransactionsChartCard";
6-
import { BarChart } from "../../../components/Analytics/BarChart";
7-
import { CombinedBarChartCard } from "../../../components/Analytics/CombinedBarChartCard";
6+
import { BarChart } from "../../../../components/Analytics/BarChart";
7+
import { CombinedBarChartCard } from "../../../../components/Analytics/CombinedBarChartCard";
88

99
export async function TransactionsChartCardUI({
1010
data,

apps/dashboard/src/app/team/[team_slug]/(team)/layout.tsx renamed to apps/dashboard/src/app/team/[team_slug]/(internal)/(team)/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { getProjects } from "@/api/projects";
22
import { getTeamNebulaWaitList, getTeams } from "@/api/team";
33
import { TabPathLinks } from "@/components/ui/tabs";
44
import { redirect } from "next/navigation";
5-
import { getValidAccount } from "../../../account/settings/getAccount";
6-
import { getAuthTokenWalletAddress } from "../../../api/lib/getAuthToken";
7-
import { TeamHeaderLoggedIn } from "../../components/TeamHeader/team-header-logged-in.client";
5+
import { getValidAccount } from "../../../../account/settings/getAccount";
6+
import { getAuthTokenWalletAddress } from "../../../../api/lib/getAuthToken";
7+
import { TeamHeaderLoggedIn } from "../../../components/TeamHeader/team-header-logged-in.client";
88

99
export default async function TeamLayout(props: {
1010
children: React.ReactNode;

0 commit comments

Comments
 (0)