Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Unify the voting footer and make all-no responses explicit (#2893)
Luke Vellad4f6cefd209a
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex e89901103..9cddd7b94 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -199,6 +199,9 @@"dangerZone": "Danger zone","dangerZoneAccountDeletion": "Delete your account and all data associated with it","dates": "Dates",+ "decline": "Decline",+ "declineConfirmDescription": "{count, plural, one {This will discard your selected option and respond no to everything.} other {This will discard your # selected options and respond no to everything.}}",+ "declineConfirmTitle": "Decline?","decreaseSeats": "Decrease seats","defaultCalendar": "Default calendar","defaultCalendarDescription": "Select the calendar that we should create events in",@@ -521,6 +524,7 @@"optional": "optional","optionalLabel": "(Optional)","optionCount": "{count, plural, one {# option} other {# options}}",+ "optionsSelected": "{count, plural, =0 {None selected} one {# option selected} other {# options selected}}","or": "Or","organizationName": "Organization name","organizationNamePlaceholder": "e.g. Acme Corp",@@ -663,7 +667,6 @@"rsvpVerifyTitle": "Verify your email","save": "Save","saved": "Saved",- "saveInstruction": "Select your availability and click <b>{action}</b>","saving": "Saving...","schedulePoll": "Schedule","schedulePollDescription": "Select a final date for your event.",@@ -680,6 +683,7 @@"securityAuthentication": "Authentication","securityAuthenticationDescription": "Manage how you sign in to your account","securityDescription": "Manage your account security and password settings",+ "selectAtLeastOneOptionOrDecline": "Select at least one option, or decline","selectPlan": "Select plan:","selectPotentialDates": "Select potential dates or times for your event","sendFeedback": "Send feedback",diff --git a/apps/web/src/features/poll/components/desktop-poll.tsx b/apps/web/src/features/poll/components/desktop-poll.tsxindex 40ce53fbd..f2c750ad3 100644--- a/apps/web/src/features/poll/components/desktop-poll.tsx+++ b/apps/web/src/features/poll/components/desktop-poll.tsx@@ -29,6 +29,7 @@ import { ScrollContainer } from "@/components/scroll-container";import { usePermissions, usePoll } from "@/features/poll/client";import { useParticipants } from "@/features/poll/components/participants-provider";import { useVisibleParticipants } from "@/features/poll/components/visibility";+import { VotingFooter } from "@/features/poll/components/voting-footer";import { useVotingForm } from "@/features/poll/components/voting-form";import { Trans, useTranslation } from "@/i18n/client";import ParticipantRow from "./desktop-poll/participant-row";@@ -414,29 +415,8 @@ const DesktopPoll: React.FunctionComponent = () => {</EmptyState>)}{mode === "new" ? (- <div className="flex items-center justify-between gap-4 border-t p-3">- <Button- onClick={() => {- votingForm.cancel();- }}- >- <Trans i18nKey="cancel" />- </Button>- <p className="hidden min-w-0 truncate text-sm md:block">- <Trans- i18nKey="saveInstruction"- defaults="Select your availability and click <b>{action}</b>"- values={{- action: mode === "new" ? t("continue") : t("save"),- }}- components={{- b: <strong className="font-semibold" />,- }}- />- </p>- <Button type="submit" variant="primary" form="voting-form">- <Trans i18nKey="continue" />- </Button>+ <div className="border-t p-3">+ <VotingFooter /></div>) : null}</div>diff --git a/apps/web/src/features/poll/components/desktop-poll/participant-row-form.tsx b/apps/web/src/features/poll/components/desktop-poll/participant-row-form.tsxindex c0b082987..9735b86c0 100644--- a/apps/web/src/features/poll/components/desktop-poll/participant-row-form.tsx+++ b/apps/web/src/features/poll/components/desktop-poll/participant-row-form.tsx@@ -71,7 +71,17 @@ const ParticipantRowForm = ({)}<ParticipantName>{participantName}</ParticipantName></Participant>- {!isNew ? (+ {isNew ? (+ <Button+ variant="ghost"+ size="xs"+ onClick={() => {+ form.cancel();+ }}+ >+ <Trans i18nKey="cancel" defaults="Cancel" />+ </Button>+ ) : (<div className="flex items-center gap-1"><Tooltip><TooltipTrigger@@ -82,27 +92,27 @@ const ParticipantRowForm = ({onClick={() => {form.cancel();}}- size="icon-sm"+ size="icon-xs"><UndoIcon /></Button>}/><TooltipContent>- <Trans i18nKey="cancel" />+ <Trans i18nKey="cancel" defaults="Cancel" /></TooltipContent></Tooltip><Buttonvariant="primary"loading={form.formState.isSubmitting}- size="sm"+ size="xs"form="voting-form"type="submit"><Trans i18nKey="save" /></Button></div>- ) : null}+ )}</div></td>{optionIds.map((optionId, i) => {diff --git a/apps/web/src/features/poll/components/mobile-poll.tsx b/apps/web/src/features/poll/components/mobile-poll.tsxindex 578200433..581435291 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, CardContent, CardFooter } from "@rallly/ui/card";+import { Card, CardFooter } from "@rallly/ui/card";import { Icon } from "@rallly/ui/icon";import {Select,@@ -26,6 +26,7 @@ import { ParticipantDropdown } from "@/features/poll/components/participant-dropimport { ParticipantNote } from "@/features/poll/components/participant-note";import { useOptions, usePoll } from "@/features/poll/components/poll-context";import { useVisibleParticipants } from "@/features/poll/components/visibility";+import { VotingFooter } from "@/features/poll/components/voting-footer";import { useVotingForm } from "@/features/poll/components/voting-form";import { YouAvatar } from "@/features/poll/components/you-avatar";import { useUser } from "@/features/user/client";@@ -46,7 +47,6 @@ const MobilePoll: React.FunctionComponent = () => {const session = useUser();const votingForm = useVotingForm();- const { formState } = votingForm;const selectedParticipantId = votingForm.watch("participantId");@@ -205,9 +205,9 @@ const MobilePoll: React.FunctionComponent = () => {</div></div>{poll.options[0]?.duration !== 0 && poll.timeZone ? (- <CardContent className="border-b">+ <div className="border-b p-2"><TimesShownIn />- </CardContent>+ </div>) : null}<GroupedOptionsselectedParticipantId={selectedParticipantId}@@ -237,16 +237,7 @@ const MobilePoll: React.FunctionComponent = () => {}}><CardFooter className="border-t">- <Button- form="voting-form"- className="w-full"- type="submit"- variant="primary"- size="lg"- loading={formState.isSubmitting}- >- {selectedParticipantId ? t("save") : t("continue")}- </Button>+ <VotingFooter className="flex-1" /></CardFooter></m.div>) : null}diff --git a/apps/web/src/features/poll/components/participant-note.tsx b/apps/web/src/features/poll/components/participant-note.tsxindex ab37c3752..3d6bff783 100644--- a/apps/web/src/features/poll/components/participant-note.tsx+++ b/apps/web/src/features/poll/components/participant-note.tsx@@ -1,7 +1,6 @@"use client";import { Button } from "@rallly/ui/button";-import { Icon } from "@rallly/ui/icon";import { Popover, PopoverContent, PopoverTrigger } from "@rallly/ui/popover";import { MessageSquareTextIcon } from "lucide-react";import TruncatedLinkify from "@/features/poll/components/truncated-linkify";@@ -32,9 +31,7 @@ export function ParticipantNote({size={size}variant="ghost">- <Icon>- <MessageSquareTextIcon />- </Icon>+ <MessageSquareTextIcon /></Button>}/>diff --git a/apps/web/src/features/poll/components/voting-footer.tsx b/apps/web/src/features/poll/components/voting-footer.tsxnew file mode 100644index 000000000..da83d2bbc--- /dev/null+++ b/apps/web/src/features/poll/components/voting-footer.tsx@@ -0,0 +1,133 @@+"use client";+import { cn } from "@rallly/ui";+import { Button } from "@rallly/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ useDialog,+} from "@rallly/ui/dialog";+import { toast } from "@rallly/ui/sonner";++import { useVotingForm } from "@/features/poll/components/voting-form";+import { Trans, useTranslation } from "@/i18n/client";++/**+ * Shared footer for the desktop and mobile voting forms. Announces the+ * selection count to screen readers, offers an explicit decline path for an+ * all-no response (confirming first if it would discard selections), and the+ * Continue/Save submit which is gated until a new participant selects at+ * least one option.+ */+export const VotingFooter = ({ className }: { className?: string }) => {+ const { t } = useTranslation();+ const votingForm = useVotingForm();+ const confirmDialog = useDialog();++ const selectedParticipantId = votingForm.watch("participantId");+ const votes = votingForm.watch("votes");+ const selectedCount = votes.filter(+ (vote) => vote?.type === "yes" || vote?.type === "ifNeedBe",+ ).length;+ const isNewResponse = !selectedParticipantId;+ const isBlocked = isNewResponse && selectedCount === 0;++ const submitAllNo = () => {+ votingForm.setValue(+ "votes",+ votes.map((vote) => (vote ? { ...vote, type: "no" as const } : vote)),+ );+ document.querySelector<HTMLFormElement>("#voting-form")?.requestSubmit();+ };++ return (+ <div+ className={cn("flex items-center gap-x-2.5 md:justify-end", className)}+ >+ {/* Invisible, but keeps vote taps audible for screen readers. */}+ <p aria-live="polite" className="sr-only">+ <Trans+ i18nKey="optionsSelected"+ defaults="{count, plural, =0 {None selected} one {# option selected} other {# options selected}}"+ values={{ count: selectedCount }}+ />+ </p>+ <Button+ type="button"+ className="flex-1 md:flex-none"+ disabled={votingForm.formState.isSubmitting}+ onClick={() => {+ if (selectedCount > 0) {+ confirmDialog.trigger();+ } else {+ submitAllNo();+ }+ }}+ >+ <Trans i18nKey="decline" defaults="Decline" />+ </Button>+ <Button+ form="voting-form"+ type="submit"+ variant="primary"+ className="flex-[2] aria-disabled:opacity-50 md:flex-none"+ aria-disabled={isBlocked}+ loading={votingForm.formState.isSubmitting}+ onClick={(event) => {+ if (isBlocked) {+ event.preventDefault();+ toast(+ t("selectAtLeastOneOptionOrDecline", {+ defaultValue: "Select at least one option, or decline",+ }),+ );+ }+ }}+ >+ {isNewResponse ? (+ <Trans i18nKey="continue" defaults="Continue" />+ ) : (+ <Trans i18nKey="save" defaults="Save" />+ )}+ </Button>+ <Dialog {...confirmDialog.dialogProps}>+ <DialogContent size="sm">+ <DialogHeader>+ <DialogTitle>+ <Trans i18nKey="declineConfirmTitle" defaults="Decline?" />+ </DialogTitle>+ <DialogDescription>+ <Trans+ i18nKey="declineConfirmDescription"+ defaults="{count, plural, one {This will discard your selected option and respond no to everything.} other {This will discard your # selected options and respond no to everything.}}"+ values={{ count: selectedCount }}+ />+ </DialogDescription>+ </DialogHeader>+ <DialogFooter>+ <Button+ onClick={() => {+ confirmDialog.dismiss();+ }}+ >+ <Trans i18nKey="cancel" defaults="Cancel" />+ </Button>+ <Button+ variant="destructive"+ disabled={votingForm.formState.isSubmitting}+ onClick={() => {+ confirmDialog.dismiss();+ submitAllNo();+ }}+ >+ <Trans i18nKey="decline" defaults="Decline" />+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ </div>+ );+};