Skip to content

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

🐛 Address PR feedback + persist cleared optional fields (#2388)

Luke Vellafc7aa2a3d33a
diff --git a/apps/web/src/features/event-types/components/create-event-type-dialog.tsx b/apps/web/src/features/event-types/components/create-event-type-dialog.tsx
index 539a8869c..6b7a718f3 100644
--- a/apps/web/src/features/event-types/components/create-event-type-dialog.tsx
+++ b/apps/web/src/features/event-types/components/create-event-type-dialog.tsx
@@ -66,7 +66,7 @@ export function CreateEventTypeDialog({ open, onOpenChange }: DialogProps) {
duration_minutes: input.duration,
location_type: input.location?.type ?? "none",
has_max_attendees: input.capacity !== null,
- has_description: input.description !== undefined,
+ has_description: input.description !== null,
});
handleOpenChange(false);
});
diff --git a/apps/web/src/features/event-types/components/edit-event-type-dialog.tsx b/apps/web/src/features/event-types/components/edit-event-type-dialog.tsx
index cc7959045..4d768e4c4 100644
--- a/apps/web/src/features/event-types/components/edit-event-type-dialog.tsx
+++ b/apps/web/src/features/event-types/components/edit-event-type-dialog.tsx
@@ -65,6 +65,8 @@ export function EditEventTypeDialog({
const handleOpenChange = (nextOpen: boolean) => {
if (!nextOpen) {
form.reset(initialValues);
+ setShowMaxAttendees(eventType.capacity !== null);
+ setShowDescription(eventType.description !== null);
}
onOpenChange?.(nextOpen);
};
@@ -87,7 +89,7 @@ export function EditEventTypeDialog({
duration_minutes: input.duration,
location_type: input.location?.type ?? "none",
has_max_attendees: input.capacity !== null,
- has_description: input.description !== undefined,
+ has_description: input.description !== null,
});
handleOpenChange(false);
});
diff --git a/apps/web/src/features/event-types/components/event-type-form.tsx b/apps/web/src/features/event-types/components/event-type-form.tsx
index 74f7a0169..8fde494b7 100644
--- a/apps/web/src/features/event-types/components/event-type-form.tsx
+++ b/apps/web/src/features/event-types/components/event-type-form.tsx
@@ -55,7 +55,8 @@ export function buildEventTypeFormSchema(
});
}
} else if (data.locationType === "custom_link") {
- if (!data.locationUrl?.trim()) {
+ const trimmedUrl = data.locationUrl?.trim();
+ if (!trimmedUrl) {
ctx.addIssue({
path: ["locationUrl"],
code: "custom",
@@ -63,7 +64,7 @@ export function buildEventTypeFormSchema(
});
} else {
try {
- new URL(data.locationUrl);
+ new URL(trimmedUrl);
} catch {
ctx.addIssue({
path: ["locationUrl"],
@@ -113,16 +114,16 @@ type EventTypeInput = {
name: string;
duration: number;
capacity: number | null;
- description: string | undefined;
- location: Location | undefined;
+ description: string | null;
+ location: Location | null;
};
export function eventTypeValuesToInput(
values: EventTypeFormValues,
): EventTypeInput {
const capacity = values.maxAttendees ? Number(values.maxAttendees) : null;
- const description = values.description?.trim() || undefined;
- const location: Location | undefined =
+ const description = values.description?.trim() || null;
+ const location: Location | null =
values.locationType === "in_person" && values.locationAddress
? { type: "in_person", address: values.locationAddress.trim() }
: values.locationType === "custom_link" && values.locationUrl
@@ -131,7 +132,7 @@ export function eventTypeValuesToInput(
url: values.locationUrl.trim(),
text: values.locationText?.trim() || undefined,
}
- : undefined;
+ : null;
return {
name: values.name.trim(),
duration: values.duration,
@@ -183,6 +184,7 @@ export function EventTypeFormFields({
<FormControl>
<Input
{...field}
+ name="eventTypeName"
autoFocus
placeholder={t("eventTypeNamePlaceholder", {
defaultValue: "Discovery call",
@@ -230,9 +232,22 @@ export function EventTypeFormFields({
name="locationType"
render={({ field }) => (
<FormItem>
- <FormLabel>
- <Trans i18nKey="location" defaults="Location" />
- </FormLabel>
+ <div className="flex items-center justify-between">
+ <FormLabel>
+ <Trans i18nKey="location" defaults="Location" />
+ </FormLabel>
+ {field.value !== "" ? (
+ <RemoveOptionalButton
+ onClick={() => {
+ form.setValue("locationType", "");
+ form.setValue("locationAddress", "");
+ form.setValue("locationUrl", "");
+ form.setValue("locationText", "");
+ form.clearErrors(["locationAddress", "locationUrl"]);
+ }}
+ />
+ ) : null}
+ </div>
<FormControl>
<RadioGroup
value={field.value}
@@ -425,15 +440,13 @@ function RadioCardOption({
return (
<label
htmlFor={id}
- className="group flex cursor-pointer items-center gap-2.5 rounded-lg border border-input bg-card px-3 py-2.5 text-sm transition-colors hover:bg-accent has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5"
+ className="group flex cursor-pointer items-center gap-2 rounded-lg border border-input bg-card px-3 py-2.5 text-sm transition-colors hover:bg-accent has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5"
>
- <RadioGroupItem id={id} value={value} />
- <span className="flex items-center gap-1.5 font-medium text-foreground">
- <span className="text-muted-foreground group-has-data-[state=checked]:text-primary">
- {icon}
- </span>
- {label}
+ <span className="text-muted-foreground group-has-data-[state=checked]:text-primary">
+ {icon}
</span>
+ <span className="flex-1 font-normal">{label}</span>
+ <RadioGroupItem className="hidden" id={id} value={value} />
</label>
);
}
diff --git a/apps/web/src/features/event-types/schema.ts b/apps/web/src/features/event-types/schema.ts
index 462c19600..8198f722f 100644
--- a/apps/web/src/features/event-types/schema.ts
+++ b/apps/web/src/features/event-types/schema.ts
@@ -5,8 +5,8 @@ export const eventTypeInputSchema = z.object({
name: z.string().min(1).max(255),
duration: z.number().int().positive(),
capacity: z.number().int().positive().nullable().optional(),
- description: z.string().max(2000).optional(),
- location: locationSchema.optional(),
+ description: z.string().max(2000).nullable().optional(),
+ location: locationSchema.nullable().optional(),
});
export type EventTypeInput = z.infer<typeof eventTypeInputSchema>;
diff --git a/apps/web/src/trpc/routers/event-types.ts b/apps/web/src/trpc/routers/event-types.ts
index c8435c5ba..6df29a131 100644
--- a/apps/web/src/trpc/routers/event-types.ts
+++ b/apps/web/src/trpc/routers/event-types.ts
@@ -1,4 +1,4 @@
-import { prisma } from "@rallly/database";
+import { Prisma, prisma } from "@rallly/database";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { isEventTypesEnabled } from "@/features/event-types/constants";
@@ -38,7 +38,7 @@ export const eventTypes = router({
duration: input.duration,
capacity: input.capacity,
description: input.description,
- location: input.location,
+ location: input.location ?? Prisma.JsonNull,
},
include: {
host: {
@@ -63,7 +63,7 @@ export const eventTypes = router({
duration: input.duration,
capacity: input.capacity,
description: input.description,
- location: input.location,
+ location: input.location ?? Prisma.JsonNull,
},
include: {
host: {
diff --git a/packages/database/src/client.ts b/packages/database/src/client.ts
index eead269bd..66c03f25b 100644
--- a/packages/database/src/client.ts
+++ b/packages/database/src/client.ts
@@ -2,6 +2,7 @@ import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "../generated/prisma/client";
export type * from "../generated/prisma/client";
+export { Prisma } from "../generated/prisma/client";
const globalForPrisma = globalThis as unknown as {
prisma?: PrismaClient;