1
1
"use client" ;
2
+ import { Spinner } from "@/components/ui/Spinner/Spinner" ;
2
3
import { Button } from "@/components/ui/button" ;
3
4
import {
4
5
Form ,
5
6
FormControl ,
6
7
FormDescription ,
7
8
FormField ,
8
9
FormItem ,
10
+ FormLabel ,
9
11
FormMessage ,
10
12
} from "@/components/ui/form" ;
11
13
import { Input } from "@/components/ui/input" ;
12
- import {
13
- Select ,
14
- SelectContent ,
15
- SelectItem ,
16
- SelectTrigger ,
17
- SelectValue ,
18
- } from "@/components/ui/select" ;
19
- import { ToolTipLabel } from "@/components/ui/tooltip" ;
20
14
import { cn } from "@/lib/utils" ;
21
15
import { zodResolver } from "@hookform/resolvers/zod" ;
22
16
import { useForm } from "react-hook-form" ;
@@ -26,14 +20,17 @@ import type { Ecosystem } from "../../../../types";
26
20
import { partnerFormSchema } from "../../constants" ;
27
21
import { useAddPartner } from "../../hooks/use-add-partner" ;
28
22
29
- export function AddPartnerForm ( { ecosystem } : { ecosystem : Ecosystem } ) {
23
+ export function AddPartnerForm ( {
24
+ ecosystem,
25
+ onPartnerAdded,
26
+ } : { ecosystem : Ecosystem ; onPartnerAdded : ( ) => void } ) {
30
27
const form = useForm < z . input < typeof partnerFormSchema > > ( {
31
28
resolver : zodResolver ( partnerFormSchema ) ,
32
29
} ) ;
33
30
34
31
const { mutateAsync : addPartner , isPending } = useAddPartner ( {
35
32
onSuccess : ( ) => {
36
- form . reset ( ) ;
33
+ onPartnerAdded ( ) ;
37
34
} ,
38
35
onError : ( error ) => {
39
36
const message =
@@ -57,18 +54,18 @@ export function AddPartnerForm({ ecosystem }: { ecosystem: Ecosystem }) {
57
54
allowlistedBundleIds : values . bundleIds
58
55
. split ( / , | / )
59
56
. filter ( ( d ) => d . length > 0 ) ,
60
- permissions : [ values . permissions ] ,
61
57
} ) ;
62
58
} ) }
63
- className = "flex flex-col gap-2 lg:flex-row "
59
+ className = "flex flex-col gap-6 "
64
60
>
65
- < div className = "grid gap-2 lg:grid-cols-12 grow " >
61
+ < div className = "flex flex-col gap-4 " >
66
62
< FormField
67
63
control = { form . control }
68
64
name = "name"
69
65
defaultValue = "" // Note: you *must* provide a default value here or the field won't reset
70
66
render = { ( { field } ) => (
71
- < FormItem className = "col-span-4 lg:col-span-3" >
67
+ < FormItem >
68
+ < FormLabel > App Name </ FormLabel >
72
69
< FormControl >
73
70
< Input
74
71
placeholder = "App name"
@@ -94,22 +91,16 @@ export function AddPartnerForm({ ecosystem }: { ecosystem: Ecosystem }) {
94
91
name = "domains"
95
92
defaultValue = "" // Note: you *must* provide a default value here or the field won't reset
96
93
render = { ( { field } ) => (
97
- < FormItem className = "col-span-4 lg:col-span-4" >
94
+ < FormItem >
95
+ < FormLabel > Domains </ FormLabel >
98
96
< FormControl >
99
- < >
100
- < Input placeholder = "Domains" className = "peer" { ...field } />
101
- < FormDescription
102
- className = { cn (
103
- "hidden text-xs transition-all lg:block lg:-translate-y-4 lg:opacity-0 peer-focus-visible:opacity-100 peer-focus-visible:translate-y-0" ,
104
- form . formState . errors . domains ?. message &&
105
- "text-destructive lg:translate-y-0 lg:opacity-100 block" , // If there are errors show them rather than the tip
106
- ) }
107
- >
108
- { form . formState . errors . domains ?. message ??
109
- "Space or comma-separated list of regex domains (e.g. *.example.com)" }
110
- </ FormDescription >
111
- </ >
97
+ < Input placeholder = "Domains" className = "peer" { ...field } />
112
98
</ FormControl >
99
+
100
+ < FormDescription >
101
+ Space or comma-separated list of regex domains (e.g.
102
+ *.example.com)
103
+ </ FormDescription >
113
104
</ FormItem >
114
105
) }
115
106
/>
@@ -118,75 +109,24 @@ export function AddPartnerForm({ ecosystem }: { ecosystem: Ecosystem }) {
118
109
name = "bundleIds"
119
110
defaultValue = "" // Note: you *must* provide a default value here or the field won't reset
120
111
render = { ( { field } ) => (
121
- < FormItem className = "col-span-4 lg:col-span-3" >
112
+ < FormItem >
113
+ < FormLabel > Bundle ID </ FormLabel >
122
114
< FormControl >
123
- < >
124
- < Input
125
- placeholder = "Bundle ID"
126
- className = "peer"
127
- { ...field }
128
- />
129
- < FormDescription
130
- className = { cn (
131
- "hidden text-xs transition-all lg:block lg:-translate-y-4 lg:opacity-0 peer-focus-visible:opacity-100 peer-focus-visible:translate-y-0" ,
132
- form . formState . errors . bundleIds ?. message &&
133
- "text-destructive translate-y-0 opacity-100 block" ,
134
- ) }
135
- >
136
- { form . formState . errors . bundleIds ?. message ??
137
- "Space or comma-separated list of bundle IDs" }
138
- </ FormDescription >
139
- </ >
115
+ < Input placeholder = "Bundle ID" className = "peer" { ...field } />
140
116
</ FormControl >
141
- < FormMessage />
142
- </ FormItem >
143
- ) }
144
- />
145
- < FormField
146
- control = { form . control }
147
- name = "permissions"
148
- defaultValue = "PROMPT_USER_V1" // Note: you *must* provide a default value here or the field won't reset
149
- render = { ( { field } ) => (
150
- < FormItem className = "col-span-4 lg:col-span-2" >
151
- < Select
152
- onValueChange = { field . onChange }
153
- defaultValue = { field . value }
154
- >
155
- < ToolTipLabel label = "Should wallet actions prompt the user for approval?" >
156
- < FormControl >
157
- < SelectTrigger className = "w-full" >
158
- < SelectValue placeholder = "Wallet prompts" />
159
- </ SelectTrigger >
160
- </ FormControl >
161
- </ ToolTipLabel >
162
- < SelectContent >
163
- < SelectItem value = "FULL_CONTROL_V1" >
164
- Never prompt
165
- </ SelectItem >
166
- < SelectItem value = "PROMPT_USER_V1" > Prompt user</ SelectItem >
167
- </ SelectContent >
168
117
169
- < FormDescription
170
- className = { cn (
171
- "hidden text-xs transition-all lg:block lg:-translate-y-4 lg:opacity-0 peer-focus-visible:opacity-100 peer-focus-visible:translate-y-0" ,
172
- form . formState . errors . permissions ?. message &&
173
- "text-destructive lg:translate-y-0 lg:opacity-100 block" , // If there are errors show them rather than the tip
174
- ) }
175
- >
176
- { form . formState . errors . permissions ?. message ??
177
- "Wallet signing" }
178
- </ FormDescription >
179
- </ Select >
118
+ < FormDescription >
119
+ Space or comma-separated list of bundle IDs
120
+ </ FormDescription >
121
+
122
+ < FormMessage />
180
123
</ FormItem >
181
124
) }
182
125
/>
183
126
</ div >
184
- < Button
185
- disabled = { isPending }
186
- type = "submit"
187
- variant = "outline"
188
- className = "w-full lg:w-auto"
189
- >
127
+
128
+ < Button disabled = { isPending } type = "submit" className = "w-full gap-2" >
129
+ { isPending && < Spinner className = "size-4" /> }
190
130
Add
191
131
</ Button >
192
132
</ form >
0 commit comments