Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Redesign the mobile poll voting experience (#2903)
Luke Vellabf57b77c4bcb
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex ced7260f2..8f36d0c20 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -520,6 +520,7 @@"optionalLabel": "(Optional)","optionCount": "{count, plural, one {# option} other {# options}}","optionsSelected": "{count, plural, =0 {None selected} one {# option selected} other {# options selected}}",+ "optionVoteBreakdown": "{yesScore} yes, {ifNeedBeScore} if need be","or": "Or","organizationName": "Organization name","organizationNamePlaceholder": "e.g. Acme Corp",@@ -701,6 +702,7 @@"setupPasswordAlertTitle": "Login quicker with a password","setupPasswordButton": "Set up password","share": "Share",+ "showParticipantVotes": "Show participant votes","showPassword": "Show password","shrink": "Shrink","signedInAs": "You're signed in as:",diff --git a/apps/web/src/features/poll/components/mobile-poll.tsx b/apps/web/src/features/poll/components/mobile-poll.tsxindex 581435291..4c44c0df7 100644--- a/apps/web/src/features/poll/components/mobile-poll.tsx+++ b/apps/web/src/features/poll/components/mobile-poll.tsx@@ -1,6 +1,6 @@import { Badge } from "@rallly/ui/badge";import { Button } from "@rallly/ui/button";-import { Card, CardFooter } from "@rallly/ui/card";+import { Card } from "@rallly/ui/card";import { Icon } from "@rallly/ui/icon";import {Select,@@ -102,14 +102,13 @@ const MobilePoll: React.FunctionComponent = () => {];return (- <Card>+ <Card className="overflow-visible"><div className="flex flex-col space-y-2 border-b p-2">- <div className="flex gap-x-2.5">+ <div className="flex gap-x-2">{selectedParticipantId || !isEditing ? (<Selectitems={participantOptions}- defaultValue="all"- value={selectedParticipantId}+ value={selectedParticipantId ?? "all"}onValueChange={(participantId) => {if (participantId) {votingForm.setValue("participantId", participantId);@@ -183,6 +182,7 @@ const MobilePoll: React.FunctionComponent = () => {aria-label={t("moreOptions", {defaultValue: "More options",})}+ variant="ghost"size="icon"><MoreHorizontalIcon />@@ -223,6 +223,7 @@ const MobilePoll: React.FunctionComponent = () => {<AnimatePresence>{isEditing ? (<m.div+ className="sticky bottom-0 z-20"variants={{hidden: { opacity: 0, y: -20, height: 0 },visible: { opacity: 1, y: 0, height: "auto" },@@ -236,9 +237,7 @@ const MobilePoll: React.FunctionComponent = () => {transition: { duration: 0.2 },}}>- <CardFooter className="border-t">- <VotingFooter className="flex-1" />- </CardFooter>+ <VotingFooter className="p-3" /></m.div>) : null}</AnimatePresence>diff --git a/apps/web/src/features/poll/components/mobile-poll/date-option.tsx b/apps/web/src/features/poll/components/mobile-poll/date-option.tsxindex 3e7bee75d..fca19c726 100644--- a/apps/web/src/features/poll/components/mobile-poll/date-option.tsx+++ b/apps/web/src/features/poll/components/mobile-poll/date-option.tsx@@ -21,9 +21,7 @@ const DateOption: React.FunctionComponent<DateOptionProps> = ({* until we update this component.*/}<div className="text-sm">- <span className="font-semibold">- {day} {dow}- </span>+ {day} {dow}</div></PollOption>);diff --git a/apps/web/src/features/poll/components/mobile-poll/grouped-options.tsx b/apps/web/src/features/poll/components/mobile-poll/grouped-options.tsxindex 03714ac56..752b412f5 100644--- a/apps/web/src/features/poll/components/mobile-poll/grouped-options.tsx+++ b/apps/web/src/features/poll/components/mobile-poll/grouped-options.tsx@@ -27,13 +27,10 @@ const GroupedOptions: React.FunctionComponent<GroupedOptionsProps> = ({{Object.entries(grouped).map(([day, options]) => {return (<div key={day}>- <div- className={cn(- "flex border-b bg-muted px-4 py-2 font-medium text-xs uppercase",- groupClassName,- )}- >- {day}+ <div className={cn("sticky top-0 z-10 p-1", groupClassName)}>+ <div className="rounded-lg border bg-card/80 p-2 font-semibold text-sm shadow-sm backdrop-blur-lg">+ {day}+ </div></div><PollOptionsoptions={options}diff --git a/apps/web/src/features/poll/components/mobile-poll/poll-option.tsx b/apps/web/src/features/poll/components/mobile-poll/poll-option.tsxindex 33f7ce584..6d6f3e5c9 100644--- a/apps/web/src/features/poll/components/mobile-poll/poll-option.tsx+++ b/apps/web/src/features/poll/components/mobile-poll/poll-option.tsx@@ -2,21 +2,27 @@import type { VoteType } from "@rallly/database";import { cn } from "@rallly/ui";import { Button } from "@rallly/ui/button";-import { Icon } from "@rallly/ui/icon";-import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogHeader,+ DialogTitle,+ useDialog,+} from "@rallly/ui/dialog";+import * as m from "motion/react-m";import type * as React from "react";-import { useToggle } from "react-use";import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";import {filterParticipantsByVote,useParticipants,} from "@/features/poll/components/participants-provider";-import { useTranslation } from "@/i18n/client";-+import { IfScoresVisible } from "@/features/poll/components/visibility";+import { Trans, useTranslation } from "@/i18n/client";import { ConnectedScoreSummary } from "../score-summary";import VoteIcon from "../vote-icon";-import { VoteSelector } from "../vote-selector";+import { VoteSegmentedControl } from "../vote-segmented-control";export interface PollOptionProps {children?: React.ReactNode;@@ -134,52 +140,73 @@ const PollOption: React.FunctionComponent<PollOptionProps> = ({editable = false,optionId,optionLabel,+ yesScore,+ ifNeedBeScore,}) => {- const showVotes = !!(selectedParticipantId || editable);- const [isExpanded, toggle] = useToggle(false);+ const { t } = useTranslation();+ const dialog = useDialog();++ const showVote = !editable && !!selectedParticipantId;+return (<divclassName={cn(- "relative space-y-4 bg-background p-4 transition-colors",- editable && "active:bg-accent/50",+ "grid h-14 items-center px-2 text-left transition-[grid-template-columns] duration-300",+ editable && "grid-cols-[0rem_1fr_3.5rem_8.875rem]",+ showVote && "grid-cols-[1.875rem_1fr_3.5rem_0rem]",+ !editable && !showVote && "grid-cols-[0rem_1fr_3.5rem_0rem]",)}data-testid="poll-option">- <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">- <Button- size="sm"- variant="ghost"- className="relative z-10"- onClick={() => toggle()}- >- <ConnectedScoreSummary optionId={optionId} />- <Icon>{isExpanded ? <ChevronUpIcon /> : <ChevronDownIcon />}</Icon>- </Button>-- {showVotes ? (- <div className="flex size-7 items-center justify-center">- {editable ? (- <VoteSelector- className="after:absolute after:inset-0"- optionLabel={optionLabel}- value={vote}- onChange={onChange}- />- ) : (- <div- key={vote}- className="flex h-full items-center justify-center"- >- <VoteIcon type={vote} />- </div>- )}- </div>- ) : null}- </div>- </div>- {isExpanded ? <PollOptionVoteSummary optionId={optionId} /> : null}+ <span+ aria-hidden={showVote ? undefined : true}+ className="overflow-hidden"+ >+ {showVote ? <VoteIcon type={vote} /> : null}+ </span>+ {children}+ <IfScoresVisible>+ <Button+ {...dialog.triggerProps}+ aria-label={`${t("optionVoteBreakdown", {+ defaultValue: "{yesScore} yes, {ifNeedBeScore} if need be",+ yesScore,+ ifNeedBeScore,+ })}. ${t("showParticipantVotes", {+ defaultValue: "Show participant votes",+ })}`}+ variant="ghost"+ size="lg"+ className="col-start-3 justify-self-end"+ >+ <ConnectedScoreSummary optionId={optionId} />+ </Button>+ <Dialog {...dialog.dialogProps}>+ <DialogContent size="sm">+ <DialogHeader>+ <DialogTitle>+ <Trans i18nKey="participants" defaults="Participants" />+ </DialogTitle>+ <DialogDescription>{optionLabel}</DialogDescription>+ </DialogHeader>+ <PollOptionVoteSummary optionId={optionId} />+ </DialogContent>+ </Dialog>+ </IfScoresVisible>+ {editable ? (+ <m.div+ className="col-start-4 justify-self-end"+ initial={{ opacity: 0, x: 12 }}+ animate={{ opacity: 1, x: 0 }}+ transition={{ duration: 0.3, ease: [0.4, 0, 0.2, 1] }}+ >+ <VoteSegmentedControl+ value={vote}+ onChange={onChange}+ optionLabel={optionLabel}+ />+ </m.div>+ ) : null}</div>);};diff --git a/apps/web/src/features/poll/components/mobile-poll/poll-options.tsx b/apps/web/src/features/poll/components/mobile-poll/poll-options.tsxindex b8283f16e..54b286316 100644--- a/apps/web/src/features/poll/components/mobile-poll/poll-options.tsx+++ b/apps/web/src/features/poll/components/mobile-poll/poll-options.tsx@@ -35,61 +35,66 @@ const PollOptions: React.FunctionComponent<PollOptions> = ({const score = getScore(option.optionId);const index = optionIds.indexOf(option.optionId);return (- <Controller- key={option.optionId}- control={control}- name="votes"- render={({ field }) => {- const vote =- !editable && selectedParticipant- ? getVote(selectedParticipant.id, option.optionId)- : field.value[index]?.type;+ <div key={option.optionId} className="p-2">+ <Controller+ key={option.optionId}+ control={control}+ name="votes"+ render={({ field }) => {+ const vote =+ !editable && selectedParticipant+ ? getVote(selectedParticipant.id, option.optionId)+ : field.value[index]?.type;- const handleChange = (newVote: VoteType) => {- if (!editable) {- return;- }- const newValue = [...field.value];- newValue[index] = { optionId: option.optionId, type: newVote };- field.onChange(newValue);- };+ const handleChange = (newVote: VoteType) => {+ if (!editable) {+ return;+ }+ const newValue = [...field.value];+ newValue[index] = {+ optionId: option.optionId,+ type: newVote,+ };+ field.onChange(newValue);+ };- switch (option.type) {- case "timeSlot":- return (- <TimeSlotOption- onChange={handleChange}- optionId={option.optionId}- optionLabel={getOptionDateTimeLabel(option)}- yesScore={score.yes}- ifNeedBeScore={score.ifNeedBe}- vote={vote}- startTime={option.startTime}- endTime={option.endTime}- duration={option.duration}- editable={editable}- selectedParticipantId={selectedParticipant?.id}- />- );- case "date":- return (- <DateOption- onChange={handleChange}- optionId={option.optionId}- optionLabel={getOptionDateTimeLabel(option)}- yesScore={score.yes}- ifNeedBeScore={score.ifNeedBe}- vote={vote}- dow={option.dow}- day={option.day}- month={option.month}- editable={editable}- selectedParticipantId={selectedParticipant?.id}- />- );- }- }}- />+ switch (option.type) {+ case "timeSlot":+ return (+ <TimeSlotOption+ onChange={handleChange}+ optionId={option.optionId}+ optionLabel={getOptionDateTimeLabel(option)}+ yesScore={score.yes}+ ifNeedBeScore={score.ifNeedBe}+ vote={vote}+ startTime={option.startTime}+ endTime={option.endTime}+ duration={option.duration}+ editable={editable}+ selectedParticipantId={selectedParticipant?.id}+ />+ );+ case "date":+ return (+ <DateOption+ onChange={handleChange}+ optionId={option.optionId}+ optionLabel={getOptionDateTimeLabel(option)}+ yesScore={score.yes}+ ifNeedBeScore={score.ifNeedBe}+ vote={vote}+ dow={option.dow}+ day={option.day}+ month={option.month}+ editable={editable}+ selectedParticipantId={selectedParticipant?.id}+ />+ );+ }+ }}+ />+ </div>);})}</div>diff --git a/apps/web/src/features/poll/components/mobile-poll/time-slot-option.tsx b/apps/web/src/features/poll/components/mobile-poll/time-slot-option.tsxindex 9f4e6c5b5..534f3f1b5 100644--- a/apps/web/src/features/poll/components/mobile-poll/time-slot-option.tsx+++ b/apps/web/src/features/poll/components/mobile-poll/time-slot-option.tsx@@ -1,4 +1,3 @@-import { ClockIcon } from "lucide-react";import type * as React from "react";import type { PollOptionProps } from "./poll-option";@@ -10,19 +9,24 @@ export interface TimeSlotOptionProps extends PollOptionProps {duration: string;}+const meridiem = (time: string) => /(AM|PM)$/.exec(time)?.[0];+const TimeSlotOption: React.FunctionComponent<TimeSlotOptionProps> = ({startTime,- duration,+ endTime,...rest}) => {+ // "12:00 – 1:00 PM" reads cleaner than repeating the period; keep it when+ // the range crosses noon ("11:00 AM – 1:00 PM") or the locale has none.+ const startLabel =+ meridiem(startTime) && meridiem(startTime) === meridiem(endTime)+ ? startTime.replace(/ (AM|PM)$/, "")+ : startTime;+return (<PollOption {...rest}>- <div className="flex items-center gap-x-4 text-sm">- <div>{startTime}</div>- <div className="flex items-center gap-x-1.5 text-muted-foreground">- <ClockIcon className="size-4" />- {duration}- </div>+ <div className="text-sm">+ {startLabel} – {endTime}</div></PollOption>);diff --git a/apps/web/src/features/poll/components/vote-segmented-control.tsx b/apps/web/src/features/poll/components/vote-segmented-control.tsxnew file mode 100644index 000000000..a6ec9e46e--- /dev/null+++ b/apps/web/src/features/poll/components/vote-segmented-control.tsx@@ -0,0 +1,64 @@+"use client";+import { cn } from "@rallly/ui";+import {+ SegmentedControl,+ SegmentedControlItem,+} from "@rallly/ui/segmented-control";++import { useTranslation } from "@/i18n/client";++import VoteIcon from "./vote-icon";++type VoteType = "yes" | "ifNeedBe" | "no";++const voteTypes: VoteType[] = ["yes", "ifNeedBe", "no"];++export const VoteSegmentedControl = ({+ value,+ onChange,+ optionLabel,+ className,+}: {+ value?: VoteType;+ onChange: (value: VoteType) => void;+ className?: string;+ /**+ * Accessible description of the option being voted on (e.g. "Tue 30 Jun+ * 2026, 1:00 PM – 2:00 PM") so screen readers can tie the vote to its+ * date/time.+ */+ optionLabel?: string;+}) => {+ const { t } = useTranslation();++ const voteLabels: Record<VoteType, string> = {+ yes: t("yes", { defaultValue: "Yes" }),+ ifNeedBe: t("ifNeedBe", { defaultValue: "If need be" }),+ no: t("no", { defaultValue: "No" }),+ };++ return (+ <SegmentedControl+ data-testid="vote-selector"+ aria-label={optionLabel}+ className={cn("h-11", className)}+ value={value ?? null}+ onValueChange={(newValue) => {+ if (newValue) {+ onChange(newValue as VoteType);+ }+ }}+ >+ {voteTypes.map((type) => (+ <SegmentedControlItem+ key={type}+ value={type}+ aria-label={voteLabels[type]}+ className="w-11 data-unchecked:[&_path]:fill-gray-400"+ >+ <VoteIcon type={type} />+ </SegmentedControlItem>+ ))}+ </SegmentedControl>+ );+};diff --git a/apps/web/src/features/poll/components/voting-footer.tsx b/apps/web/src/features/poll/components/voting-footer.tsxindex da83d2bbc..f0399afc4 100644--- a/apps/web/src/features/poll/components/voting-footer.tsx+++ b/apps/web/src/features/poll/components/voting-footer.tsx@@ -57,6 +57,7 @@ export const VotingFooter = ({ className }: { className?: string }) => {</p><Buttontype="button"+ size="lg"className="flex-1 md:flex-none"disabled={votingForm.formState.isSubmitting}onClick={() => {@@ -72,8 +73,9 @@ export const VotingFooter = ({ className }: { className?: string }) => {<Buttonform="voting-form"type="submit"+ size="lg"variant="primary"- className="flex-[2] aria-disabled:opacity-50 md:flex-none"+ className="flex-2 bg-primary/80 backdrop-blur-lg aria-disabled:opacity-50 md:flex-none"aria-disabled={isBlocked}loading={votingForm.formState.isSubmitting}onClick={(event) => {diff --git a/apps/web/tests/mobile-test.spec.ts b/apps/web/tests/mobile-test.spec.tsindex 5be23b4a7..615652a42 100644--- a/apps/web/tests/mobile-test.spec.ts+++ b/apps/web/tests/mobile-test.spec.ts@@ -16,7 +16,11 @@ test.describe(() => {});const voteAsNewParticipant = async (page: Page, name: string) => {- await page.getByTestId("poll-option").first().click();+ await page+ .getByTestId("vote-selector")+ .first()+ .getByRole("radio", { name: "Yes" })+ .click();await page.getByRole("button", { name: "Continue" }).click();await page.getByPlaceholder("Jessie Smith").fill(name);await page.getByRole("button", { name: "Save availability" }).click();diff --git a/packages/ui/src/alert.tsx b/packages/ui/src/alert.tsxindex 577bfb25e..ec6d840b5 100644--- a/packages/ui/src/alert.tsx+++ b/packages/ui/src/alert.tsx@@ -5,12 +5,12 @@ import type * as React from "react";import { cn } from "./lib/utils";const alertVariants = cva(- "group/alert relative grid w-full items-center gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-[>svg]:has-data-[slot=alert-action]:grid-cols-[auto_1fr_auto] has-[>svg]:grid-cols-[auto_1fr] has-data-[slot=alert-action]:grid-cols-[1fr_auto] has-data-[slot=alert-title]:items-start has-[>svg]:gap-x-2 has-data-[slot=alert-action]:gap-x-2 *:[svg:not([class*='size-'])]:size-4 *:[svg]:text-current has-data-[slot=alert-title]:*:[svg]:row-span-2 has-data-[slot=alert-title]:*:[svg]:translate-y-0.5",+ "group/alert relative grid w-full items-center gap-0.5 rounded-xl border p-2 text-left text-sm has-[>svg]:has-data-[slot=alert-action]:grid-cols-[auto_1fr_auto] has-[>svg]:grid-cols-[auto_1fr] has-data-[slot=alert-action]:grid-cols-[1fr_auto] has-data-[slot=alert-title]:items-start has-[>svg]:gap-x-2 has-data-[slot=alert-action]:gap-x-2 *:[svg:not([class*='size-'])]:size-4 *:[svg]:text-current has-data-[slot=alert-title]:*:[svg]:row-span-2 has-data-[slot=alert-title]:*:[svg]:translate-y-0.5",{variants: {variant: {primary:- "border-indigo-500/20 bg-indigo-500/10 text-indigo-900 *:data-[slot=alert-description]:text-indigo-900/90 dark:text-indigo-100 dark:*:data-[slot=alert-description]:text-indigo-100/90 [&>svg]:text-indigo-900/75 dark:[&>svg]:text-indigo-100/75",+ "border-indigo-500/20 bg-indigo-500/10 text-indigo-900 backdrop-blur-lg *:data-[slot=alert-description]:text-indigo-900/90 dark:text-indigo-100 dark:*:data-[slot=alert-description]:text-indigo-100/90 [&>svg]:text-indigo-900/75 dark:[&>svg]:text-indigo-100/75",info: "border-blue-500/20 bg-blue-500/10 text-blue-900 *:data-[slot=alert-description]:text-blue-900/90 dark:text-blue-100 dark:*:data-[slot=alert-description]:text-blue-100/90 [&>svg]:text-blue-900/75 dark:[&>svg]:text-blue-100/75",warning:"border-yellow-500/20 bg-yellow-500/10 text-yellow-900 *:data-[slot=alert-description]:text-yellow-900/90 dark:text-yellow-100 dark:*:data-[slot=alert-description]:text-yellow-100/90 [&>svg]:text-yellow-900/75 dark:[&>svg]:text-yellow-100/75",diff --git a/packages/ui/src/segmented-control.tsx b/packages/ui/src/segmented-control.tsxnew file mode 100644index 000000000..f161fd8fb--- /dev/null+++ b/packages/ui/src/segmented-control.tsx@@ -0,0 +1,37 @@+"use client";++import { Radio as RadioPrimitive } from "@base-ui/react/radio";+import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group";++import { cn } from "./lib/utils";++function SegmentedControl({ className, ...props }: RadioGroupPrimitive.Props) {+ return (+ <RadioGroupPrimitive+ data-slot="segmented-control"+ className={cn(+ "inline-flex h-8 shrink-0 items-center justify-center rounded-xl border border-input bg-muted dark:bg-gray-900",+ className,+ )}+ {...props}+ />+ );+}++function SegmentedControlItem({+ className,+ ...props+}: RadioPrimitive.Root.Props) {+ return (+ <RadioPrimitive.Root+ data-slot="segmented-control-item"+ className={cn(+ "relative inline-flex h-full cursor-pointer touch-manipulation items-center justify-center rounded-xl ring-offset-background [-webkit-tap-highlight-color:transparent] before:absolute before:inset-x-0 before:-inset-y-1 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 data-checked:bg-white data-checked:ring-1 data-checked:ring-gray-200 data-unchecked:active:bg-black/5 dark:data-checked:bg-gray-800 dark:data-checked:ring-gray-700 dark:data-unchecked:active:bg-white/5",+ className,+ )}+ {...props}+ />+ );+}++export { SegmentedControl, SegmentedControlItem };