@@ -24,7 +24,6 @@ import { zodResolver } from "@hookform/resolvers/zod";
2424import { useMutation } from "@tanstack/react-query" ;
2525import { ExternalLinkIcon , PlusIcon , Trash2Icon , UserPlus } from "lucide-react" ;
2626import Link from "next/link" ;
27- import { useEffect } from "react" ;
2827import { useForm } from "react-hook-form" ;
2928import { toast } from "sonner" ;
3029import { z } from "zod" ;
@@ -216,19 +215,17 @@ export function InviteSection(props: {
216215 } ) ;
217216 }
218217
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-
229218 return (
230219 < 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+ >
232229 < section >
233230 < div
234231 className = { cn (
@@ -338,26 +335,42 @@ export function InviteSection(props: {
338335 ) ) }
339336 </ div >
340337
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 >
361374 </ div >
362375 { bottomSection }
363376 </ div >
0 commit comments