Skip to content

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

♻️ Adopt Setting rows on the General space settings page (#2839)

Luke Vella99dbd788b894
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 4c70ee3a6..430197471 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -91,7 +91,10 @@
"billingSettingsDescription": "View and manage your space's subscription and billing information.",
"billingSubscriptionDescription": "Manage your current subscription plan.",
"branding": "Branding",
+ "brandingCardDescription": "How your space appears to you and the people you invite",
"brandingDescription": "View your instance branding configuration",
+ "brandingPreviewEventTitle": "Team Offsite",
+ "brandingPreviewLocation": "The Old Fire Station",
"calendar": "Calendar",
"calendarDisconnectedError": "Failed to disconnect calendar",
"calendarDisconnectedSuccess": "Calendar disconnected successfully",
@@ -181,6 +184,8 @@
"customBrandingPromptCta": "Set Up Now",
"customBrandingPromptDescription": "Get professional scheduling polls with your own logo and colors.",
"customBrandingPromptTitle": "Custom Branding",
+ "customBrandingSettingLabel": "Show your logo and colors to participants.",
+ "customBrandingSettingTitle": "Custom branding",
"dangerZone": "Danger Zone",
"dangerZoneAccountDeletion": "Delete your account and all data associated with it",
"dates": "Dates",
@@ -215,11 +220,11 @@
"deletePollPrompt": "Are you sure you want to delete <b>{title}</b>?",
"deleteSpace": "Delete Space",
"deleteSpaceConfirmLabel": "Confirm space name",
- "deleteSpaceDescription": "Permanently delete this space and all its contents. This action cannot be undone.",
"deleteSpaceDialogDescription": "This will permanently delete the space and all polls inside it. This action cannot be undone.",
"deleteSpaceDialogTitle": "Delete Space",
"deleteSpaceInstruction": "Please type the space name to confirm:",
"deleteSpacePermanently": "Delete Space Permanently",
+ "deleteSpaceSettingHint": "Permanently delete this space and everything in it.",
"deleteUserDesc": "Are you sure you want to delete this user?",
"deleteUserHint": "Type <b>{email}</b> to delete this user.",
"deleteUserTitle": "Delete User",
@@ -373,6 +378,7 @@
"leaveSpaceDialogDescription": "Are you sure you want to leave this space?",
"leaveSpaceDialogTitle": "Leave Space",
"leaveSpaceInstruction": "Please type the space name to confirm:",
+ "leaveSpaceSettingHint": "Remove yourself from this space and lose access to its polls.",
"leftSpaceSuccess": "You have left the space",
"license": "License",
"licenseeEmail": "Licensee Email",
@@ -562,11 +568,14 @@
"poweredByRallly": "Powered by <a>{name}</a>",
"preferences": "Preferences",
"preferencesDescription": "Manage your preferences",
+ "preview": "Preview",
"previousMonth": "Previous month",
"previousWeek": "Previous week",
"priceFree": "Free",
"primaryColor": "Primary Color",
"primaryColorDark": "Primary Color (Dark Mode)",
+ "primaryColorSettingHint": "Used for buttons and highlights.",
+ "primaryColorSettingTitle": "Primary color",
"prioritySupport": "Priority Support",
"prioritySupportDescription": "Get faster response times and dedicated assistance",
"profile": "Profile",
@@ -604,6 +613,7 @@
"resetPasswordFooter": "Don't need to reset? <a>Back to login</a>",
"resetPasswordInvalidTokenMessage": "The password reset link is invalid or has expired. Please request a new one.",
"resetPasswordTitle": "Reset Password",
+ "resetToDefault": "Reset to default",
"respondedOn": "Responded on",
"response": "Response",
"responseOptions": "Response Options",
@@ -675,7 +685,6 @@
"setupPasswordAlertTitle": "Login quicker with a password",
"setupPasswordButton": "Set up password",
"share": "Share",
- "showBrandingDescription": "Show your brand identity on your public pages and emails",
"showPassword": "Show password",
"shrink": "Shrink",
"signIn": "Sign in",
@@ -683,9 +692,12 @@
"signUp": "Sign Up",
"skipToContent": "Skip to main content",
"space": "Space",
+ "spaceDangerZoneDescription": "These actions cannot be undone",
"spaceInviteMember": "Invite Member",
+ "spaceLogoSettingHint": "Your space's logo.",
"spaceNameMismatch": "Space name does not match",
"spaceNamePlaceholder": "My Team",
+ "spaceNameSettingLabel": "What this space is called.",
"spaces": "Spaces",
"spacesDescription": "Manage the spaces you belong to",
"spaceSettings": "Space Settings",
@@ -759,7 +771,6 @@
"uploadImage": "Upload",
"url": "URL",
"urlInvalid": "Must be a valid URL",
- "useCustomBranding": "Enable Custom Branding",
"user": "User",
"userCount": "{count, number, ::compact-short}",
"userRegistration": "User Registration",
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/branding-preview.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/branding-preview.tsx
new file mode 100644
index 000000000..ad6e304aa
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/branding-preview.tsx
@@ -0,0 +1,114 @@
+"use client";
+
+import { Badge } from "@rallly/ui/badge";
+import { Card, CardContent } from "@rallly/ui/card";
+import { MapPinIcon, User2Icon } from "lucide-react";
+import React from "react";
+import { getPrimaryColorVars } from "@/features/branding/utils";
+import {
+ EventMetaItem,
+ EventMetaList,
+ EventMetaTitle,
+} from "@/features/poll/components/event-meta";
+import { SpaceIcon } from "@/features/space/components/space-icon";
+import { Trans } from "@/i18n/client";
+
+// Taller than the card it frames: the card runs past the bottom edge and is
+// cropped, which is what makes it read as a window onto a longer page. The
+// extra height over the original 220 is top padding, so the same amount of
+// card stays visible before the crop.
+const PREVIEW_HEIGHT = 252;
+
+/**
+ * Approximates the poll invite card so the chosen color can be judged against
+ * the surface it actually lands on. The branded variables are scoped to this
+ * container rather than :root so they can't bleed into the settings chrome.
+ *
+ * The card is deliberately taller than the frame and cropped, with a fade at
+ * the bottom edge, to read as a window onto a longer page rather than a
+ * complete card whose content happens to be sparse.
+ *
+ * Sits in the SettingHint slot of the row whose switch controls it, so the
+ * preview reads as evidence for that setting rather than a separate panel.
+ */
+export function BrandingPreview({
+ spaceName,
+ spaceImage,
+ primaryColor,
+ hostName,
+}: {
+ spaceName: string;
+ spaceImage?: string | null;
+ primaryColor: string;
+ hostName: string;
+}) {
+ const vars = React.useMemo(
+ () => getPrimaryColorVars(primaryColor),
+ [primaryColor],
+ );
+
+ return (
+ <div
+ // The public page follows the viewer's theme, so both sets of values are
+ // supplied and the dark variants swap them in.
+ style={
+ {
+ "--primary": vars.light,
+ "--primary-foreground": vars.lightForeground,
+ "--preview-primary-dark": vars.dark,
+ "--preview-primary-dark-foreground": vars.darkForeground,
+ height: PREVIEW_HEIGHT,
+ } as React.CSSProperties
+ }
+ className="relative overflow-hidden rounded-lg border bg-gray-100 px-4 pt-12 dark:bg-gray-900 dark:[--primary-foreground:var(--preview-primary-dark-foreground)] dark:[--primary:var(--preview-primary-dark)]"
+ >
+ <Badge className="absolute top-2.5 right-3 z-10" size="sm">
+ <Trans i18nKey="preview" defaults="Preview" />
+ </Badge>
+ {/* Decorative: it restates settings already present as real controls */}
+ <div className="mx-auto max-w-sm" aria-hidden="true">
+ <Card>
+ {/* The branded bar, mirroring RandomGradientBar on the real card */}
+ <div className="-mx-px -mt-px h-2 rounded-t-2xl bg-linear-to-r from-primary to-primary/75" />
+ <CardContent>
+ <div className="mb-2">
+ <SpaceIcon
+ name={spaceName}
+ src={spaceImage ?? undefined}
+ size="xl"
+ />
+ <p className="mt-2 truncate font-medium text-muted-foreground text-sm">
+ {spaceName}
+ </p>
+ </div>
+ <EventMetaTitle>
+ <Trans
+ i18nKey="brandingPreviewEventTitle"
+ defaults="Team Offsite"
+ />
+ </EventMetaTitle>
+ <EventMetaList className="mt-4">
+ <EventMetaItem>
+ <User2Icon />
+ <Trans
+ i18nKey="organizedBy"
+ defaults="Organized by {name}"
+ values={{ name: hostName }}
+ />
+ </EventMetaItem>
+ <EventMetaItem>
+ <MapPinIcon />
+ <Trans
+ i18nKey="brandingPreviewLocation"
+ defaults="The Old Fire Station"
+ />
+ </EventMetaItem>
+ </EventMetaList>
+ </CardContent>
+ </Card>
+ </div>
+ {/* Fades the cropped edge so the card reads as continuing below */}
+ <div className="pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-linear-to-b from-transparent to-gray-100 dark:to-gray-900" />
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
index 7f2c173c7..dc5485b2d 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
@@ -1,10 +1,12 @@
"use client";
-import { Button } from "@rallly/ui/button";
+import type { Color } from "@rallly/ui/color-picker";
import { ColorPicker, parseColor } from "@rallly/ui/color-picker";
-import { Field, FieldGroup, FieldLabel } from "@rallly/ui/field";
+import { InputGroupButton } from "@rallly/ui/input-group";
import { toast } from "@rallly/ui/sonner";
import { Switch } from "@rallly/ui/switch";
+import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";
+import { CheckIcon, RotateCcwIcon } from "lucide-react";
import React from "react";
import {
PageSection,
@@ -13,6 +15,16 @@ import {
PageSectionHeader,
PageSectionTitle,
} from "@/components/page-layout";
+import {
+ Setting,
+ SettingControl,
+ SettingDescription,
+ SettingHint,
+ SettingRow,
+ SettingsGroup,
+ SettingTitle,
+ useSettingLabels,
+} from "@/components/setting";
import { showPayWall, useIsFree } from "@/features/billing/client";
import { ProBadge } from "@/features/billing/components/pro-badge";
import { DEFAULT_PRIMARY_COLOR } from "@/features/branding/constants";
@@ -21,8 +33,11 @@ import {
updateSpaceShowBrandingAction,
} from "@/features/space/actions";
import { useSpace } from "@/features/space/client";
+import { useAuthedUser } from "@/features/user/client";
import { Trans, useTranslation } from "@/i18n/client";
import { useSafeAction } from "@/lib/safe-action/client";
+import { BrandingPreview } from "./branding-preview";
+import { SpaceSettingsForm } from "./space-settings-form";
export function CustomBrandingSection({
disabled = false,
@@ -30,13 +45,17 @@ export function CustomBrandingSection({
disabled?: boolean;
}) {
const { data: space } = useSpace();
+ const user = useAuthedUser();
const isFree = useIsFree();
const { t } = useTranslation();
const currentColor = space.primaryColor ?? DEFAULT_PRIMARY_COLOR;
const [color, setColor] = React.useState(() => parseColor(currentColor));
const hexColor = color.toString("hex");
- const isDirty = hexColor !== currentColor;
+ // Stored values may differ in case from what the picker emits
+ const isDirty = hexColor.toLowerCase() !== currentColor.toLowerCase();
+ const isDefault =
+ hexColor.toLowerCase() === DEFAULT_PRIMARY_COLOR.toLowerCase();
const updateShowBranding = useSafeAction(updateSpaceShowBrandingAction);
const updateSpace = useSafeAction(updateSpaceAction);
@@ -71,11 +90,13 @@ export function CustomBrandingSection({
if (result?.serverError || result?.validationErrors) {
setPendingShowBranding(null);
+ return;
}
+
+ toast.success(t("saved", { defaultValue: "Saved" }));
};
- const handleSave = async () => {
- const value = hexColor === DEFAULT_PRIMARY_COLOR ? null : hexColor;
+ const persistColor = async (value: string | null) => {
const result = await updateSpace.executeAsync({ primaryColor: value });
if (!result?.serverError && !result?.validationErrors) {
@@ -83,6 +104,15 @@ export function CustomBrandingSection({
}
};
+ const handleSave = () => persistColor(isDefault ? null : hexColor);
+
+ // Clearing the column is what "default" means in the database, so reset
+ // writes null rather than storing the default value literally.
+ const handleReset = async () => {
+ setColor(parseColor(DEFAULT_PRIMARY_COLOR));
+ await persistColor(null);
+ };
+
return (
<PageSection variant="card">
<PageSectionHeader>
@@ -91,54 +121,154 @@ export function CustomBrandingSection({
</PageSectionTitle>
<PageSectionDescription>
<Trans
- i18nKey="showBrandingDescription"
- defaults="Show your brand identity on your public pages and emails"
+ i18nKey="brandingCardDescription"
+ defaults="How your space appears to you and the people you invite"
/>
</PageSectionDescription>
</PageSectionHeader>
<PageSectionContent>
- <FieldGroup>
- <Field orientation="horizontal">
- <Switch
- checked={showBranding}
- onCheckedChange={handleToggle}
- disabled={disabled || updateShowBranding.isExecuting}
- />
- <FieldLabel>
+ <SettingsGroup>
+ <SpaceSettingsForm space={space} disabled={disabled} />
+ <SettingRow>
+ <SettingTitle>
<Trans
- i18nKey="useCustomBranding"
- defaults="Enable Custom Branding"
+ i18nKey="primaryColorSettingTitle"
+ defaults="Primary color"
+ />
+ </SettingTitle>
+ <SettingDescription>
+ <Trans
+ i18nKey="primaryColorSettingHint"
+ defaults="Used for buttons and highlights."
+ />
+ </SettingDescription>
+ <SettingControl>
+ <PrimaryColorField
+ value={color}
+ onChange={setColor}
+ disabled={disabled}
+ isDefault={isDefault}
+ isDirty={isDirty}
+ isSaving={updateSpace.isExecuting}
+ onSave={handleSave}
+ onReset={handleReset}
+ />
+ </SettingControl>
+ </SettingRow>
+ <Setting>
+ <SettingTitle>
+ <Trans
+ i18nKey="customBrandingSettingTitle"
+ defaults="Custom branding"
/>
{space.tier !== "pro" && <ProBadge />}
- </FieldLabel>
- </Field>
- <div
- className={
- !showBranding || disabled
- ? "pointer-events-none opacity-50"
- : undefined
- }
- >
- <FieldGroup>
- <Field>
- <FieldLabel>
- <Trans i18nKey="primaryColor" defaults="Primary Color" />
- </FieldLabel>
- <ColorPicker value={color} onChange={setColor} />
- </Field>
- <Field orientation="horizontal">
- <Button
- onClick={handleSave}
- disabled={!showBranding || !isDirty || disabled}
- loading={updateSpace.isExecuting}
- >
- <Trans i18nKey="save" defaults="Save" />
- </Button>
- </Field>
- </FieldGroup>
- </div>
- </FieldGroup>
+ </SettingTitle>
+ <SettingDescription>
+ <Trans
+ i18nKey="customBrandingSettingLabel"
+ defaults="Show your logo and colors to participants."
+ />
+ </SettingDescription>
+ <SettingControl>
+ <Switch
+ checked={showBranding}
+ onCheckedChange={handleToggle}
+ disabled={disabled || updateShowBranding.isExecuting}
+ />
+ </SettingControl>
+ <SettingHint plain>
+ <BrandingPreview
+ spaceName={space.name}
+ spaceImage={space.image}
+ primaryColor={hexColor}
+ hostName={user.name}
+ />
+ </SettingHint>
+ </Setting>
+ </SettingsGroup>
</PageSectionContent>
</PageSection>
);
}
+
+/**
+ * Split out so `useSettingLabels()` runs inside the Setting provider. The
+ * picker is a composite control, so `SettingControl` cannot label it directly
+ * — the row's title and description are forwarded to the hex input instead.
+ */
+function PrimaryColorField({
+ value,
+ onChange,
+ disabled,
+ isDefault,
+ isDirty,
+ isSaving,
+ onSave,
+ onReset,
+}: {
+ value: Color;
+ onChange: (color: Color) => void;
+ disabled: boolean;
+ isDefault: boolean;
+ isDirty: boolean;
+ isSaving: boolean;
+ onSave: () => void;
+ onReset: () => void;
+}) {
+ const { t } = useTranslation();
+ const labels = useSettingLabels();
+
+ return (
+ <ColorPicker
+ className="w-44"
+ value={value}
+ onChange={onChange}
+ {...labels}
+ actions={
+ disabled ? null : (
+ <>
+ {!isDefault ? (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <InputGroupButton
+ size="icon-xs"
+ onClick={onReset}
+ aria-label={t("resetToDefault", {
+ defaultValue: "Reset to default",
+ })}
+ >
+ <RotateCcwIcon />
+ </InputGroupButton>
+ }
+ />
+ <TooltipContent>
+ <Trans i18nKey="resetToDefault" defaults="Reset to default" />
+ </TooltipContent>
+ </Tooltip>
+ ) : null}
+ {isDirty ? (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <InputGroupButton
+ size="icon-xs"
+ onClick={onSave}
+ loading={isSaving}
+ aria-label={t("save", { defaultValue: "Save" })}
+ >
+ <CheckIcon />
+ </InputGroupButton>
+ }
+ />
+ <TooltipContent>
+ <Trans i18nKey="save" defaults="Save" />
+ </TooltipContent>
+ </Tooltip>
+ ) : null}
+ </>
+ )
+ }
+ />
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/leave-space-button.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/leave-space-button.tsx
index 419d1dc4a..6f3fb8e6e 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/components/leave-space-button.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/leave-space-button.tsx
@@ -23,7 +23,6 @@ import {
import { Input } from "@rallly/ui/input";
import { toast } from "@rallly/ui/sonner";
-import { LogOutIcon } from "lucide-react";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { Trans, useTranslation } from "@/i18n/client";
@@ -149,8 +148,7 @@ export function LeaveSpaceButton({
}: LeaveSpaceButtonProps) {
return (
<LeaveSpaceDialog spaceName={spaceName} spaceId={spaceId}>
- <DialogTrigger render={<Button />}>
- <LogOutIcon data-icon="inline-start" />
+ <DialogTrigger render={<Button className="text-destructive" />}>
<Trans i18nKey="leaveSpace" defaults="Leave Space" />
</DialogTrigger>
</LeaveSpaceDialog>
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx
index 92c0a3759..4cb6b645a 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/space-settings-form.tsx
@@ -1,16 +1,18 @@
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
-import { Button } from "@rallly/ui/button";
+import { FieldError } from "@rallly/ui/field";
import {
- Field,
- FieldError,
- FieldGroup,
- FieldLabel,
- FieldSet,
-} from "@rallly/ui/field";
-import { Input } from "@rallly/ui/input";
+ InputGroup,
+ InputGroupAddon,
+ InputGroupButton,
+ InputGroupInput,
+} from "@rallly/ui/input-group";
import { toast } from "@rallly/ui/sonner";
+import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";
+import { CheckIcon } from "lucide-react";
+import type React from "react";
+import type { Control } from "react-hook-form";
import { Controller, useForm } from "react-hook-form";
import * as z from "zod";
import {
@@ -18,6 +20,13 @@ import {
ImageUploadControl,
ImageUploadPreview,
} from "@/components/image-upload";
+import {
+ SettingControl,
+ SettingDescription,
+ SettingRow,
+ SettingTitle,
+ useSettingLabels,
+} from "@/components/setting";
import {
getSpaceImageUploadUrlAction,
removeSpaceImageAction,
@@ -36,6 +45,8 @@ const spaceSettingsSchema = z.object({
.max(100, "Space name must be less than 100 characters"),
});
+type SpaceSettingsValues = z.infer<typeof spaceSettingsSchema>;
+
interface SpaceSettingsFormProps {
space: SpaceDTO;
disabled?: boolean;
@@ -80,76 +91,129 @@ export function SpaceSettingsForm({
};
return (
- <form
- onSubmit={form.handleSubmit(async (data) => {
- const result = await updateSpace.executeAsync({ name: data.name });
-
- if (!result?.serverError && !result?.validationErrors) {
- form.reset(data);
- toast.success(
- t("spaceUpdatedSuccess", {
- defaultValue: "Space updated successfully",
- }),
- );
- }
- })}
- >
- <FieldGroup>
- <FieldSet>
- <FieldGroup>
- <Field>
- <FieldLabel>
- <Trans i18nKey="logo" defaults="Logo" />
- </FieldLabel>
- <ImageUpload>
- <ImageUploadPreview>
- <SpaceIcon name={space.name} src={space.image} size="xl" />
- </ImageUploadPreview>
- <ImageUploadControl
- getUploadUrl={handleGetUploadUrl}
- onUploadSuccess={handleImageUploadSuccess}
- onRemoveSuccess={handleImageRemoveSuccess}
- hasCurrentImage={!!space.image}
- />
- </ImageUpload>
- </Field>
- <Controller
- control={form.control}
- name="name"
- render={({ field, fieldState }) => (
- <Field data-invalid={fieldState.invalid}>
- <FieldLabel>
- <Trans i18nKey="name" defaults="Name" />
- </FieldLabel>
- <Input
- {...field}
- disabled={disabled}
- className="w-48"
- placeholder={t("spaceNamePlaceholder", {
- defaultValue: "My Team",
- })}
- id={field.name}
- aria-invalid={fieldState.invalid}
- />
- {fieldState.invalid && (
- <FieldError errors={[fieldState.error]} />
- )}
- </Field>
- )}
+ <>
+ <SettingRow>
+ <SettingTitle>
+ <Trans i18nKey="logo" defaults="Logo" />
+ </SettingTitle>
+ <SettingDescription>
+ <Trans i18nKey="spaceLogoSettingHint" defaults="Your space's logo." />
+ </SettingDescription>
+ <SettingControl>
+ <ImageUpload>
+ <ImageUploadPreview>
+ <SpaceIcon name={space.name} src={space.image} size="xl" />
+ </ImageUploadPreview>
+ <ImageUploadControl
+ getUploadUrl={handleGetUploadUrl}
+ onUploadSuccess={handleImageUploadSuccess}
+ onRemoveSuccess={handleImageRemoveSuccess}
+ hasCurrentImage={!!space.image}
/>
- </FieldGroup>
- </FieldSet>
- <Field orientation="horizontal">
- <Button
- type="submit"
- disabled={
- disabled || updateSpace.isExecuting || !form.formState.isDirty
- }
- >
- <Trans i18nKey="save" defaults="Save" />
- </Button>
- </Field>
- </FieldGroup>
+ </ImageUpload>
+ </SettingControl>
+ </SettingRow>
+ <SettingRow>
+ <SettingTitle>
+ <Trans i18nKey="name" defaults="Name" />
+ </SettingTitle>
+ <SettingDescription>
+ <Trans
+ i18nKey="spaceNameSettingLabel"
+ defaults="What this space is called."
+ />
+ </SettingDescription>
+ <SettingControl>
+ <SpaceNameField
+ control={form.control}
+ disabled={disabled}
+ isSaving={updateSpace.isExecuting}
+ isDirty={form.formState.isDirty}
+ onSubmit={form.handleSubmit(async (data) => {
+ const result = await updateSpace.executeAsync({
+ name: data.name,
+ });
+
+ if (!result?.serverError && !result?.validationErrors) {
+ form.reset(data);
+ toast.success(
+ t("spaceUpdatedSuccess", {
+ defaultValue: "Space updated successfully",
+ }),
+ );
+ }
+ })}
+ />
+ </SettingControl>
+ </SettingRow>
+ </>
+ );
+}
+
+function SpaceNameField({
+ control,
+ disabled,
+ isSaving,
+ isDirty,
+ onSubmit,
+}: {
+ control: Control<SpaceSettingsValues>;
+ disabled: boolean;
+ isSaving: boolean;
+ isDirty: boolean;
+ onSubmit: React.FormEventHandler<HTMLFormElement>;
+}) {
+ const { t } = useTranslation();
+ const labels = useSettingLabels();
+
+ return (
+ <form onSubmit={onSubmit}>
+ <Controller
+ control={control}
+ name="name"
+ render={({ field, fieldState }) => (
+ <>
+ <InputGroup className="w-56">
+ <InputGroupInput
+ {...field}
+ {...labels}
+ disabled={disabled}
+ placeholder={t("spaceNamePlaceholder", {
+ defaultValue: "My Team",
+ })}
+ aria-invalid={fieldState.invalid}
+ />
+ {/* Rendered only when there is something to save. A disabled
+ button here would trip InputGroup's `has-disabled:` styles
+ and grey out the whole field. */}
+ {isDirty && !disabled ? (
+ <InputGroupAddon align="inline-end">
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <InputGroupButton
+ type="submit"
+ size="icon-xs"
+ loading={isSaving}
+ aria-label={t("save", { defaultValue: "Save" })}
+ >
+ <CheckIcon />
+ </InputGroupButton>
+ }
+ />
+ <TooltipContent>
+ <Trans i18nKey="save" defaults="Save" />
+ </TooltipContent>
+ </Tooltip>
+ </InputGroupAddon>
+ ) : null}
+ </InputGroup>
+ {fieldState.invalid ? (
+ <FieldError className="mt-1.5" errors={[fieldState.error]} />
+ ) : null}
+ </>
+ )}
+ />
</form>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx b/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx
index 74f22837e..8bdba05a3 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/page-client.tsx
@@ -2,7 +2,7 @@
import { subject } from "@casl/ability";
import { Alert, AlertDescription } from "@rallly/ui/alert";
-import { EyeIcon } from "lucide-react";
+import { EyeIcon, LogOutIcon, TrashIcon } from "lucide-react";
import {
PageSection,
PageSectionContent,
@@ -11,6 +11,14 @@ import {
PageSectionHeader,
PageSectionTitle,
} from "@/components/page-layout";
+import {
+ SettingControl,
+ SettingDescription,
+ SettingIcon,
+ SettingRow,
+ SettingsGroup,
+ SettingTitle,
+} from "@/components/setting";
import {
SettingsPage,
SettingsPageContent,
@@ -24,7 +32,6 @@ import { Trans } from "@/i18n/client";
import { CustomBrandingSection } from "./components/custom-branding-section";
import { DeleteSpaceButton } from "./components/delete-space-button";
import { LeaveSpaceButton } from "./components/leave-space-button";
-import { SpaceSettingsForm } from "./components/space-settings-form";
export function GeneralSettingsPageClient() {
const { data: space, getMemberAbility } = useSpace();
@@ -60,45 +67,64 @@ export function GeneralSettingsPageClient() {
</AlertDescription>
</Alert>
) : null}
- <PageSection variant="card">
- <PageSectionContent>
- <SpaceSettingsForm space={space} disabled={!isAdmin} />
- </PageSectionContent>
- </PageSection>
<CustomBrandingSection disabled={!isAdmin} />
- {!isOwner ? (
- <PageSection variant="card">
- <PageSectionHeader>
- <PageSectionTitle>
- <Trans i18nKey="leaveSpace" defaults="Leave Space" />
- </PageSectionTitle>
- <PageSectionDescription>
- <Trans
- i18nKey="leaveSpaceDescription"
- defaults="Remove yourself from this space. You'll lose access to all polls in this space."
- />
- </PageSectionDescription>
- </PageSectionHeader>
- <PageSectionContent>
- <LeaveSpaceButton spaceName={space.name} spaceId={space.id} />
- </PageSectionContent>
- </PageSection>
- ) : null}
- {canDeleteSpace ? (
+ {!isOwner || canDeleteSpace ? (
<PageSection variant="card">
<PageSectionHeader>
<PageSectionTitle>
- <Trans i18nKey="deleteSpace" defaults="Delete Space" />
+ <Trans i18nKey="dangerZone" defaults="Danger Zone" />
</PageSectionTitle>
<PageSectionDescription>
<Trans
- i18nKey="deleteSpaceDescription"
- defaults="Permanently delete this space and all its content. This action cannot be undone."
+ i18nKey="spaceDangerZoneDescription"
+ defaults="These actions cannot be undone"
/>
</PageSectionDescription>
</PageSectionHeader>
<PageSectionContent>
- <DeleteSpaceButton spaceName={space.name} />
+ <SettingsGroup>
+ {!isOwner ? (
+ <SettingRow>
+ <SettingIcon>
+ <LogOutIcon />
+ </SettingIcon>
+ <SettingTitle>
+ <Trans i18nKey="leaveSpace" defaults="Leave Space" />
+ </SettingTitle>
+ <SettingDescription>
+ <Trans
+ i18nKey="leaveSpaceSettingHint"
+ defaults="Remove yourself from this space and lose access to its polls."
+ />
+ </SettingDescription>
+ <SettingControl>
+ <LeaveSpaceButton
+ spaceName={space.name}
+ spaceId={space.id}
+ />
+ </SettingControl>
+ </SettingRow>
+ ) : null}
+ {canDeleteSpace ? (
+ <SettingRow>
+ <SettingIcon>
+ <TrashIcon />
+ </SettingIcon>
+ <SettingTitle>
+ <Trans i18nKey="deleteSpace" defaults="Delete Space" />
+ </SettingTitle>
+ <SettingDescription>
+ <Trans
+ i18nKey="deleteSpaceSettingHint"
+ defaults="Permanently delete this space and everything in it."
+ />
+ </SettingDescription>
+ <SettingControl>
+ <DeleteSpaceButton spaceName={space.name} />
+ </SettingControl>
+ </SettingRow>
+ ) : null}
+ </SettingsGroup>
</PageSectionContent>
</PageSection>
) : null}
diff --git a/apps/web/src/components/page-layout.tsx b/apps/web/src/components/page-layout.tsx
index e8da29832..667fccf99 100644
--- a/apps/web/src/components/page-layout.tsx
+++ b/apps/web/src/components/page-layout.tsx
@@ -123,7 +123,7 @@ export function PageSectionGroup({ children }: { children?: React.ReactNode }) {
return <div className="space-y-6">{children}</div>;
}
-const pageSectionVariants = cva("flex flex-col gap-4", {
+const pageSectionVariants = cva("flex flex-col gap-6", {
variants: {
variant: {
card: "rounded-2xl border border-card-border bg-card p-4",
diff --git a/apps/web/src/components/setting.tsx b/apps/web/src/components/setting.tsx
index 200083fb4..1081db563 100644
--- a/apps/web/src/components/setting.tsx
+++ b/apps/web/src/components/setting.tsx
@@ -1,5 +1,6 @@
"use client";
+import { cva } from "class-variance-authority";
import { InfoIcon } from "lucide-react";
import React from "react";
import { PageIcon } from "@/components/page-icons";
@@ -8,6 +9,8 @@ const SettingContext = React.createContext<{
titleId: string;
descriptionId: string;
hintId: string;
+ /** Whether SettingControl labels its child, or the control names itself. */
+ labelsControl: boolean;
} | null>(null);
const useSetting = () => {
@@ -22,28 +25,78 @@ export const SettingsGroup = ({ children }: React.PropsWithChildren) => {
return <div className="divide-y">{children}</div>;
};
-export const Setting = ({ children }: React.PropsWithChildren) => {
+const settingVariants = cva(
+ // The icon column is `auto`, so it collapses to zero width without a
+ // SettingIcon; a uniform `gap-x` would still indent iconless rows, so the
+ // gap is zero and SettingIcon/SettingControl carry their own margins.
+ // Below `sm` everything stacks in one column so wide controls (pickers,
+ // input groups) get the full width rather than being squeezed beside the
+ // title; from `sm` up the control moves to its own column on the right.
+ "grid grid-cols-1 py-4 [column-gap:0] [grid-template-areas:'title'_'description'_'control'_'hint'] first:pt-0 last:pb-0 sm:grid-cols-[auto_1fr_auto] sm:[grid-template-areas:'icon_title_control'_'icon_description_control'_'icon_hint_hint']",
+ {
+ variants: {
+ interactive: {
+ true: "cursor-pointer select-none",
+ false: "",
+ },
+ },
+ defaultVariants: { interactive: false },
+ },
+);
+
+const SettingProvider = ({
+ children,
+ labelsControl,
+}: React.PropsWithChildren<{ labelsControl: boolean }>) => {
const titleId = React.useId();
const descriptionId = React.useId();
const hintId = React.useId();
const value = React.useMemo(
- () => ({ titleId, descriptionId, hintId }),
- [titleId, descriptionId, hintId],
+ () => ({ titleId, descriptionId, hintId, labelsControl }),
+ [titleId, descriptionId, hintId, labelsControl],
+ );
+ return (
+ <SettingContext.Provider value={value}>{children}</SettingContext.Provider>
);
+};
+/**
+ * A setting whose control is a single labelable element — a switch, a select.
+ * The row renders as a label, so clicking anywhere on it activates the
+ * control, and SettingControl labels the control automatically.
+ *
+ * For a control made of several elements (an input with a button, a picker, a
+ * dialog trigger) use SettingRow instead: there is no single element for a
+ * label to point at, and wrapping several controls in one label is invalid.
+ */
+export const Setting = ({ children }: React.PropsWithChildren) => {
return (
- <SettingContext.Provider value={value}>
+ <SettingProvider labelsControl>
{/* biome-ignore lint/a11y/noLabelWithoutControl: control is rendered inside */}
- <label className="grid cursor-pointer select-none grid-cols-[1fr_auto] gap-x-3 py-4 [grid-template-areas:'title_control'_'description_control'_'hint_hint'] first:pt-0 last:pb-0 sm:grid-cols-[auto_1fr_auto] sm:[grid-template-areas:'icon_title_control'_'icon_description_control'_'icon_hint_hint']">
+ <label className={settingVariants({ interactive: true })}>
{children}
</label>
- </SettingContext.Provider>
+ </SettingProvider>
+ );
+};
+
+/**
+ * A setting whose control is not a single labelable element — a button, an
+ * input with its own actions, a picker. Renders a plain row, so the control has
+ * to name itself: spread `useSettingLabels()` onto whichever element is the
+ * real control.
+ */
+export const SettingRow = ({ children }: React.PropsWithChildren) => {
+ return (
+ <SettingProvider labelsControl={false}>
+ <div className={settingVariants()}>{children}</div>
+ </SettingProvider>
);
};
export const SettingIcon = ({ children }: React.PropsWithChildren) => {
return (
- <div className="hidden self-start [grid-area:icon] sm:block">
+ <div className="mr-3 hidden self-start [grid-area:icon] sm:block">
<PageIcon size="lg">{children}</PageIcon>
</div>
);
@@ -73,6 +126,12 @@ export const SettingDescription = ({ children }: React.PropsWithChildren) => {
);
};
+/**
+ * Holds the row's control. Inside `Setting` the control is a single labelable
+ * element, so the row's title and description are applied to it directly.
+ * Inside `SettingRow` there is no single element to label — the control names
+ * itself with `useSettingLabels()` — so the child is rendered untouched.
+ */
export const SettingControl = ({
children,
}: {
@@ -81,20 +140,47 @@ export const SettingControl = ({
"aria-describedby"?: string;
}>;
}) => {
- const { titleId, descriptionId, hintId } = useSetting();
+ const { titleId, descriptionId, hintId, labelsControl } = useSetting();
return (
- <div className="self-start justify-self-end [grid-area:control]">
+ <div className="mt-3 self-start justify-self-start [grid-area:control] sm:mt-0 sm:ml-3 sm:justify-self-end">
{/* A dangling hint id is ignored by assistive tech while no hint is rendered */}
- {React.cloneElement(children, {
- "aria-labelledby": titleId,
- "aria-describedby": `${descriptionId} ${hintId}`,
- })}
+ {labelsControl
+ ? React.cloneElement(children, {
+ "aria-labelledby": titleId,
+ "aria-describedby": `${descriptionId} ${hintId}`,
+ })
+ : children}
</div>
);
};
-export const SettingHint = ({ children }: React.PropsWithChildren) => {
+export const useSettingLabels = () => {
+ const { titleId, descriptionId, hintId } = useSetting();
+ return {
+ "aria-labelledby": titleId,
+ "aria-describedby": `${descriptionId} ${hintId}`,
+ };
+};
+
+/**
+ * Supplementary content spanning the full row width, below the title and
+ * control. Text hints get an info icon; `plain` drops the icon and the text
+ * styling for rich content such as an embedded preview.
+ */
+export const SettingHint = ({
+ children,
+ plain = false,
+}: React.PropsWithChildren<{ plain?: boolean }>) => {
const { hintId } = useSetting();
+
+ if (plain) {
+ return (
+ <div id={hintId} className="mt-4 [grid-area:hint]">
+ {children}
+ </div>
+ );
+ }
+
return (
<div
id={hintId}
diff --git a/packages/ui/src/color-picker.tsx b/packages/ui/src/color-picker.tsx
index ee6a01ba6..100e721a2 100644
--- a/packages/ui/src/color-picker.tsx
+++ b/packages/ui/src/color-picker.tsx
@@ -28,12 +28,25 @@ import { Popover, PopoverContent, PopoverTrigger } from "./popover";
export type ColorPickerProps = Pick<
RAColorPickerProps,
"value" | "onChange" | "defaultValue"
->;
+> & {
+ /** Rendered as an inline-end addon, for actions such as save or reset. */
+ actions?: React.ReactNode;
+ className?: string;
+ /** Applied to the hex input, which is the control an external label names. */
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
+};
export type { Color };
export { parseColor } from "react-aria-components";
-function HexColorInput() {
+function HexColorInput({
+ "aria-labelledby": labelledBy,
+ "aria-describedby": describedBy,
+}: {
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
+}) {
const pickerState = React.useContext(ColorPickerStateContext);
const inputRef = React.useRef<HTMLInputElement>(null);
@@ -45,7 +58,11 @@ function HexColorInput() {
});
const { inputProps } = useColorField(
- { "aria-label": "Hex color" },
+ // An external label wins; the generic fallback only applies when the
+ // picker is used without one.
+ labelledBy
+ ? { "aria-labelledby": labelledBy, "aria-describedby": describedBy }
+ : { "aria-label": "Hex color", "aria-describedby": describedBy },
state,
inputRef,
);
@@ -60,17 +77,29 @@ function HexColorInput() {
);
}
-export function ColorPicker(props: ColorPickerProps) {
+export function ColorPicker({
+ actions,
+ className,
+ "aria-labelledby": labelledBy,
+ "aria-describedby": describedBy,
+ ...props
+}: ColorPickerProps) {
return (
<ColorPickerPrimitive {...props}>
<Popover>
- <InputGroup className="w-32">
+ <InputGroup className={cn("w-32", className)}>
<InputGroupAddon align="inline-start">
<PopoverTrigger render={<InputGroupButton />}>
<ColorSwatch className="size-4 rounded-sm border border-black/10" />
</PopoverTrigger>
</InputGroupAddon>
- <HexColorInput />
+ <HexColorInput
+ aria-labelledby={labelledBy}
+ aria-describedby={describedBy}
+ />
+ {actions ? (
+ <InputGroupAddon align="inline-end">{actions}</InputGroupAddon>
+ ) : null}
</InputGroup>
<PopoverContent align="start" className="w-48">
<ColorArea