mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-06 21:56:03 +02:00
🐛 Fix race condition (#1625)
This commit is contained in:
parent
e777e673a3
commit
dd719620ff
2 changed files with 10 additions and 14 deletions
|
@ -69,13 +69,6 @@ export const CreatePoll: React.FunctionComponent = () => {
|
|||
const posthog = usePostHog();
|
||||
const createPoll = trpc.polls.create.useMutation({
|
||||
networkMode: "always",
|
||||
onMutate: async () => {
|
||||
if (session.status !== "authenticated") {
|
||||
await signIn("guest", {
|
||||
redirect: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
if (error.data?.code === "BAD_REQUEST") {
|
||||
toast({
|
||||
|
@ -91,6 +84,11 @@ export const CreatePoll: React.FunctionComponent = () => {
|
|||
<form
|
||||
onSubmit={form.handleSubmit(async (formData) => {
|
||||
const title = required(formData?.title);
|
||||
if (session.status !== "authenticated") {
|
||||
await signIn("guest", {
|
||||
redirect: false,
|
||||
});
|
||||
}
|
||||
await createPoll.mutateAsync(
|
||||
{
|
||||
title: title,
|
||||
|
|
|
@ -84,13 +84,6 @@ function NewCommentForm({
|
|||
const { toast } = useToast();
|
||||
|
||||
const addComment = trpc.polls.comments.add.useMutation({
|
||||
onMutate: async () => {
|
||||
if (session.status !== "authenticated") {
|
||||
await signIn("guest", {
|
||||
redirect: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
posthog?.capture("created comment");
|
||||
},
|
||||
|
@ -105,6 +98,11 @@ function NewCommentForm({
|
|||
<form
|
||||
className="w-full space-y-2.5"
|
||||
onSubmit={handleSubmit(async ({ authorName, content }) => {
|
||||
if (session.status !== "authenticated") {
|
||||
await signIn("guest", {
|
||||
redirect: false,
|
||||
});
|
||||
}
|
||||
await addComment.mutateAsync({ authorName, content, pollId });
|
||||
reset({ authorName, content: "" });
|
||||
onSubmit?.();
|
||||
|
|
Loading…
Add table
Reference in a new issue