Skip to content

Commit cbc3bf1

Browse files
[Dashboard] feat: Add allowed operations to partner access control (#6478)
1 parent 20ead11 commit cbc3bf1

18 files changed

+1363
-233
lines changed

apps/dashboard/src/app/account/settings/getAccount.ts

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export async function getRawAccount() {
2222
},
2323
});
2424

25+
if (!res.ok) {
26+
console.error("Error fetching account", res.status, res.statusText);
27+
return undefined;
28+
}
29+
2530
const json = await res.json();
2631

2732
if (json.error) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {} from "@/components/ui/breadcrumb";
2+
import { getAuthToken } from "../../../../../../../../../api/lib/getAuthToken";
3+
import { loginRedirect } from "../../../../../../../../../login/loginRedirect";
4+
import { AddPartnerForm } from "../components/client/add-partner-form.client";
5+
import { fetchEcosystem } from "../hooks/fetchEcosystem";
6+
7+
export default async function AddPartnerPage({
8+
params,
9+
}: {
10+
params: Promise<{ slug: string; team_slug: string }>;
11+
}) {
12+
const { slug, team_slug } = await params;
13+
const authToken = await getAuthToken();
14+
15+
if (!authToken) {
16+
loginRedirect(`/team/${team_slug}/~/ecosystem/${slug}`);
17+
}
18+
19+
const teamSlug = team_slug;
20+
const ecosystemSlug = slug;
21+
22+
try {
23+
const ecosystem = await fetchEcosystem({
24+
teamIdOrSlug: teamSlug,
25+
slug: ecosystemSlug,
26+
authToken,
27+
});
28+
29+
return (
30+
<div className="flex flex-col">
31+
<div className="container">
32+
<h1 className="mb-6 font-semibold text-2xl tracking-tight">
33+
Add New Partner
34+
</h1>
35+
<AddPartnerForm ecosystem={ecosystem} authToken={authToken} />
36+
</div>
37+
</div>
38+
);
39+
} catch (error) {
40+
console.error("Error fetching ecosystem:", error);
41+
return (
42+
<div className="container py-8">
43+
<div className="mx-auto max-w-3xl">
44+
<h1 className="mb-6 font-semibold text-2xl tracking-tight">Error</h1>
45+
<p>Could not load ecosystem. Please try again.</p>
46+
</div>
47+
</div>
48+
);
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,23 @@
11
"use client";
22

33
import { Button } from "@/components/ui/button";
4-
import {
5-
Dialog,
6-
DialogContent,
7-
DialogHeader,
8-
DialogTitle,
9-
DialogTrigger,
10-
} from "@/components/ui/dialog";
114
import { PlusIcon } from "lucide-react";
12-
import { useState } from "react";
5+
import Link from "next/link";
136
import type { Ecosystem } from "../../../../../types";
14-
import { AddPartnerForm } from "./add-partner-form.client";
157

168
export function AddPartnerDialogButton(props: {
9+
teamSlug: string;
1710
ecosystem: Ecosystem;
1811
authToken: string;
1912
}) {
20-
const [open, setOpen] = useState(false);
13+
const addPartnerUrl = `/team/${props.teamSlug}/~/ecosystem/${props.ecosystem.slug}/configuration/add-partner`;
14+
2115
return (
22-
<Dialog open={open} onOpenChange={setOpen}>
23-
<DialogTrigger asChild>
24-
<Button className="gap-2 max-sm:w-full" variant="outline" size="sm">
25-
<PlusIcon className="size-4" />
26-
Add Partner
27-
</Button>
28-
</DialogTrigger>
29-
<DialogContent>
30-
<DialogHeader className="mb-2">
31-
<DialogTitle className="font-semibold text-2xl tracking-tight">
32-
Add Partner
33-
</DialogTitle>
34-
</DialogHeader>
35-
<AddPartnerForm
36-
ecosystem={props.ecosystem}
37-
onPartnerAdded={() => setOpen(false)}
38-
authToken={props.authToken}
39-
/>
40-
</DialogContent>
41-
</Dialog>
16+
<Link href={addPartnerUrl} passHref>
17+
<Button className="gap-2 max-sm:w-full" variant="outline" size="sm">
18+
<PlusIcon className="size-4" />
19+
Add Partner
20+
</Button>
21+
</Link>
4222
);
4323
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export function EcosystemPermissionsPage({
2121
/>
2222
<AuthOptionsSection ecosystem={ecosystem} authToken={authToken} />
2323
{ecosystem?.permission === "PARTNER_WHITELIST" && (
24-
<EcosystemPartnersSection ecosystem={ecosystem} authToken={authToken} />
24+
<EcosystemPartnersSection
25+
teamSlug={params.team_slug}
26+
ecosystem={ecosystem}
27+
authToken={authToken}
28+
/>
2529
)}
2630
</div>
2731
);

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1+
"use client";
2+
import { useDashboardRouter } from "@/lib/DashboardRouter";
3+
import { useParams } from "next/navigation";
14
import { toast } from "sonner";
25
import type { Ecosystem, Partner } from "../../../../../types";
36
import { useAddPartner } from "../../hooks/use-add-partner";
47
import { PartnerForm, type PartnerFormValues } from "./partner-form.client";
58

69
export function AddPartnerForm({
710
ecosystem,
8-
onPartnerAdded,
911
authToken,
1012
}: {
11-
authToken: string;
1213
ecosystem: Ecosystem;
13-
onPartnerAdded: () => void;
14+
authToken: string;
1415
}) {
16+
const router = useDashboardRouter();
17+
const params = useParams();
18+
const teamSlug = params.team_slug as string;
19+
const ecosystemSlug = params.slug as string;
20+
1521
const { mutateAsync: addPartner, isPending } = useAddPartner(
1622
{
1723
authToken,
1824
},
1925
{
2026
onSuccess: () => {
21-
onPartnerAdded();
27+
toast.success("Partner added successfully", {
28+
description: "The partner has been added to your ecosystem.",
29+
});
30+
31+
// Redirect to the redirect page that will take us back to the configuration page
32+
const redirectPath = `/team/${teamSlug}/~/ecosystem/${ecosystemSlug}`;
33+
router.push(redirectPath);
2234
},
2335
onError: (error) => {
2436
const message =

0 commit comments

Comments
 (0)