Skip to content

Commit 2b39c5d

Browse files
committed
Dashboard: Fix team invite UI not showing feedback on submit
1 parent d568f8f commit 2b39c5d

File tree

1 file changed

+43
-32
lines changed
  • apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/members

1 file changed

+43
-32
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/members/InviteSection.tsx

+43-32
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { zodResolver } from "@hookform/resolvers/zod";
2424
import { useMutation } from "@tanstack/react-query";
2525
import { ExternalLinkIcon, PlusIcon, Trash2Icon, UserPlus } from "lucide-react";
2626
import Link from "next/link";
27-
import { useEffect } from "react";
2827
import { useForm } from "react-hook-form";
2928
import { toast } from "sonner";
3029
import { z } from "zod";
@@ -216,19 +215,15 @@ 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+
sendInvites.reset();
225+
}}
226+
>
232227
<section>
233228
<div
234229
className={cn(
@@ -338,26 +333,42 @@ export function InviteSection(props: {
338333
))}
339334
</div>
340335

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>
361372
</div>
362373
{bottomSection}
363374
</div>

0 commit comments

Comments
 (0)