Store participant timezone in response (#1811)

This commit is contained in:
Luke Vella 2025-07-11 15:25:15 +01:00 committed by GitHub
parent 968e513dba
commit 965e969fd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 101 additions and 87 deletions

View file

@ -13,6 +13,7 @@ import z from "zod";
import { usePoll } from "@/contexts/poll";
import { useTranslation } from "@/i18n/client";
import { useTimezone } from "@/features/timezone";
import { useAddParticipantMutation } from "./poll/mutations";
import VoteIcon from "./poll/vote-icon";
import { useUser } from "./user-provider";
@ -89,7 +90,7 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {
const poll = usePoll();
const isEmailRequired = poll.requireParticipantEmail;
const { timezone } = useTimezone();
const { user, createGuestIfNeeded } = useUser();
const isLoggedIn = !user.isGuest;
const { register, setError, formState, handleSubmit } =
@ -117,6 +118,7 @@ export const NewParticipantForm = (props: NewParticipantModalProps) => {
votes: props.votes,
email: data.email,
pollId: poll.id,
timeZone: timezone,
});
props.onSubmit?.(newParticipant);
} catch (error) {

View file

@ -574,6 +574,7 @@ export const polls = router({
name: true,
email: true,
locale: true,
timeZone: true,
user: {
select: {
email: true,
@ -661,7 +662,8 @@ export const polls = router({
inviteeName: p.name,
inviteeEmail:
p.user?.email ?? p.email ?? `${p.id}@rallly.co`,
inviteeTimeZone: p.user?.timeZone ?? poll.timeZone, // We should track participant's timezone
inviteeTimeZone:
p.user?.timeZone ?? p.timeZone ?? poll.timeZone,
status: (
{
yes: "accepted",
@ -758,6 +760,7 @@ export const polls = router({
name: string;
email: string;
locale: string | undefined;
timeZone: string | null;
}> = [];
if (input.notify === "all") {
@ -768,6 +771,7 @@ export const polls = router({
name: p.name,
email: p.email,
locale: p.locale ?? undefined,
timeZone: p.timeZone,
});
}
});
@ -781,6 +785,7 @@ export const polls = router({
name: p.name,
email: p.email,
locale: p.locale ?? undefined,
timeZone: p.timeZone,
});
}
});
@ -821,7 +826,7 @@ export const polls = router({
end: scheduledEvent.end,
allDay: scheduledEvent.allDay,
timeZone: scheduledEvent.timeZone,
// inviteeTimeZone: p.timeZone, // TODO: implement this
inviteeTimeZone: p.timeZone,
});
getEmailClient(p.locale ?? undefined).queueTemplate(
"FinalizeParticipantEmail",

View file

@ -129,6 +129,7 @@ export const participants = router({
pollId: z.string(),
name: z.string().min(1, "Participant name is required").max(100),
email: z.string().optional(),
timeZone: z.string().optional(),
votes: z
.object({
optionId: z.string(),
@ -137,7 +138,8 @@ export const participants = router({
.array(),
}),
)
.mutation(async ({ ctx, input: { pollId, votes, name, email } }) => {
.mutation(
async ({ ctx, input: { pollId, votes, name, email, timeZone } }) => {
const { user } = ctx;
const participant = await prisma.$transaction(async (prisma) => {
@ -160,6 +162,7 @@ export const participants = router({
pollId: pollId,
name: name,
email,
timeZone,
...(user.isGuest ? { guestId: user.id } : { userId: user.id }),
locale: user.locale ?? undefined,
},
@ -230,7 +233,8 @@ export const participants = router({
);
return participant;
}),
},
),
rename: publicProcedure
.input(z.object({ participantId: z.string(), newName: z.string() }))
.mutation(async ({ input: { participantId, newName } }) => {

View file

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "participants" ADD COLUMN "time_zone" TEXT;

View file

@ -76,6 +76,7 @@ model Participant {
guestId String? @map("guest_id")
pollId String @map("poll_id")
locale String?
timeZone String? @map("time_zone")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
deleted Boolean @default(false)