mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-07 14:16:01 +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 posthog = usePostHog();
|
||||||
const createPoll = trpc.polls.create.useMutation({
|
const createPoll = trpc.polls.create.useMutation({
|
||||||
networkMode: "always",
|
networkMode: "always",
|
||||||
onMutate: async () => {
|
|
||||||
if (session.status !== "authenticated") {
|
|
||||||
await signIn("guest", {
|
|
||||||
redirect: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
if (error.data?.code === "BAD_REQUEST") {
|
if (error.data?.code === "BAD_REQUEST") {
|
||||||
toast({
|
toast({
|
||||||
|
@ -91,6 +84,11 @@ export const CreatePoll: React.FunctionComponent = () => {
|
||||||
<form
|
<form
|
||||||
onSubmit={form.handleSubmit(async (formData) => {
|
onSubmit={form.handleSubmit(async (formData) => {
|
||||||
const title = required(formData?.title);
|
const title = required(formData?.title);
|
||||||
|
if (session.status !== "authenticated") {
|
||||||
|
await signIn("guest", {
|
||||||
|
redirect: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
await createPoll.mutateAsync(
|
await createPoll.mutateAsync(
|
||||||
{
|
{
|
||||||
title: title,
|
title: title,
|
||||||
|
|
|
@ -84,13 +84,6 @@ function NewCommentForm({
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const addComment = trpc.polls.comments.add.useMutation({
|
const addComment = trpc.polls.comments.add.useMutation({
|
||||||
onMutate: async () => {
|
|
||||||
if (session.status !== "authenticated") {
|
|
||||||
await signIn("guest", {
|
|
||||||
redirect: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
posthog?.capture("created comment");
|
posthog?.capture("created comment");
|
||||||
},
|
},
|
||||||
|
@ -105,6 +98,11 @@ function NewCommentForm({
|
||||||
<form
|
<form
|
||||||
className="w-full space-y-2.5"
|
className="w-full space-y-2.5"
|
||||||
onSubmit={handleSubmit(async ({ authorName, content }) => {
|
onSubmit={handleSubmit(async ({ authorName, content }) => {
|
||||||
|
if (session.status !== "authenticated") {
|
||||||
|
await signIn("guest", {
|
||||||
|
redirect: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
await addComment.mutateAsync({ authorName, content, pollId });
|
await addComment.mutateAsync({ authorName, content, pollId });
|
||||||
reset({ authorName, content: "" });
|
reset({ authorName, content: "" });
|
||||||
onSubmit?.();
|
onSubmit?.();
|
||||||
|
|
Loading…
Add table
Reference in a new issue