From 65309cbc0c678501bf6e453ca31d1ff1e05a14b8 Mon Sep 17 00:00:00 2001 From: Manan Tank Date: Sun, 22 Sep 2024 03:55:01 +0530 Subject: [PATCH] Remove permissions form field in ecosystem partners page + UI adjusments --- .../client/AddPartnerDialogButton.tsx | 41 ++++++ .../client/add-partner-form.client.tsx | 120 +++++------------- .../client/update-partner-form.client.tsx | 114 +++++------------ .../client/update-partner-modal.client.tsx | 7 +- .../server/ecosystem-partners-section.tsx | 28 ++-- .../components/server/partners-table.tsx | 10 +- .../ecosystem/[slug]/(active)/constants.ts | 8 -- .../[slug]/(active)/hooks/use-add-partner.ts | 4 +- .../(active)/hooks/use-update-partner.ts | 2 - .../ecosystem/[slug]/(active)/utils.ts | 6 - .../dashboard/connect/ecosystem/types.ts | 2 +- apps/dashboard/src/app/(dashboard)/layout.tsx | 2 +- 12 files changed, 126 insertions(+), 218 deletions(-) create mode 100644 apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/AddPartnerDialogButton.tsx delete mode 100644 apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/utils.ts diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/AddPartnerDialogButton.tsx b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/AddPartnerDialogButton.tsx new file mode 100644 index 00000000000..df82c47c78d --- /dev/null +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/AddPartnerDialogButton.tsx @@ -0,0 +1,41 @@ +"use client"; + +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { PlusIcon } from "lucide-react"; +import { useState } from "react"; +import type { Ecosystem } from "../../../../types"; +import { AddPartnerForm } from "./add-partner-form.client"; + +export function AddPartnerDialogButton(props: { + ecosystem: Ecosystem; +}) { + const [open, setOpen] = useState(false); + return ( + + + + + + + + Add Partner + + + setOpen(false)} + /> + + + ); +} diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/add-partner-form.client.tsx b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/add-partner-form.client.tsx index 92777a603d4..ee0db640973 100644 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/add-partner-form.client.tsx +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/add-partner-form.client.tsx @@ -1,4 +1,5 @@ "use client"; +import { Spinner } from "@/components/ui/Spinner/Spinner"; import { Button } from "@/components/ui/button"; import { Form, @@ -6,17 +7,10 @@ import { FormDescription, FormField, FormItem, + FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; -import { ToolTipLabel } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; @@ -26,14 +20,17 @@ import type { Ecosystem } from "../../../../types"; import { partnerFormSchema } from "../../constants"; import { useAddPartner } from "../../hooks/use-add-partner"; -export function AddPartnerForm({ ecosystem }: { ecosystem: Ecosystem }) { +export function AddPartnerForm({ + ecosystem, + onPartnerAdded, +}: { ecosystem: Ecosystem; onPartnerAdded: () => void }) { const form = useForm>({ resolver: zodResolver(partnerFormSchema), }); const { mutateAsync: addPartner, isPending } = useAddPartner({ onSuccess: () => { - form.reset(); + onPartnerAdded(); }, onError: (error) => { const message = @@ -57,18 +54,18 @@ export function AddPartnerForm({ ecosystem }: { ecosystem: Ecosystem }) { allowlistedBundleIds: values.bundleIds .split(/,| /) .filter((d) => d.length > 0), - permissions: [values.permissions], }); })} - className="flex flex-col gap-2 lg:flex-row" + className="flex flex-col gap-6" > -
+
( - + + App Name ( - + + Domains - <> - - - {form.formState.errors.domains?.message ?? - "Space or comma-separated list of regex domains (e.g. *.example.com)"} - - + + + + Space or comma-separated list of regex domains (e.g. + *.example.com) + )} /> @@ -118,75 +109,24 @@ export function AddPartnerForm({ ecosystem }: { ecosystem: Ecosystem }) { name="bundleIds" defaultValue="" // Note: you *must* provide a default value here or the field won't reset render={({ field }) => ( - + + Bundle ID - <> - - - {form.formState.errors.bundleIds?.message ?? - "Space or comma-separated list of bundle IDs"} - - + - - - )} - /> - ( - - + + Space or comma-separated list of bundle IDs + + + )} />
- diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-form.client.tsx b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-form.client.tsx index cb7f59e1991..f6cb23a77bc 100644 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-form.client.tsx +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-form.client.tsx @@ -1,4 +1,5 @@ "use client"; +import { Spinner } from "@/components/ui/Spinner/Spinner"; import { Button } from "@/components/ui/button"; import { Form, @@ -6,20 +7,12 @@ import { FormDescription, FormField, FormItem, + FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; -import { ToolTipLabel } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; -import { Loader2 } from "lucide-react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import type { z } from "zod"; @@ -38,7 +31,6 @@ export function UpdatePartnerForm({ name: partner.name, domains: partner.allowlistedDomains.join(","), bundleIds: partner.allowlistedBundleIds.join(","), - permissions: partner.permissions[0], }, }); @@ -70,18 +62,18 @@ export function UpdatePartnerForm({ allowlistedBundleIds: values.bundleIds .split(/,| /) .filter((d) => d.length > 0), - permissions: [values.permissions], }); })} className="flex flex-col gap-4" > -
+
( + Name ( + Domains - <> - - - {form.formState.errors.domains?.message ?? - "Space or comma-separated list of regex domains (e.g. *.example.com)"} - - + + + {form.formState.errors.domains?.message ?? + "Space or comma-separated list of regex domains (e.g. *.example.com)"} + )} /> @@ -132,75 +123,32 @@ export function UpdatePartnerForm({ defaultValue="" // Note: you *must* provide a default value here or the field won't reset render={({ field }) => ( + Bundle ID - <> - - - {form.formState.errors.bundleIds?.message ?? - "Space or comma-separated list of bundle IDs"} - - + - - - )} - /> - ( - - + {form.formState.errors.bundleIds?.message ?? + "Space or comma-separated list of bundle IDs"} + + )} />
+ diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-modal.client.tsx b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-modal.client.tsx index f58c8213ac6..17ec8494123 100644 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-modal.client.tsx +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/client/update-partner-modal.client.tsx @@ -20,11 +20,8 @@ export function UpdatePartnerModal({ return ( {children} - - + + Update {partner.name} -
-

- Ecosystem partners -

-

- Configure apps that can use your wallet. Creating a partner will - generate a unique partner ID that can access your ecosystem. You will - need to generate at least one partner ID for use in your own app. -

+
+
+
+

+ Ecosystem partners +

+

+ Configure apps that can use your wallet. Creating a partner will + generate a unique partner ID that can access your ecosystem.
{" "} + You will need to generate at least one partner ID for use in your + own app. +

+
+ +
-
); diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/server/partners-table.tsx b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/server/partners-table.tsx index d884c31d0d0..3b864daaddf 100644 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/server/partners-table.tsx +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/components/server/partners-table.tsx @@ -44,9 +44,7 @@ export function PartnersTable({ ecosystem }: { ecosystem: Ecosystem }) { Domains Bundle ID Partner ID - - Wallet Prompts - + {/* Empty space for delete button */} @@ -108,11 +106,7 @@ function PartnerRow(props: {
- - {props.partner.permissions.includes("PROMPT_USER_V1") - ? "Prompt user" - : "Never prompt"} - +
d.length > 0) .join(","), ), - permissions: z.custom( - (value) => isValidPermission(value), - { - message: "Invalid permissions setting", - }, - ), }); diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-add-partner.ts b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-add-partner.ts index aacdf298c80..509c2503f29 100644 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-add-partner.ts +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-add-partner.ts @@ -11,7 +11,6 @@ type AddPartnerParams = { name: string; allowlistedDomains: string[]; allowlistedBundleIds: string[]; - permissions: ["PROMPT_USER_V1" | "FULL_CONTROL_V1"]; }; export function useAddPartner( @@ -44,7 +43,8 @@ export function useAddPartner( name: params.name, allowlistedDomains: params.allowlistedDomains, allowlistedBundleIds: params.allowlistedBundleIds, - permissions: params.permissions, + // TODO - remove the requirement for permissions in API endpoint + permissions: ["FULL_CONTROL_V1"], }), }, ); diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-update-partner.ts b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-update-partner.ts index d74750501ef..74f47e80886 100644 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-update-partner.ts +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/hooks/use-update-partner.ts @@ -12,7 +12,6 @@ type UpdatePartnerParams = { name: string; allowlistedDomains: string[]; allowlistedBundleIds: string[]; - permissions: ["PROMPT_USER_V1" | "FULL_CONTROL_V1"]; }; export function useUpdatePartner( @@ -45,7 +44,6 @@ export function useUpdatePartner( name: params.name, allowlistedDomains: params.allowlistedDomains, allowlistedBundleIds: params.allowlistedBundleIds, - permissions: params.permissions, }), }, ); diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/utils.ts b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/utils.ts deleted file mode 100644 index 435e219604a..00000000000 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/[slug]/(active)/utils.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { PartnerPermission } from "../../types.ts"; - -export const isValidPermission = ( - permission: string, -): permission is PartnerPermission => - ["FULL_CONTROL_V1", "PROMPT_USER_V1"].includes(permission); diff --git a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/types.ts b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/types.ts index d9e8ce55be2..e72a222a4fa 100644 --- a/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/types.ts +++ b/apps/dashboard/src/app/(dashboard)/dashboard/connect/ecosystem/types.ts @@ -11,7 +11,7 @@ export type Ecosystem = { updatedAt: string; }; -export type PartnerPermission = "PROMPT_USER_V1" | "FULL_CONTROL_V1"; +type PartnerPermission = "PROMPT_USER_V1" | "FULL_CONTROL_V1"; export type Partner = { id: string; name: string; diff --git a/apps/dashboard/src/app/(dashboard)/layout.tsx b/apps/dashboard/src/app/(dashboard)/layout.tsx index 5e401b5ce1d..d228dd56ba2 100644 --- a/apps/dashboard/src/app/(dashboard)/layout.tsx +++ b/apps/dashboard/src/app/(dashboard)/layout.tsx @@ -5,7 +5,7 @@ import { ErrorProvider } from "../../contexts/error-handler"; export default function DashboardLayout(props: { children: React.ReactNode }) { return ( -
+
{props.children}