Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Anonymize hidden participants instead of hiding their responses (#2422)
Luke Vella8eda9333c7c3
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex 290d2a862..4e7431869 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -294,6 +294,7 @@"guest": "Guest","guestPollAlertDescription": "<0>Create an account</0> or <1>login</1> to claim this poll.","guestPollAlertTitle": "Your administrator rights can be lost if you clear your cookies",+ "hiddenParticipantName": "Participant #{number}","hideAttribution": "Hide Attribution","hideParticipantsLabel": "Hide participant list from other participants","hideScoresLabel": "Hide scores until after a participant has voted",diff --git a/apps/web/src/components/participants-provider.tsx b/apps/web/src/components/participants-provider.tsxindex db950e095..1d18f0fa4 100644--- a/apps/web/src/components/participants-provider.tsx+++ b/apps/web/src/components/participants-provider.tsx@@ -3,6 +3,7 @@ import { useParams, useSearchParams } from "next/navigation";import * as React from "react";import { useVisibility } from "@/components/visibility";import { usePermissions } from "@/contexts/permissions";+import { useTranslation } from "@/i18n/client";import { trpc } from "@/trpc/client";export function filterParticipantsByVote<@@ -16,29 +17,46 @@ export function filterParticipantsByVote<}export const useParticipants = () => {+ const { t } = useTranslation();const urlId = useParams<{ urlId: string }>().urlId;const token = useSearchParams().get("token") ?? undefined;- const [participants] = trpc.polls.participants.list.useSuspenseQuery({+ const [rawParticipants] = trpc.polls.participants.list.useSuspenseQuery({pollId: urlId,token,});+ const participants = React.useMemo(() => {+ return rawParticipants.map((participant, index) => {+ if (!participant.hidden) {+ return participant;+ }++ return {+ ...participant,+ name: t("hiddenParticipantName", {+ defaultValue: "Participant #{number}",+ number: rawParticipants.length - index,+ }),+ };+ });+ }, [rawParticipants, t]);+return { participants };};export const useVisibleParticipants = () => {- const { canSeeOtherParticipants } = useVisibility();+ const { canSeeScores } = useVisibility();const { canEditParticipant } = usePermissions();const { participants } = useParticipants();const filteredParticipants = React.useMemo(() => {- if (!canSeeOtherParticipants) {+ if (!canSeeScores) {return participants.filter((participant) =>canEditParticipant(participant.id),);}return participants;- }, [canEditParticipant, canSeeOtherParticipants, participants]);+ }, [canEditParticipant, canSeeScores, participants]);return filteredParticipants;};diff --git a/apps/web/src/components/poll/mobile-poll/poll-option.tsx b/apps/web/src/components/poll/mobile-poll/poll-option.tsxindex 599c47738..1593cbabe 100644--- a/apps/web/src/components/poll/mobile-poll/poll-option.tsx+++ b/apps/web/src/components/poll/mobile-poll/poll-option.tsx@@ -15,8 +15,6 @@ import {filterParticipantsByVote,useParticipants,} from "@/components/participants-provider";-import { usePoll } from "@/contexts/poll";-import { useRole } from "@/contexts/role";import { useTranslation } from "@/i18n/client";import { ConnectedScoreSummary } from "../score-summary";@@ -139,9 +137,7 @@ const PollOption: React.FunctionComponent<PollOptionProps> = ({editable = false,optionId,}) => {- const poll = usePoll();const showVotes = !!(selectedParticipantId || editable);- const role = useRole();const selectorRef = React.useRef<HTMLButtonElement>(null);const [active, setActive] = React.useState(false);const [isExpanded, toggle] = useToggle(false);@@ -162,23 +158,17 @@ const PollOption: React.FunctionComponent<PollOptionProps> = ({<div className="flex h-7 items-center justify-between gap-x-4"><div className="shrink-0">{children}</div><div className="flex items-center gap-x-4">- {role === "participant" && poll.hideParticipants ? (+ <Button+ size="sm"+ variant="ghost"+ onClick={(e) => {+ e.stopPropagation();+ toggle();+ }}+ ><ConnectedScoreSummary optionId={optionId} />- ) : (- <Button- size="sm"- variant="ghost"- onClick={(e) => {- e.stopPropagation();- toggle();- }}- >- <ConnectedScoreSummary optionId={optionId} />- <Icon>- {isExpanded ? <ChevronUpIcon /> : <ChevronDownIcon />}- </Icon>- </Button>- )}+ <Icon>{isExpanded ? <ChevronUpIcon /> : <ChevronDownIcon />}</Icon>+ </Button>{showVotes ? (<div className="relative flex size-7 items-center justify-center">diff --git a/apps/web/src/components/poll/scheduled-event.tsx b/apps/web/src/components/poll/scheduled-event.tsxdeleted file mode 100644index 605874b7e..000000000--- a/apps/web/src/components/poll/scheduled-event.tsx+++ /dev/null@@ -1,109 +0,0 @@-"use client";--import { Badge } from "@rallly/ui/badge";-import { CalendarIcon } from "lucide-react";-import { AddToCalendarButton } from "@/components/add-to-calendar-button";-import { ParticipantAvatarBar } from "@/components/participant-avatar-bar";-import { IfParticipantsVisible } from "@/components/visibility";-import { usePoll } from "@/contexts/poll";-import { Trans } from "@/i18n/client";-import { dayjs } from "@/lib/dayjs";-import { useDayjs } from "@/utils/dayjs";--function FinalDate({ start }: { start: Date }) {- const poll = usePoll();- const { adjustTimeZone } = useDayjs();- return (- <span>{adjustTimeZone(start, !poll.timeZone).format("dddd, LL")}</span>- );-}--function DateIcon({ start }: { start: Date }) {- const poll = usePoll();- const { adjustTimeZone } = useDayjs();- const d = adjustTimeZone(start, !poll.timeZone);- return (- <time- className="inline-flex size-12 flex-col items-center justify-center gap-1 rounded-lg border text-center"- dateTime={d.toISOString()}- >- <div className="text-[10px] text-muted-foreground uppercase">- {d.format("MMM")}- </div>- <div className="font-bold text-sm">{d.format("D")}</div>- </time>- );-}--function FinalTime({ start, duration }: { start: Date; duration: number }) {- const poll = usePoll();- const { adjustTimeZone } = useDayjs();- if (duration === 0) {- return <Trans i18nKey="allDay" />;- }- return (- <span>{`${adjustTimeZone(start, !poll.timeZone).format("LT")} - ${adjustTimeZone(dayjs(start).add(duration, "minutes"), !poll.timeZone).format(poll.timeZone ? "LT z" : "LT")}`}</span>- );-}--function useAttendees() {- const poll = usePoll();- return poll.event?.attendees ?? [];-}--function Attendees() {- const attendees = useAttendees();-- return <ParticipantAvatarBar participants={attendees} max={5} />;-}--export function ScheduledEvent() {- const poll = usePoll();- const { event } = poll;-- if (!event) {- return null;- }-- return (- <>- <div className="rounded-lg border-card-border bg-card p-0.5 shadow-xs">- <div className="flex h-9 items-center gap-x-2 rounded-md bg-gray-100 px-2 text-card-foreground dark:bg-gray-800">- <CalendarIcon className="size-4" />- <h2 className="font-medium text-sm">- <Trans i18nKey="schedulateDate" defaults="Scheduled Date" />- </h2>- </div>- <div className="flex flex-col justify-between gap-4 p-4 sm:flex-row sm:items-center">- <div className="flex items-center gap-6">- <div>- <DateIcon start={event.start} />- </div>- <div className="items-center gap-x-4">- <div className="space-y-1">- <div className="font-medium text-sm">- <FinalDate start={event.start} />- </div>- <div className="text-sm opacity-75">- <FinalTime start={event.start} duration={event.duration} />- </div>- </div>- </div>- {event.status === "canceled" && (- <Badge>- <Trans i18nKey="canceled" defaults="Canceled" />- </Badge>- )}- </div>- <div className="flex items-center gap-4">- <IfParticipantsVisible>- <Attendees />- </IfParticipantsVisible>- <AddToCalendarButton eventId={event.id} />- </div>- </div>- </div>- <hr />- </>- );-}diff --git a/apps/web/src/components/visibility.tsx b/apps/web/src/components/visibility.tsxindex dc1c76e47..5cf822fb8 100644--- a/apps/web/src/components/visibility.tsx+++ b/apps/web/src/components/visibility.tsx@@ -7,16 +7,6 @@ import { useParticipants } from "@/components/participants-provider";import { usePermissions } from "@/contexts/permissions";import { usePoll } from "@/contexts/poll";-export const IfParticipantsVisible = (props: React.PropsWithChildren) => {- const context = React.useContext(VisibilityContext);-- if (context.canSeeOtherParticipants) {- return <>{props.children}</>;- }-- return null;-};-export const IfScoresVisible = (props: React.PropsWithChildren) => {const context = React.useContext(VisibilityContext);@@ -32,11 +22,9 @@ export const useVisibility = () => {};const VisibilityContext = React.createContext<{- canSeeOtherParticipants: boolean;canSeeScores: boolean;}>({canSeeScores: true,- canSeeOtherParticipants: true,});export const VisibilityProvider = ({ children }: React.PropsWithChildren) => {@@ -48,12 +36,10 @@ export const VisibilityProvider = ({ children }: React.PropsWithChildren) => {});const canSeeScores = poll.hideScores ? userAlreadyVoted : true;- const canSeeOtherParticipants = poll.hideParticipants ? false : canSeeScores;return (<VisibilityContext.Providervalue={{- canSeeOtherParticipants,canSeeScores,}}>diff --git a/apps/web/src/trpc/routers/polls/participants.ts b/apps/web/src/trpc/routers/polls/participants.tsindex cca2cb1db..f6b9920d0 100644--- a/apps/web/src/trpc/routers/polls/participants.ts+++ b/apps/web/src/trpc/routers/polls/participants.ts@@ -37,6 +37,7 @@ function createParticipantFullDTO(...rest,image: user?.image ?? null,votes,+ hidden: false,};}@@ -173,9 +174,10 @@ export const participants = router({return {...participant,userId: null,- name: "Anonymous",+ name: "",email: null,image: null,+ hidden: true,};});}