Skip to content

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

✨ Rebuild the manage seats dialog around a seat gauge (#3322)

Luke Vella97e6afc581b8
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 7dacfb33c..ab8658642 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -199,7 +199,6 @@
"createSpaceDescription": "Create a new space to organize your polls and events.",
"cropPreview": "Crop preview",
"currency": "Currency",
- "currentlyUsing": "Currently using {usedSeats} of {currentSeats} seats",
"currentPassword": "Current password",
"currentPlan": "Current plan",
"customBranding": "Custom branding",
@@ -624,7 +623,6 @@
"noUsers": "No users found",
"noUsersDescription": "Try adjusting your search",
"noVotes": "No one has voted for this option",
- "numberOfSeats": "Number of seats",
"oidcAutoSignInDescription": "You are being redirected to the login page...",
"openPollCount": "{count, plural, other {# open}}",
"optional": "(optional)",
@@ -811,6 +809,8 @@
"searchUsers": "Search users...",
"seatCount": "{count, plural, one {# seat} other {# seats}}",
"seatsAvailable": "{count, plural, =0 {No seats available} one {# seat available} other {# seats available}}",
+ "seatsBelowUsedError": "You can only remove unused seats. Remove members first.",
+ "seatsUnusedCount": "{used} of {total} seats used",
"seatsUpdatedAlertTitle": "Seats updated",
"security": "Security",
"securityAuthentication": "Authentication",
@@ -926,7 +926,6 @@
"titlePlaceholder": "Monthly Meetup",
"today": "Today",
"tooManyVerificationAttempts": "Too many incorrect attempts. Request a new code to continue.",
- "totalSeats": "Total seats",
"tryAgain": "Try again",
"unbanUser": "Unban user",
"unconfirmedEventsEmptyStateDescription": "Unconfirmed events will show up here.",
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx
index adac8d92a..710e841d2 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/manage-seats-dialog.tsx
@@ -1,5 +1,6 @@
"use client";
+import { cn } from "@rallly/ui";
import { Button } from "@rallly/ui/button";
import type { DialogProps } from "@rallly/ui/dialog";
import {
@@ -11,109 +12,73 @@ import {
DialogHeader,
DialogTitle,
} from "@rallly/ui/dialog";
-
-import { Input } from "@rallly/ui/input";
-import { Label } from "@rallly/ui/label";
import { MinusIcon, PlusIcon } from "lucide-react";
-import { useCallback, useState } from "react";
-import { Trans, useTranslation } from "@/i18n/client";
+import * as React from "react";
+import { NumberTicker } from "@/components/number-ticker";
+import { Trans } from "@/i18n/client";
import { trpc } from "@/trpc/client";
-interface ManageSeatsButtonProps {
- currentSeats: number;
- usedSeats: number;
-}
-
-interface SeatCountSelectorProps {
- value: number;
- onChange: (value: number) => void;
- currentSeats: number;
- minSeats: number;
-}
-
-function SeatCountSelector({
- value,
- onChange,
- currentSeats,
- minSeats,
-}: SeatCountSelectorProps) {
- const { t } = useTranslation();
- const handleIncrement = useCallback(() => {
- onChange(value + 1);
- }, [value, onChange]);
-
- const handleDecrement = useCallback(() => {
- if (value > minSeats) {
- onChange(value - 1);
- }
- }, [value, minSeats, onChange]);
-
- const handleInputChange = useCallback(
- (e: React.ChangeEvent<HTMLInputElement>) => {
- const inputValue = e.target.value;
-
- // Allow empty input for better UX while typing
- if (inputValue === "") {
- return;
- }
+const MAX_SEATS = 999;
- const numValue = Number.parseInt(inputValue, 10);
+const GAUGE_SIZE = 88;
+const GAUGE_STROKE = 6;
+const GAUGE_RADIUS = (GAUGE_SIZE - GAUGE_STROKE) / 2;
+const GAUGE_CIRCUMFERENCE = 2 * Math.PI * GAUGE_RADIUS;
- // Only update if it's a valid positive integer
- if (!Number.isNaN(numValue) && numValue >= minSeats && numValue <= 999) {
- onChange(numValue);
- }
- },
- [minSeats, onChange],
- );
-
- const handleInputBlur = useCallback(() => {
- // If the input is empty or invalid on blur, reset to current value
- if (value < minSeats || Number.isNaN(value)) {
- onChange(currentSeats);
- }
- }, [value, minSeats, currentSeats, onChange]);
-
- const canDecrement = value > minSeats;
- const canIncrement = value < 999; // Reasonable upper limit
+/**
+ * Ring around the seat count showing how much of the new total is already
+ * taken. Over-allocation (fewer seats than members) fills the ring and turns
+ * destructive, so the error message is not the only signal.
+ */
+function SeatGauge({
+ usedSeats,
+ totalSeats,
+ children,
+}: {
+ usedSeats: number;
+ totalSeats: number;
+ children: React.ReactNode;
+}) {
+ const ratio = totalSeats > 0 ? Math.min(usedSeats / totalSeats, 1) : 1;
+ const overAllocated = usedSeats > totalSeats;
return (
- <div>
- <div className="flex items-center gap-2">
- <Button
- type="button"
- variant="default"
- onClick={handleDecrement}
- disabled={!canDecrement}
- >
- <MinusIcon data-icon="inline-start" />
- <span className="sr-only">
- <Trans i18nKey="decreaseSeats" defaults="Decrease seats" />
- </span>
- </Button>
-
- <Input
- type="number"
- aria-label={t("numberOfSeats", { defaultValue: "Number of seats" })}
- value={value}
- onChange={handleInputChange}
- onBlur={handleInputBlur}
- min={minSeats}
- max={999}
- className="w-20 text-center"
+ <div
+ className="relative flex shrink-0 items-center justify-center"
+ style={{ width: GAUGE_SIZE, height: GAUGE_SIZE }}
+ >
+ <svg
+ className="absolute inset-0 -rotate-90"
+ width={GAUGE_SIZE}
+ height={GAUGE_SIZE}
+ aria-hidden="true"
+ >
+ <circle
+ className="text-border"
+ cx={GAUGE_SIZE / 2}
+ cy={GAUGE_SIZE / 2}
+ r={GAUGE_RADIUS}
+ fill="none"
+ stroke="currentColor"
+ strokeWidth={GAUGE_STROKE}
/>
-
- <Button
- type="button"
- onClick={handleIncrement}
- disabled={!canIncrement}
- >
- <PlusIcon data-icon="inline-start" />
- <span className="sr-only">
- <Trans i18nKey="increaseSeats" defaults="Increase seats" />
- </span>
- </Button>
- </div>
+ <circle
+ className={cn(
+ "transition-[stroke-dashoffset,color] duration-300 ease-out motion-reduce:transition-none",
+ overAllocated ? "text-destructive" : "text-primary",
+ )}
+ cx={GAUGE_SIZE / 2}
+ cy={GAUGE_SIZE / 2}
+ r={GAUGE_RADIUS}
+ fill="none"
+ stroke="currentColor"
+ strokeWidth={GAUGE_STROKE}
+ strokeLinecap="round"
+ strokeDasharray={GAUGE_CIRCUMFERENCE}
+ strokeDashoffset={GAUGE_CIRCUMFERENCE * (1 - ratio)}
+ />
+ </svg>
+ {children}
</div>
);
}
@@ -124,16 +89,33 @@ export function ManageSeatsDialog({
children,
currentSeats,
usedSeats,
-}: DialogProps & ManageSeatsButtonProps) {
- const [newSeatCount, setNewSeatCount] = useState(currentSeats);
+}: DialogProps & { currentSeats: number; usedSeats: number }) {
+ const [newSeatCount, setNewSeatCount] = React.useState(currentSeats);
+ // The stepper is allowed below usedSeats so the reason surfaces as a
+ // message; a silently clamped button leaves the user guessing.
+ const [showUsedSeatsError, setShowUsedSeatsError] = React.useState(false);
+
const seatDelta = newSeatCount - currentSeats;
- const isRemoving = seatDelta < 0;
- const isAdding = seatDelta > 0;
- const canRemoveSeats = newSeatCount >= usedSeats;
+ const belowUsedSeats = newSeatCount < usedSeats;
const hasChanges = seatDelta !== 0;
const updateSeats = trpc.billing.updateSeats.useMutation();
+ const handleDecrement = () => {
+ if (newSeatCount <= 1) {
+ return;
+ }
+ const next = newSeatCount - 1;
+ setNewSeatCount(next);
+ setShowUsedSeatsError(next < usedSeats);
+ };
+
+ const handleIncrement = () => {
+ const next = Math.min(newSeatCount + 1, MAX_SEATS);
+ setNewSeatCount(next);
+ setShowUsedSeatsError(next < usedSeats);
+ };
+
const handleUpdate = async () => {
const { url } = await updateSeats.mutateAsync({ seatDelta });
window.location.href = url;
@@ -142,7 +124,7 @@ export function ManageSeatsDialog({
return (
<Dialog open={open} onOpenChange={onOpenChange}>
{children}
- <DialogContent size="md">
+ <DialogContent size="sm" className="sm:max-w-xs">
<DialogHeader>
<DialogTitle>
<Trans i18nKey="manageSeats" defaults="Manage seats" />
@@ -154,44 +136,76 @@ export function ManageSeatsDialog({
/>
</DialogDescription>
</DialogHeader>
- <div className="flex items-end justify-between gap-4">
- <div>
- <Label className="mb-2">
- <Trans i18nKey="totalSeats" defaults="Total seats" />
- </Label>
-
- <p className="mt-1 text-muted-foreground text-sm">
+ <div className="flex flex-col items-center gap-3 py-2">
+ <div className="flex items-center gap-6">
+ <Button
+ size="icon-lg"
+ className="rounded-full"
+ onClick={handleDecrement}
+ disabled={newSeatCount <= 1}
+ >
+ <MinusIcon />
+ <span className="sr-only">
+ <Trans i18nKey="decreaseSeats" defaults="Decrease seats" />
+ </span>
+ </Button>
+ <SeatGauge usedSeats={usedSeats} totalSeats={newSeatCount}>
+ <NumberTicker
+ value={newSeatCount}
+ startOnView={false}
+ announceChanges
+ duration={0.4}
+ className="w-[3ch] justify-center font-semibold text-3xl"
+ />
+ </SeatGauge>
+ <Button
+ size="icon-lg"
+ className="rounded-full"
+ onClick={handleIncrement}
+ disabled={newSeatCount >= MAX_SEATS}
+ >
+ <PlusIcon />
+ <span className="sr-only">
+ <Trans i18nKey="increaseSeats" defaults="Increase seats" />
+ </span>
+ </Button>
+ </div>
+ {showUsedSeatsError ? null : (
+ <p className="text-center text-muted-foreground text-sm">
<Trans
- i18nKey="currentlyUsing"
- defaults="Currently using {usedSeats} of {currentSeats} seats"
- values={{ usedSeats, currentSeats }}
+ i18nKey="seatsUnusedCount"
+ defaults="{used} of {total} seats used"
+ values={{ used: usedSeats, total: newSeatCount }}
/>
</p>
- </div>
- <SeatCountSelector
- value={newSeatCount}
- onChange={setNewSeatCount}
- currentSeats={currentSeats}
- minSeats={usedSeats}
- />
+ )}
+ {showUsedSeatsError ? (
+ <p role="alert" className="text-center text-destructive text-sm">
+ <Trans
+ i18nKey="seatsBelowUsedError"
+ defaults="You can only remove unused seats. Remove members first."
+ />
+ </p>
+ ) : null}
</div>
- <DialogFooter>
- <DialogClose render={<Button />}>
+ <DialogFooter className="flex-col-reverse gap-2 sm:flex-col-reverse">
+ <DialogClose render={<Button className="w-full" />}>
<Trans i18nKey="cancel" defaults="Cancel" />
</DialogClose>
<Button
+ className="w-full"
variant="primary"
onClick={handleUpdate}
- disabled={!canRemoveSeats || !hasChanges}
+ disabled={belowUsedSeats || !hasChanges}
loading={updateSeats.isPending}
>
- {isAdding ? (
+ {seatDelta > 0 ? (
<Trans
i18nKey="addSeats"
defaults="{count, plural, one {Add # seat} other {Add # seats}}"
values={{ count: seatDelta }}
/>
- ) : isRemoving ? (
+ ) : seatDelta < 0 ? (
<Trans
i18nKey="removeSeats"
defaults="{count, plural, one {Remove # seat} other {Remove # seats}}"
diff --git a/apps/web/src/components/number-ticker.tsx b/apps/web/src/components/number-ticker.tsx
new file mode 100644
index 000000000..23e44a0c5
--- /dev/null
+++ b/apps/web/src/components/number-ticker.tsx
@@ -0,0 +1,190 @@
+"use client";
+// beui.dev/components/motion/number
+
+import { cn } from "@rallly/ui";
+import { animate, motion, useInView, useReducedMotion } from "motion/react";
+import { useEffect, useMemo, useRef, useState } from "react";
+import { EASE_OUT } from "@/lib/ease";
+
+export interface NumberTickerProps {
+ value: number;
+ /** Digits to pad to (left). */
+ pad?: number;
+ /** Per-digit roll duration in seconds. */
+ duration?: number;
+ /** Stagger between digits. */
+ stagger?: number;
+ /** Render only after the element enters the viewport. */
+ startOnView?: boolean;
+ prefix?: string;
+ suffix?: string;
+ /** Add a small blur during digit rolls. */
+ blur?: boolean;
+ className?: string;
+ digitClassName?: string;
+ /** Custom formatter, e.g. for group separators. */
+ format?: (value: number) => string;
+ /**
+ * Announce each new value politely. Off by default: a ticker that counts up
+ * as decoration would otherwise interrupt a screen reader on every frame.
+ * Turn it on where the number is the thing the user is changing.
+ */
+ announceChanges?: boolean;
+}
+
+const DIGIT_HEIGHT_EM = 1.1;
+const DIGITS = Array.from({ length: 10 }, (_, n) => n);
+
+export function NumberTicker({
+ value,
+ pad,
+ duration = 0.9,
+ stagger = 0.04,
+ startOnView = true,
+ prefix,
+ suffix,
+ blur = false,
+ className,
+ digitClassName,
+ format,
+ announceChanges = false,
+}: NumberTickerProps) {
+ const containerRef = useRef<HTMLSpanElement>(null);
+ const inView = useInView(containerRef, { once: true, amount: 0.6 });
+ const [armed, setArmed] = useState(!startOnView);
+
+ useEffect(() => {
+ if (startOnView && inView) setArmed(true);
+ }, [startOnView, inView]);
+
+ const text = useMemo(() => {
+ const rounded = Math.round(value);
+ const formatted = format ? format(rounded) : String(rounded);
+ return pad ? formatted.padStart(pad, "0") : formatted;
+ }, [value, pad, format]);
+ const glyphs = useMemo(() => {
+ const chars = text.split("");
+ // Key by place value (position from the right): a changing digit keeps its
+ // identity and rolls to the new value instead of remounting and replaying
+ // from 0. Growing numbers add glyphs on the left without re-keying the
+ // ones, tens, hundreds already on screen.
+ return chars.map((char, i) => ({ char, id: `g-${chars.length - 1 - i}` }));
+ }, [text]);
+ const readableText = `${prefix ?? ""}${text}${suffix ?? ""}`;
+
+ // Stagger is an entrance flourish. Once the reveal has played, value
+ // changes roll every digit immediately — a per-digit delay on live updates
+ // reads as lag.
+ const [entered, setEntered] = useState(false);
+ useEffect(() => {
+ if (!armed || entered) return;
+ const total = (duration + glyphs.length * stagger) * 1000;
+ const t = window.setTimeout(() => setEntered(true), total);
+ return () => window.clearTimeout(t);
+ }, [armed, entered, duration, stagger, glyphs.length]);
+
+ return (
+ <span
+ ref={containerRef}
+ className={cn("inline-flex items-center tabular-nums", className)}
+ >
+ <span
+ className="sr-only"
+ aria-live={announceChanges ? "polite" : undefined}
+ aria-atomic={announceChanges ? "true" : undefined}
+ >
+ {readableText}
+ </span>
+ <span aria-hidden="true" className="inline-flex items-center">
+ {prefix ? <span>{prefix}</span> : null}
+ {glyphs.map(({ char, id }, i) => {
+ const isDigit = /\d/.test(char);
+ if (!isDigit) {
+ return (
+ <span key={id} className="inline-block">
+ {char}
+ </span>
+ );
+ }
+ const digit = Number(char);
+ return (
+ <Digit
+ key={id}
+ digit={armed ? digit : 0}
+ delay={entered ? 0 : i * stagger}
+ duration={duration}
+ blur={blur}
+ className={digitClassName}
+ />
+ );
+ })}
+ {suffix ? <span>{suffix}</span> : null}
+ </span>
+ </span>
+ );
+}
+
+function Digit({
+ digit,
+ delay,
+ duration,
+ blur,
+ className,
+}: {
+ digit: number;
+ delay: number;
+ duration: number;
+ blur: boolean;
+ className?: string;
+}) {
+ const reduce = useReducedMotion();
+ const columnRef = useRef<HTMLSpanElement>(null);
+
+ useEffect(() => {
+ if (reduce || !blur || !columnRef.current || !Number.isFinite(digit)) {
+ return;
+ }
+
+ const node = columnRef.current;
+ const controls = animate(
+ node,
+ { filter: ["blur(10px)", "blur(0px)"] },
+ {
+ duration: Math.min(duration * 0.75, 0.32),
+ delay,
+ ease: EASE_OUT,
+ },
+ );
+
+ return () => {
+ controls.stop();
+ node.style.filter = "blur(0px)";
+ };
+ }, [blur, delay, digit, duration, reduce]);
+
+ return (
+ <span
+ className={cn("relative inline-block overflow-hidden", className)}
+ style={{ height: `${DIGIT_HEIGHT_EM}em`, width: "1ch" }}
+ >
+ <motion.span
+ ref={columnRef}
+ initial={{ y: 0 }}
+ animate={{ y: `-${digit * DIGIT_HEIGHT_EM}em` }}
+ transition={
+ reduce ? { duration: 0 } : { duration, delay, ease: EASE_OUT }
+ }
+ className="absolute inset-x-0 top-0 flex flex-col items-center will-change-[transform,filter]"
+ >
+ {DIGITS.map((n) => (
+ <span
+ key={n}
+ className="flex h-[1.1em] items-center justify-center leading-none"
+ >
+ {n}
+ </span>
+ ))}
+ </motion.span>
+ </span>
+ );
+}
diff --git a/apps/web/src/lib/ease.ts b/apps/web/src/lib/ease.ts
new file mode 100644
index 000000000..c46f60b73
--- /dev/null
+++ b/apps/web/src/lib/ease.ts
@@ -0,0 +1,57 @@
+// Shared motion tokens. Easing curves mirror the CSS custom properties in
+// globals.css; springs are the canonical physics used across components.
+// Strong custom variants — defaults like `ease-in`/`ease-out` feel weak.
+
+export const EASE_OUT = [0.16, 1, 0.3, 1] as const;
+export const EASE_IN_OUT = [0.77, 0, 0.175, 1] as const;
+export const EASE_DRAWER = [0.32, 0.72, 0, 1] as const;
+
+/** CSS string form of EASE_OUT for inline style transitions. */
+export const EASE_OUT_CSS = "cubic-bezier(0.16, 1, 0.3, 1)";
+
+/** Press feedback on buttons and other tappable surfaces. */
+export const SPRING_PRESS = {
+ type: "spring",
+ stiffness: 500,
+ damping: 30,
+ mass: 0.6,
+} as const;
+
+/** Content swaps — label/icon slots trading places inside a control. */
+export const SPRING_SWAP = {
+ type: "spring",
+ stiffness: 460,
+ damping: 30,
+ mass: 0.55,
+} as const;
+
+/** Overlay panel entrances — modals and sheets summoned by pointer. */
+export const SPRING_PANEL = {
+ type: "spring",
+ stiffness: 420,
+ damping: 40,
+ mass: 0.5,
+} as const;
+
+/** Shared-layout glides — pills, indicators and panels morphing between positions. */
+export const SPRING_LAYOUT = {
+ type: "spring",
+ stiffness: 360,
+ damping: 32,
+ mass: 0.6,
+} as const;
+
+/** Cursor-follow physics for decorative mouse tracking (magnetic, tilt, dock). */
+export const SPRING_MOUSE = {
+ stiffness: 200,
+ damping: 15,
+ mass: 0.3,
+} as const;
+
+/** Dragged handles and fills (sliders) — critically damped `useSpring` config,
+ * so the value follows the pointer butterily and never rebounds off an end. */
+export const SPRING_GLIDE = {
+ stiffness: 700,
+ damping: 50,
+ mass: 0.5,
+} as const;