@@ -24,7 +24,6 @@ import { zodResolver } from "@hookform/resolvers/zod";
24
24
import { useMutation } from "@tanstack/react-query" ;
25
25
import { ExternalLinkIcon , PlusIcon , Trash2Icon , UserPlus } from "lucide-react" ;
26
26
import Link from "next/link" ;
27
- import { useEffect } from "react" ;
28
27
import { useForm } from "react-hook-form" ;
29
28
import { toast } from "sonner" ;
30
29
import { z } from "zod" ;
@@ -216,19 +215,15 @@ export function InviteSection(props: {
216
215
} ) ;
217
216
}
218
217
219
- // eslint-disable-next-line no-restricted-syntax
220
- useEffect ( ( ) => {
221
- // when form updates - reset mutation result
222
- const subscription = form . watch ( ( ) => {
223
- sendInvites . reset ( ) ;
224
- } ) ;
225
-
226
- return ( ) => subscription . unsubscribe ( ) ;
227
- } , [ form . watch , sendInvites . reset ] ) ;
228
-
229
218
return (
230
219
< Form { ...form } >
231
- < form onSubmit = { form . handleSubmit ( onSubmit ) } >
220
+ < form
221
+ onSubmit = { form . handleSubmit ( onSubmit ) }
222
+ onChange = { ( ) => {
223
+ // when form updates - reset mutation result
224
+ sendInvites . reset ( ) ;
225
+ } }
226
+ >
232
227
< section >
233
228
< div
234
229
className = { cn (
@@ -338,26 +333,42 @@ export function InviteSection(props: {
338
333
) ) }
339
334
</ div >
340
335
341
- < Button
342
- type = "button"
343
- variant = "outline"
344
- size = "sm"
345
- className = "mt-4 gap-2"
346
- disabled = {
347
- ! inviteEnabled ||
348
- form . watch ( "invites" ) . length >= maxAllowedInvitesAtOnce
349
- }
350
- onClick = { ( ) => {
351
- const currentInvites = form . watch ( "invites" ) ;
352
- form . setValue ( "invites" , [
353
- ...currentInvites ,
354
- { email : "" , role : "MEMBER" } ,
355
- ] ) ;
356
- } }
357
- >
358
- < PlusIcon className = "size-4" />
359
- Add Another
360
- </ Button >
336
+ < div className = "mt-6 flex gap-3" >
337
+ < Button
338
+ type = "button"
339
+ variant = "outline"
340
+ size = "sm"
341
+ className = "gap-2"
342
+ disabled = {
343
+ ! inviteEnabled ||
344
+ form . watch ( "invites" ) . length >= maxAllowedInvitesAtOnce
345
+ }
346
+ onClick = { ( ) => {
347
+ const currentInvites = form . watch ( "invites" ) ;
348
+ form . setValue ( "invites" , [
349
+ ...currentInvites ,
350
+ { email : "" , role : "MEMBER" } ,
351
+ ] ) ;
352
+ } }
353
+ >
354
+ < PlusIcon className = "size-4" />
355
+ Add Another
356
+ </ Button >
357
+
358
+ < Button
359
+ type = "button"
360
+ variant = "outline"
361
+ size = "sm"
362
+ disabled = { ! form . formState . isDirty }
363
+ className = "gap-2"
364
+ onClick = { ( ) => {
365
+ form . reset ( ) ;
366
+ sendInvites . reset ( ) ;
367
+ } }
368
+ >
369
+ Reset
370
+ </ Button >
371
+ </ div >
361
372
</ div >
362
373
{ bottomSection }
363
374
</ div >
0 commit comments