Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Require non-empty title when duplicating (#807)

Luke Vella1c44b3954bab
diff --git a/apps/web/src/pages/poll/[urlId]/duplicate.tsx b/apps/web/src/pages/poll/[urlId]/duplicate.tsx
index 63da03d58..63c6ed44d 100644
--- a/apps/web/src/pages/poll/[urlId]/duplicate.tsx
+++ b/apps/web/src/pages/poll/[urlId]/duplicate.tsx
@@ -1,3 +1,4 @@
+import { zodResolver } from "@hookform/resolvers/zod";
import { trpc } from "@rallly/backend";
import { Button } from "@rallly/ui/button";
import {
@@ -19,22 +20,29 @@ import { Input } from "@rallly/ui/input";
import Link from "next/link";
import { useRouter } from "next/router";
import { useForm } from "react-hook-form";
+import { z } from "zod";
import { getPollLayout } from "@/components/layouts/poll-layout";
import { PayWall } from "@/components/pay-wall";
import { usePoll } from "@/components/poll-context";
import { Trans } from "@/components/trans";
import { NextPageWithLayout } from "@/types";
+import { usePostHog } from "@/utils/posthog";
import { getStaticTranslations } from "@/utils/with-page-translations";
+const formSchema = z.object({
+ title: z.string().trim().min(1),
+});
+
const Page: NextPageWithLayout = () => {
const { poll } = usePoll();
const duplicate = trpc.polls.duplicate.useMutation();
const router = useRouter();
-
+ const posthog = usePostHog();
const pollLink = `/poll/${poll.id}`;
- const form = useForm<{ title: string }>({
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
defaultValues: {
title: poll.title,
},
@@ -51,6 +59,10 @@ const Page: NextPageWithLayout = () => {
{ pollId: poll.id, newTitle: data.title },
{
onSuccess: async (res) => {
+ posthog?.capture("duplicate poll", {
+ pollId: poll.id,
+ newPollId: res.id,
+ });
await router.push(`/poll/${res.id}`);
},
},
diff --git a/packages/backend/trpc/routers/polls.ts b/packages/backend/trpc/routers/polls.ts
index 6e29630ff..f8fa5c6f7 100644
--- a/packages/backend/trpc/routers/polls.ts
+++ b/packages/backend/trpc/routers/polls.ts
@@ -65,7 +65,7 @@ export const polls = router({
create: possiblyPublicProcedure
.input(
z.object({
- title: z.string(),
+ title: z.string().trim().min(1),
timeZone: z.string().optional(),
location: z.string().optional(),
description: z.string().optional(),
@@ -794,7 +794,7 @@ export const polls = router({
.input(
z.object({
pollId: z.string(),
- newTitle: z.string(),
+ newTitle: z.string().min(1),
}),
)
.mutation(async ({ input, ctx }) => {