Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard] Add team ID to ecosystem API requests #6659

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {} from "@/components/ui/breadcrumb";
import { notFound } from "next/navigation";
import { getTeamBySlug } from "../../../../../../../../../../@/api/team";
import { getAuthToken } from "../../../../../../../../../api/lib/getAuthToken";
import { loginRedirect } from "../../../../../../../../../login/loginRedirect";
import { AddPartnerForm } from "../components/client/add-partner-form.client";
Expand All @@ -10,12 +12,19 @@ export default async function AddPartnerPage({
params: Promise<{ slug: string; team_slug: string }>;
}) {
const { slug, team_slug } = await params;
const authToken = await getAuthToken();
const [authToken, team] = await Promise.all([
getAuthToken(),
getTeamBySlug(team_slug),
]);

if (!authToken) {
loginRedirect(`/team/${team_slug}/~/ecosystem/${slug}`);
}

if (!team) {
notFound();
}

const teamSlug = team_slug;
const ecosystemSlug = slug;

Expand All @@ -32,7 +41,11 @@ export default async function AddPartnerPage({
<h1 className="mb-6 font-semibold text-2xl tracking-tight">
Add New Partner
</h1>
<AddPartnerForm ecosystem={ecosystem} authToken={authToken} />
<AddPartnerForm
ecosystem={ecosystem}
authToken={authToken}
teamId={team.id}
/>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { IntegrationPermissionsSection } from "../server/integration-permissions
export function EcosystemPermissionsPage({
params,
authToken,
}: { params: { slug: string; team_slug: string }; authToken: string }) {
teamId,
}: {
params: { slug: string; team_slug: string };
authToken: string;
teamId: string;
}) {
const { data: ecosystem } = useEcosystem({
slug: params.slug,
teamIdOrSlug: params.team_slug,
Expand All @@ -18,13 +23,19 @@ export function EcosystemPermissionsPage({
<IntegrationPermissionsSection
ecosystem={ecosystem}
authToken={authToken}
teamId={teamId}
/>
<AuthOptionsSection
ecosystem={ecosystem}
authToken={authToken}
teamId={teamId}
/>
<AuthOptionsSection ecosystem={ecosystem} authToken={authToken} />
{ecosystem?.permission === "PARTNER_WHITELIST" && (
<EcosystemPartnersSection
teamSlug={params.team_slug}
ecosystem={ecosystem}
authToken={authToken}
teamId={teamId}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { PartnerForm, type PartnerFormValues } from "./partner-form.client";
export function AddPartnerForm({
ecosystem,
authToken,
teamId,
}: {
ecosystem: Ecosystem;
authToken: string;
teamId: string;
}) {
const router = useDashboardRouter();
const params = useParams();
Expand All @@ -21,6 +23,7 @@ export function AddPartnerForm({
const { mutateAsync: addPartner, isPending } = useAddPartner(
{
authToken,
teamId,
},
{
onSuccess: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type AuthOptionsFormData = {
export function AuthOptionsForm({
ecosystem,
authToken,
}: { ecosystem: Ecosystem; authToken: string }) {
teamId,
}: { ecosystem: Ecosystem; authToken: string; teamId: string }) {
const form = useForm<AuthOptionsFormData>({
defaultValues: {
authOptions: ecosystem.authOptions || [],
Expand Down Expand Up @@ -147,6 +148,7 @@ export function AuthOptionsForm({
const { mutateAsync: updateEcosystem, isPending } = useUpdateEcosystem(
{
authToken,
teamId,
},
{
onError: (error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { useUpdateEcosystem } from "../../hooks/use-update-ecosystem";
export function IntegrationPermissionsToggle({
ecosystem,
authToken,
}: { ecosystem: Ecosystem; authToken: string }) {
teamId,
}: { ecosystem: Ecosystem; authToken: string; teamId: string }) {
const [messageToConfirm, setMessageToConfirm] = useState<
| {
title: string;
Expand All @@ -28,6 +29,7 @@ export function IntegrationPermissionsToggle({
} = useUpdateEcosystem(
{
authToken,
teamId,
},
{
onError: (error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export function UpdatePartnerForm({
ecosystem,
partner,
authToken,
teamId,
}: {
ecosystem: Ecosystem;
partner: Partner;
authToken: string;
teamId: string;
}) {
const router = useDashboardRouter();
const params = useParams();
Expand All @@ -23,6 +25,7 @@ export function UpdatePartnerForm({
const { mutateAsync: updatePartner, isPending } = useUpdatePartner(
{
authToken,
teamId,
},
{
onSuccess: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import {
export function AuthOptionsSection({
ecosystem,
authToken,
}: { ecosystem?: Ecosystem; authToken: string }) {
teamId,
}: { ecosystem?: Ecosystem; authToken: string; teamId: string }) {
return (
<section className="flex flex-col gap-4 md:gap-8">
{ecosystem ? (
<AuthOptionsForm ecosystem={ecosystem} authToken={authToken} />
<AuthOptionsForm
ecosystem={ecosystem}
authToken={authToken}
teamId={teamId}
/>
) : (
<AuthOptionsFormSkeleton />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ export function EcosystemPartnersSection({
teamSlug,
ecosystem,
authToken,
}: { teamSlug: string; ecosystem: Ecosystem; authToken: string }) {
teamId,
}: {
teamSlug: string;
ecosystem: Ecosystem;
authToken: string;
teamId: string;
}) {
return (
<div className="rounded-lg border border-border bg-card px-4 py-6 lg:px-6">
<div className="flex flex-col items-start justify-between max-sm:mb-5 lg:flex-row">
Expand All @@ -33,6 +39,7 @@ export function EcosystemPartnersSection({
ecosystem={ecosystem}
authToken={authToken}
teamSlug={teamSlug}
teamId={teamId}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
export function IntegrationPermissionsSection({
ecosystem,
authToken,
}: { ecosystem?: Ecosystem; authToken: string }) {
teamId,
}: { ecosystem?: Ecosystem; authToken: string; teamId: string }) {
return (
<div className="relative rounded-lg border border-border bg-card px-4 py-6 lg:px-6">
<h3 className="font-semibold text-xl tracking-tight">
Expand All @@ -27,6 +28,7 @@ export function IntegrationPermissionsSection({
<IntegrationPermissionsToggle
ecosystem={ecosystem}
authToken={authToken}
teamId={teamId}
/>
) : (
<IntegrationPermissionsToggleSkeleton />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ export function PartnersTable({
ecosystem,
authToken,
teamSlug,
teamId,
}: {
ecosystem: Ecosystem;
authToken: string;
teamSlug: string;
teamId: string;
}) {
const { partners, isPending } = usePartners({
ecosystem,
authToken,
teamId,
});

if (isPending) {
Expand Down Expand Up @@ -68,6 +71,7 @@ export function PartnersTable({
ecosystem={ecosystem}
authToken={authToken}
teamSlug={teamSlug}
teamId={teamId}
/>
))}
</TableBody>
Expand All @@ -81,12 +85,14 @@ function PartnerRow(props: {
ecosystem: Ecosystem;
teamSlug: string;
authToken: string;
teamId: string;
}) {
const router = useDashboardRouter();
const { mutateAsync: deletePartner, isPending: isDeleting } =
useDeletePartner(
{
authToken: props.authToken,
teamId: props.teamId,
},
{
onError: (error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ export async function fetchPartnerDetails(args: {
authToken: string;
ecosystem: Ecosystem;
partnerId: string;
teamId: string;
}): Promise<Partner> {
const { authToken, ecosystem, partnerId } = args;
const { authToken, ecosystem, partnerId, teamId } = args;

try {
const response = await fetch(
Expand All @@ -14,6 +15,7 @@ export async function fetchPartnerDetails(args: {
method: "GET",
headers: {
Authorization: `Bearer ${authToken}`,
"x-thirdweb-team-id": teamId,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import type { Ecosystem, Partner } from "../../../../types";
export async function fetchPartners({
ecosystem,
authToken,
teamId,
}: {
ecosystem: Ecosystem;
authToken: string;
teamId: string;
}): Promise<Partner[]> {
const res = await fetch(`${ecosystem.url}/${ecosystem.id}/partners`, {
headers: {
Authorization: `Bearer ${authToken}`,
"x-thirdweb-team-id": teamId,
},
next: {
revalidate: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ type AddPartnerParams = {
export function useAddPartner(
params: {
authToken: string;
teamId: string;
},
options?: Omit<
UseMutationOptions<Partner, unknown, AddPartnerParams>,
"mutationFn"
>,
) {
const { authToken } = params;
const { authToken, teamId } = params;
const { onSuccess, ...queryOptions } = options || {};
const queryClient = useQueryClient();

Expand All @@ -37,6 +38,7 @@ export function useAddPartner(
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
"x-thirdweb-team-id": teamId,
},
body: JSON.stringify({
name: params.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ type DeletePartnerParams = {
export function useDeletePartner(
params: {
authToken: string;
teamId: string;
},
options?: Omit<
UseMutationOptions<boolean, unknown, DeletePartnerParams>,
"mutationFn"
>,
) {
const { authToken } = params;
const { authToken, teamId } = params;
const { onSuccess, ...queryOptions } = options || {};
const queryClient = useQueryClient();

Expand All @@ -33,6 +34,7 @@ export function useDeletePartner(
{
method: "DELETE",
headers: {
"x-thirdweb-team-id": teamId,
Authorization: `Bearer ${authToken}`,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import type { Ecosystem } from "../../../../types";
export function useUpdateEcosystem(
params: {
authToken: string;
teamId: string;
},
options?: Omit<UseMutationOptions<boolean, unknown, Ecosystem>, "mutationFn">,
) {
const { authToken } = params;
const { authToken, teamId } = params;
const { onSuccess, ...queryOptions } = options || {};
const queryClient = useQueryClient();

Expand All @@ -22,6 +23,7 @@ export function useUpdateEcosystem(
method: "PATCH",
headers: {
"Content-Type": "application/json",
"x-thirdweb-team-id": teamId,
Authorization: `Bearer ${authToken}`,
},
body: JSON.stringify(params),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ type UpdatePartnerParams = {
export function useUpdatePartner(
params: {
authToken: string;
teamId: string;
},
options?: Omit<
UseMutationOptions<Partner, unknown, UpdatePartnerParams>,
"mutationFn"
>,
) {
const { authToken } = params;
const { authToken, teamId } = params;
const { onSuccess, ...queryOptions } = options || {};
const queryClient = useQueryClient();

Expand All @@ -43,6 +44,7 @@ export function useUpdatePartner(
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken}`,
"x-thirdweb-team-id": teamId,
},
body: JSON.stringify({
name: params.name,
Expand Down
Loading