Skip to content

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

✨ Let users type the seat count in the manage seats dialog (#3405)

Luke Vella5d3f2f36e1c0
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 5a30fccb2..18b0f27cb 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -543,6 +543,7 @@
"manageBilling": "Manage billing",
"manageSeats": "Manage seats",
"manageSeatsDescription": "Adjust the number of seats for your space.",
+ "manageSeatsInputLabel": "Number of seats",
"maxAttendees": "Max attendees",
"maxAttendeesInvalid": "Must be a positive integer",
"member": "Member",
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 27390011e..b2f9864b1 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,6 +1,6 @@
"use client";
-import { cn } from "@rallly/ui";
+import { cn, passwordManagerIgnoreProps } from "@rallly/ui";
import { Button } from "@rallly/ui/button";
import type { DialogProps } from "@rallly/ui/dialog";
import {
@@ -15,7 +15,7 @@ import {
import { NumberTicker } from "@rallly/ui/number-ticker";
import { MinusIcon, PlusIcon } from "lucide-react";
import * as React from "react";
-import { Trans } from "@/i18n/client";
+import { Trans, useTranslation } from "@/i18n/client";
import { trpc } from "@/trpc/client";
const MAX_SEATS = 999;
@@ -90,6 +90,7 @@ export function ManageSeatsDialog({
currentSeats,
usedSeats,
}: DialogProps & { currentSeats: number; usedSeats: number }) {
+ const { t } = useTranslation();
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.
@@ -101,19 +102,59 @@ export function ManageSeatsDialog({
const updateSeats = trpc.billing.updateSeats.useMutation();
+ // Holds the raw text while the field is focused so it can be empty or
+ // mid-edit; null means the ticker shows the committed count.
+ const [draft, setDraft] = React.useState<string | null>(null);
+ const isEditing = draft !== null;
+
+ // MAX_SEATS caps increases only; a space already above it can still step
+ // down one seat at a time.
+ const maxSeats = Math.max(MAX_SEATS, currentSeats);
+ const canIncrement = newSeatCount < MAX_SEATS;
+
+ const updateSeatCount = (next: number) => {
+ const clamped = Math.min(Math.max(next, 1), maxSeats);
+ setNewSeatCount(clamped);
+ setShowUsedSeatsError(clamped < usedSeats);
+ return clamped;
+ };
+
const handleDecrement = () => {
if (newSeatCount <= 1) {
return;
}
- const next = newSeatCount - 1;
- setNewSeatCount(next);
- setShowUsedSeatsError(next < usedSeats);
+ updateSeatCount(newSeatCount - 1);
};
const handleIncrement = () => {
- const next = Math.min(newSeatCount + 1, MAX_SEATS);
- setNewSeatCount(next);
- setShowUsedSeatsError(next < usedSeats);
+ if (!canIncrement) {
+ return;
+ }
+ updateSeatCount(newSeatCount + 1);
+ };
+
+ const handleInputChange = (value: string) => {
+ const digits = value.replace(/\D/g, "").slice(0, String(maxSeats).length);
+ setDraft(digits);
+ const parsed = Number.parseInt(digits, 10);
+ if (parsed >= 1) {
+ updateSeatCount(parsed);
+ }
+ };
+
+ const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === "ArrowUp" || e.key === "ArrowDown") {
+ e.preventDefault();
+ if (e.key === "ArrowUp" && !canIncrement) {
+ return;
+ }
+ const next = updateSeatCount(
+ newSeatCount + (e.key === "ArrowUp" ? 1 : -1),
+ );
+ setDraft(String(next));
+ } else if (e.key === "Enter") {
+ e.currentTarget.blur();
+ }
};
const handleUpdate = async () => {
@@ -150,18 +191,46 @@ export function ManageSeatsDialog({
</span>
</Button>
<SeatGauge usedSeats={usedSeats} totalSeats={newSeatCount}>
- <NumberTicker
- value={newSeatCount}
- announceChanges
- duration={0.4}
- className="inline-flex w-[3ch] justify-center font-semibold text-3xl"
- />
+ <span className="relative inline-flex font-semibold text-3xl">
+ <NumberTicker
+ value={newSeatCount}
+ announceChanges
+ duration={0.4}
+ className={cn(
+ "inline-flex w-[3ch] justify-center",
+ isEditing && "invisible",
+ )}
+ />
+ <input
+ {...passwordManagerIgnoreProps}
+ type="text"
+ inputMode="numeric"
+ autoComplete="off"
+ aria-label={t("manageSeatsInputLabel", {
+ defaultValue: "Number of seats",
+ })}
+ value={draft ?? String(newSeatCount)}
+ onFocus={(e) => {
+ setDraft(String(newSeatCount));
+ e.currentTarget.select();
+ }}
+ onBlur={() => setDraft(null)}
+ onChange={(e) => handleInputChange(e.target.value)}
+ onKeyDown={handleInputKeyDown}
+ className={cn(
+ "absolute inset-0 w-full appearance-none border-0 bg-transparent p-0 text-center tabular-nums outline-none",
+ isEditing
+ ? "text-foreground"
+ : "text-transparent caret-transparent",
+ )}
+ />
+ </span>
</SeatGauge>
<Button
size="icon-lg"
className="rounded-full"
onClick={handleIncrement}
- disabled={newSeatCount >= MAX_SEATS}
+ disabled={!canIncrement}
>
<PlusIcon />
<span className="sr-only">