@@ -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,17 @@ 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
+ if ( sendInvites . data ) {
225
+ sendInvites . reset ( ) ;
226
+ }
227
+ } }
228
+ >
232
229
< section >
233
230
< div
234
231
className = { cn (
@@ -338,26 +335,42 @@ export function InviteSection(props: {
338
335
) ) }
339
336
</ div >
340
337
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 >
338
+ < div className = "mt-6 flex gap-3" >
339
+ < Button
340
+ type = "button"
341
+ variant = "outline"
342
+ size = "sm"
343
+ className = "gap-2"
344
+ disabled = {
345
+ ! inviteEnabled ||
346
+ form . watch ( "invites" ) . length >= maxAllowedInvitesAtOnce
347
+ }
348
+ onClick = { ( ) => {
349
+ const currentInvites = form . watch ( "invites" ) ;
350
+ form . setValue ( "invites" , [
351
+ ...currentInvites ,
352
+ { email : "" , role : "MEMBER" } ,
353
+ ] ) ;
354
+ } }
355
+ >
356
+ < PlusIcon className = "size-4" />
357
+ Add Another
358
+ </ Button >
359
+
360
+ < Button
361
+ type = "button"
362
+ variant = "outline"
363
+ size = "sm"
364
+ disabled = { ! form . formState . isDirty }
365
+ className = "gap-2"
366
+ onClick = { ( ) => {
367
+ form . reset ( ) ;
368
+ sendInvites . reset ( ) ;
369
+ } }
370
+ >
371
+ Reset
372
+ </ Button >
373
+ </ div >
361
374
</ div >
362
375
{ bottomSection }
363
376
</ div >
0 commit comments