Skip to content

Commit d753201

Browse files
committed
update ecosystem API routes to include team slug (#6422)
Updates ecosystem API endpoints to be scoped under team routes The ecosystem wallet API endpoints have been updated to be scoped under team routes, ensuring proper data isolation between teams. All ecosystem-related API calls now include the team ID or slug in the path. Key changes: - Updated API endpoints from `/v1/ecosystem-wallet/*` to `/v1/teams/{teamIdOrSlug}/ecosystem-wallet/*` - Added team slug parameter to ecosystem fetch and list operations - Modified React hooks to include team context in query keys - Updated component props to pass team information through the component tree This change ensures ecosystem wallets are properly scoped to their respective teams and maintains data isolation between different team contexts. <!-- start pr-codex --> --- ## PR-Codex overview This PR updates various functions and components within the ecosystem module to include `team_slug` as a parameter. This change enhances the ability to fetch ecosystems and their details specific to a team, improving data handling across the application. ### Detailed summary - Updated `fetchEcosystem` to accept `team_slug`. - Modified `fetchEcosystemList` to include `team_slug`. - Adjusted the `useEcosystemList` hook to utilize `teamIdOrSlug`. - Enhanced `useEcosystem` to accept `teamIdOrSlug`. - Updated components to pass `team_slug` where necessary. - Changed redirect logic to incorporate team-specific ecosystems. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 6046d45 commit d753201

File tree

9 files changed

+60
-25
lines changed

9 files changed

+60
-25
lines changed

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/[slug]/(active)/analytics/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async function Page(props: {
2828
}
2929

3030
const [ecosystem, team] = await Promise.all([
31-
fetchEcosystem(params.slug, authToken),
31+
fetchEcosystem(params.slug, authToken, params.team_slug),
3232
getTeamBySlug(params.team_slug),
3333
]);
3434

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/[slug]/(active)/components/EcosystemSlugLayout.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function EcosystemLayoutSlug({
1010
ecosystemLayoutPath,
1111
}: {
1212
children: React.ReactNode;
13-
params: { slug: string };
13+
params: { slug: string; team_slug: string };
1414
ecosystemLayoutPath: string;
1515
}) {
1616
const authToken = await getAuthToken();
@@ -19,7 +19,11 @@ export async function EcosystemLayoutSlug({
1919
redirect(ecosystemLayoutPath);
2020
}
2121

22-
const ecosystem = await fetchEcosystem(params.slug, authToken);
22+
const ecosystem = await fetchEcosystem(
23+
params.slug,
24+
authToken,
25+
params.team_slug,
26+
);
2327

2428
if (!ecosystem) {
2529
redirect(ecosystemLayoutPath);
@@ -30,6 +34,7 @@ export async function EcosystemLayoutSlug({
3034
<EcosystemHeader
3135
ecosystem={ecosystem}
3236
ecosystemLayoutPath={ecosystemLayoutPath}
37+
teamIdOrSlug={params.team_slug}
3338
/>
3439

3540
<SidebarLayout

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/[slug]/(active)/components/ecosystem-header.client.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ function EcosystemAlertBanner({ ecosystem }: { ecosystem: Ecosystem }) {
6262
function EcosystemSelect(props: {
6363
ecosystem: Ecosystem;
6464
ecosystemLayoutPath: string;
65+
teamIdOrSlug: string;
6566
}) {
66-
const { data: ecosystems, isPending } = useEcosystemList();
67+
const { data: ecosystems, isPending } = useEcosystemList({
68+
teamIdOrSlug: props.teamIdOrSlug,
69+
});
6770

6871
return isPending ? (
6972
<Skeleton className="h-10 w-full md:w-[160px]" />
@@ -109,8 +112,10 @@ function EcosystemSelect(props: {
109112
export function EcosystemHeader(props: {
110113
ecosystem: Ecosystem;
111114
ecosystemLayoutPath: string;
115+
teamIdOrSlug: string;
112116
}) {
113117
const { data: fetchedEcosystem } = useEcosystem({
118+
teamIdOrSlug: props.teamIdOrSlug,
114119
slug: props.ecosystem.slug,
115120
refetchInterval:
116121
props.ecosystem.status === "requested"
@@ -192,6 +197,7 @@ export function EcosystemHeader(props: {
192197
<EcosystemSelect
193198
ecosystem={ecosystem}
194199
ecosystemLayoutPath={props.ecosystemLayoutPath}
200+
teamIdOrSlug={props.teamIdOrSlug}
195201
/>
196202
</div>
197203
</div>

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/[slug]/(active)/configuration/components/client/EcosystemPermissionsPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import { IntegrationPermissionsSection } from "../server/integration-permissions
77
export function EcosystemPermissionsPage({
88
params,
99
authToken,
10-
}: { params: { slug: string }; authToken: string }) {
11-
const { data: ecosystem } = useEcosystem({ slug: params.slug });
10+
}: { params: { slug: string; team_slug: string }; authToken: string }) {
11+
const { data: ecosystem } = useEcosystem({
12+
slug: params.slug,
13+
teamIdOrSlug: params.team_slug,
14+
});
1215

1316
return (
1417
<div className="flex flex-col gap-8">

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/[slug]/(active)/hooks/use-ecosystem.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ import { useQuery } from "@tanstack/react-query";
33
import type { Ecosystem } from "../../../types";
44

55
export function useEcosystem({
6+
teamIdOrSlug,
67
slug,
78
refetchInterval,
89
refetchOnWindowFocus,
910
initialData,
1011
}: {
12+
teamIdOrSlug: string;
1113
slug: string;
1214
refetchInterval?: number;
1315
refetchOnWindowFocus?: boolean;
1416
initialData?: Ecosystem;
1517
}) {
1618
return useQuery({
17-
queryKey: ["ecosystems", slug],
19+
queryKey: ["ecosystems", teamIdOrSlug, slug],
1820
queryFn: async () => {
1921
const res = await apiServerProxy({
20-
pathname: `/v1/ecosystem-wallet/${slug}`,
22+
pathname: `/v1/teams/${teamIdOrSlug}/ecosystem-wallet/${slug}`,
2123
method: "GET",
2224
});
2325

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/hooks/use-ecosystem-list.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { useQuery } from "@tanstack/react-query";
33
import { useActiveAccount } from "thirdweb/react";
44
import type { Ecosystem } from "../types";
55

6-
export function useEcosystemList() {
6+
export function useEcosystemList({
7+
teamIdOrSlug,
8+
}: {
9+
teamIdOrSlug: string;
10+
}) {
711
const address = useActiveAccount()?.address;
812
return useQuery({
9-
queryKey: ["ecosystems", address],
13+
queryKey: ["ecosystems", teamIdOrSlug, address],
1014
queryFn: async () => {
1115
const res = await apiServerProxy({
12-
pathname: "/v1/ecosystem-wallet/list",
16+
pathname: `/v1/teams/${teamIdOrSlug}/ecosystem-wallet`,
1317
method: "GET",
1418
});
1519

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ export default async function Page(props: {
2020
loginRedirect(ecosystemLayoutPath);
2121
}
2222

23-
const ecosystems = await fetchEcosystemList(authToken).catch((err) => {
24-
console.error("failed to fetch ecosystems", err);
25-
return [];
26-
});
23+
const ecosystems = await fetchEcosystemList(authToken, team_slug).catch(
24+
(err) => {
25+
console.error("failed to fetch ecosystems", err);
26+
return [];
27+
},
28+
);
2729
if (ecosystems[0]) {
2830
redirect(`${ecosystemLayoutPath}/${ecosystems[0].slug}`);
2931
}

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/utils/fetchEcosystem.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { API_SERVER_URL } from "@/constants/env";
22
import type { Ecosystem } from "../types";
33

4-
export async function fetchEcosystem(slug: string, authToken: string) {
5-
const res = await fetch(`${API_SERVER_URL}/v1/ecosystem-wallet/${slug}`, {
6-
headers: {
7-
Authorization: `Bearer ${authToken}`,
4+
export async function fetchEcosystem(
5+
slug: string,
6+
authToken: string,
7+
teamIdOrSlug: string,
8+
) {
9+
const res = await fetch(
10+
`${API_SERVER_URL}/v1/teams/${teamIdOrSlug}/ecosystem-wallet/${slug}`,
11+
{
12+
headers: {
13+
Authorization: `Bearer ${authToken}`,
14+
},
815
},
9-
});
16+
);
1017
if (!res.ok) {
1118
const data = await res.json();
1219
console.error(data);

apps/dashboard/src/app/team/[team_slug]/(team)/~/ecosystem/utils/fetchEcosystemList.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import { API_SERVER_URL } from "@/constants/env";
22
import type { Ecosystem } from "../types";
33

4-
export async function fetchEcosystemList(authToken: string) {
5-
const res = await fetch(`${API_SERVER_URL}/v1/ecosystem-wallet/list`, {
6-
headers: {
7-
Authorization: `Bearer ${authToken}`,
4+
export async function fetchEcosystemList(
5+
authToken: string,
6+
teamIdOrSlug: string,
7+
) {
8+
const res = await fetch(
9+
`${API_SERVER_URL}/v1/teams/${teamIdOrSlug}/ecosystem-wallet`,
10+
{
11+
headers: {
12+
Authorization: `Bearer ${authToken}`,
13+
},
814
},
9-
});
15+
);
1016

1117
if (!res.ok) {
1218
const data = await res.json();

0 commit comments

Comments
 (0)