Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🐛 Fix possible race condition when adding new participant (#1617)
Luke Vellabb8a7f410210
diff --git a/apps/web/src/components/new-participant-modal.tsx b/apps/web/src/components/new-participant-modal.tsxindex 3a0cc942c..c15a234f8 100644--- a/apps/web/src/components/new-participant-modal.tsx+++ b/apps/web/src/components/new-participant-modal.tsx@@ -7,6 +7,7 @@ import { FormMessage } from "@rallly/ui/form";import { Input } from "@rallly/ui/input";import * as Sentry from "@sentry/nextjs";import { TRPCClientError } from "@trpc/client";+import { signIn, useSession } from "next-auth/react";import { useForm } from "react-hook-form";import z from "zod";@@ -91,6 +92,7 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {const isEmailRequired = poll.requireParticipantEmail;const { user } = useUser();+ const session = useSession();const isLoggedIn = !user.isGuest;const { register, setError, formState, handleSubmit } =useForm<NewParticipantFormData>({@@ -111,6 +113,11 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {<formonSubmit={handleSubmit(async (data) => {try {+ if (session.status !== "authenticated") {+ await signIn("guest", {+ redirect: false,+ });+ }const newParticipant = await addParticipant.mutateAsync({name: data.name,votes: props.votes,diff --git a/apps/web/src/components/poll/mutations.ts b/apps/web/src/components/poll/mutations.tsindex 430911a27..edc546f17 100644--- a/apps/web/src/components/poll/mutations.ts+++ b/apps/web/src/components/poll/mutations.ts@@ -1,6 +1,5 @@import { usePostHog } from "@rallly/posthog/client";import { useToast } from "@rallly/ui/hooks/use-toast";-import { signIn, useSession } from "next-auth/react";import { usePoll } from "@/components/poll-context";import { trpc } from "@/trpc/client";@@ -20,15 +19,7 @@ export const normalizeVotes = (export const useAddParticipantMutation = () => {const posthog = usePostHog();const queryClient = trpc.useUtils();- const session = useSession();return trpc.polls.participants.add.useMutation({- onMutate: async () => {- if (session.status !== "authenticated") {- await signIn("guest", {- redirect: false,- });- }- },onSuccess: async (newParticipant, input) => {const { pollId, name, email } = newParticipant;queryClient.polls.participants.list.setData(