Skip to content

Commit 90010ee

Browse files
[Dashboard] feat: Add access control and server verifier to partner configuration (#6473)
1 parent 269fbe5 commit 90010ee

File tree

8 files changed

+504
-273
lines changed

8 files changed

+504
-273
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
1-
import { Spinner } from "@/components/ui/Spinner/Spinner";
2-
import { Button } from "@/components/ui/button";
3-
import {
4-
Form,
5-
FormControl,
6-
FormDescription,
7-
FormField,
8-
FormItem,
9-
FormLabel,
10-
FormMessage,
11-
} from "@/components/ui/form";
12-
import { Input } from "@/components/ui/input";
13-
import { cn } from "@/lib/utils";
14-
import { zodResolver } from "@hookform/resolvers/zod";
15-
import { useForm } from "react-hook-form";
161
import { toast } from "sonner";
17-
import type { z } from "zod";
18-
import type { Ecosystem } from "../../../../../types";
19-
import { partnerFormSchema } from "../../constants";
2+
import type { Ecosystem, Partner } from "../../../../../types";
203
import { useAddPartner } from "../../hooks/use-add-partner";
4+
import { PartnerForm, type PartnerFormValues } from "./partner-form.client";
215

226
export function AddPartnerForm({
237
ecosystem,
248
onPartnerAdded,
259
authToken,
26-
}: { authToken: string; ecosystem: Ecosystem; onPartnerAdded: () => void }) {
27-
const form = useForm<z.input<typeof partnerFormSchema>>({
28-
resolver: zodResolver(partnerFormSchema),
29-
});
30-
10+
}: {
11+
authToken: string;
12+
ecosystem: Ecosystem;
13+
onPartnerAdded: () => void;
14+
}) {
3115
const { mutateAsync: addPartner, isPending } = useAddPartner(
3216
{
3317
authToken,
@@ -46,95 +30,28 @@ export function AddPartnerForm({
4630
},
4731
);
4832

49-
return (
50-
<Form {...form}>
51-
<form
52-
onSubmit={form.handleSubmit((values) => {
53-
addPartner({
54-
ecosystem,
55-
name: values.name,
56-
allowlistedDomains: values.domains
57-
.split(/,| /)
58-
.filter((d) => d.length > 0),
59-
allowlistedBundleIds: values.bundleIds
60-
.split(/,| /)
61-
.filter((d) => d.length > 0),
62-
});
63-
})}
64-
className="flex flex-col gap-6"
65-
>
66-
<div className="flex flex-col gap-4">
67-
<FormField
68-
control={form.control}
69-
name="name"
70-
defaultValue="" // Note: you *must* provide a default value here or the field won't reset
71-
render={({ field }) => (
72-
<FormItem>
73-
<FormLabel> App Name </FormLabel>
74-
<FormControl>
75-
<Input
76-
placeholder="App name"
77-
{...field}
78-
value={field.value}
79-
/>
80-
</FormControl>
81-
<FormDescription
82-
className={cn(
83-
"text-xs transition-all",
84-
form.formState.errors.name?.message
85-
? "block translate-y-0 text-destructive opacity-100"
86-
: "lg:-translate-y-4 hidden opacity-0",
87-
)}
88-
>
89-
{form.formState.errors.name?.message}
90-
</FormDescription>
91-
</FormItem>
92-
)}
93-
/>
94-
<FormField
95-
control={form.control}
96-
name="domains"
97-
defaultValue="" // Note: you *must* provide a default value here or the field won't reset
98-
render={({ field }) => (
99-
<FormItem>
100-
<FormLabel> Domains </FormLabel>
101-
<FormControl>
102-
<Input placeholder="Domains" className="peer" {...field} />
103-
</FormControl>
104-
105-
<FormDescription>
106-
Space or comma-separated list of regex domains (e.g.
107-
*.example.com)
108-
</FormDescription>
109-
</FormItem>
110-
)}
111-
/>
112-
<FormField
113-
control={form.control}
114-
name="bundleIds"
115-
defaultValue="" // Note: you *must* provide a default value here or the field won't reset
116-
render={({ field }) => (
117-
<FormItem>
118-
<FormLabel> Bundle ID </FormLabel>
119-
<FormControl>
120-
<Input placeholder="Bundle ID" className="peer" {...field} />
121-
</FormControl>
33+
const handleSubmit = (
34+
values: PartnerFormValues,
35+
finalAccessControl: Partner["accessControl"] | null,
36+
) => {
37+
addPartner({
38+
ecosystem,
39+
name: values.name,
40+
allowlistedDomains: values.domains
41+
.split(/,| /)
42+
.filter((d) => d.length > 0),
43+
allowlistedBundleIds: values.bundleIds
44+
.split(/,| /)
45+
.filter((d) => d.length > 0),
46+
accessControl: finalAccessControl,
47+
});
48+
};
12249

123-
<FormDescription>
124-
Space or comma-separated list of bundle IDs
125-
</FormDescription>
126-
127-
<FormMessage />
128-
</FormItem>
129-
)}
130-
/>
131-
</div>
132-
133-
<Button disabled={isPending} type="submit" className="w-full gap-2">
134-
{isPending && <Spinner className="size-4" />}
135-
Add
136-
</Button>
137-
</form>
138-
</Form>
50+
return (
51+
<PartnerForm
52+
onSubmit={handleSubmit}
53+
isSubmitting={isPending}
54+
submitLabel="Add"
55+
/>
13956
);
14057
}

0 commit comments

Comments
 (0)