diff --git a/app/components/Collapsible.tsx b/app/components/Collapsible.tsx
index 56fb860ca1..ae7386b667 100644
--- a/app/components/Collapsible.tsx
+++ b/app/components/Collapsible.tsx
@@ -45,7 +45,7 @@ export function Collapsible({
{label}
- {children}
+ {children}
);
}
@@ -77,7 +77,8 @@ const StyledTrigger = styled(RadixCollapsible.Trigger)`
}
`;
-const StyledContent = styled(RadixCollapsible.Content)`
+/** An animated Radix Collapsible content panel. */
+export const CollapsibleContent = styled(RadixCollapsible.Content)`
overflow: hidden;
&[data-state="open"] {
diff --git a/app/scenes/Settings/Notifications.tsx b/app/scenes/Settings/Notifications.tsx
index b55b658207..b496ff2b26 100644
--- a/app/scenes/Settings/Notifications.tsx
+++ b/app/scenes/Settings/Notifications.tsx
@@ -20,6 +20,7 @@ import * as React from "react";
import { useTranslation, Trans } from "react-i18next";
import { toast } from "sonner";
import { NotificationEventType } from "@shared/types";
+import { errToString } from "@shared/utils/error";
import Heading from "~/components/Heading";
import Notice from "~/components/Notice";
import Scene from "~/components/Scene";
@@ -29,147 +30,221 @@ import useCurrentUser from "~/hooks/useCurrentUser";
import { client } from "~/utils/ApiClient";
import isCloudHosted from "~/utils/isCloudHosted";
import SettingRow from "./components/SettingRow";
+import { SettingsSection } from "./components/SettingsSection";
+
+interface NotificationOption {
+ /** The event types that the option controls. */
+ events: NotificationEventType[];
+ /** The icon for the option. */
+ icon: React.ReactNode;
+ /** The label for the option. */
+ title: string;
+ /** The description for the option. */
+ description: string;
+}
+
+interface NotificationGroup {
+ /** A stable key for the group. */
+ id: string;
+ /** The section heading. */
+ title: string;
+ /** A summary of the notification types in the group. */
+ description: string;
+ /** Whether the group is shown. Defaults to true. */
+ visible?: boolean;
+ /** The options in the group. */
+ options: NotificationOption[];
+}
function Notifications() {
const user = useCurrentUser();
const { t } = useTranslation();
- const options = [
+ const groups: NotificationGroup[] = [
{
- events: [NotificationEventType.PublishDocument],
- icon: ,
- title: t("Document published"),
+ id: "documents",
+ title: t("Documents"),
description: t(
- "Receive a notification whenever a new document is published"
+ "Documents that are published, updated, or shared with you, and access requests"
),
- },
- {
- events: [NotificationEventType.UpdateDocument],
- icon: ,
- title: t("Document updated"),
- description: t(
- "Receive a notification when a document you are subscribed to is edited"
- ),
- },
- {
- events: [NotificationEventType.CreateComment],
- icon: ,
- title: t("Comment posted"),
- description: t(
- "Receive a notification when a document you are subscribed to or a thread you participated in receives a comment"
- ),
- },
- {
- events: [
- NotificationEventType.MentionedInComment,
- NotificationEventType.MentionedInDocument,
+ options: [
+ {
+ events: [NotificationEventType.PublishDocument],
+ icon: ,
+ title: t("Document published"),
+ description: t(
+ "Receive a notification whenever a new document is published"
+ ),
+ },
+ {
+ events: [NotificationEventType.UpdateDocument],
+ icon: ,
+ title: t("Document updated"),
+ description: t(
+ "Receive a notification when a document you are subscribed to is edited"
+ ),
+ },
+ {
+ events: [NotificationEventType.AddUserToDocument],
+ icon: ,
+ title: t("Invited to document"),
+ description: t(
+ "Receive a notification when a document is shared with you"
+ ),
+ },
+ {
+ events: [NotificationEventType.RequestDocumentAccess],
+ icon: ,
+ title: t("Document access requested"),
+ description: t(
+ "Receive a notification when a user requests access to a document you manage"
+ ),
+ },
],
- icon: ,
- title: t("Mentioned"),
- description: t(
- "Receive a notification when someone mentions you in a document or comment"
- ),
},
{
- events: [
- NotificationEventType.GroupMentionedInDocument,
- NotificationEventType.GroupMentionedInComment,
+ id: "collections",
+ title: t("Collections"),
+ description: t("New collections and access to collections"),
+ options: [
+ {
+ events: [NotificationEventType.CreateCollection],
+ icon: ,
+ title: t("Collection created"),
+ description: t(
+ "Receive a notification whenever a new collection is created"
+ ),
+ },
+ {
+ events: [NotificationEventType.AddUserToCollection],
+ icon: ,
+ title: t("Invited to collection"),
+ description: t(
+ "Receive a notification when you are given access to a collection"
+ ),
+ },
],
- icon: ,
- title: t("Group mentions"),
- description: t(
- "Receive a notification when someone mentions a group you are a member of in a document or comment"
- ),
},
{
- events: [NotificationEventType.ResolveComment],
- icon: ,
- title: t("Resolved"),
+ id: "comments",
+ title: t("Comments and mentions"),
description: t(
- "Receive a notification when a comment thread you were involved in is resolved"
+ "New comments, mentions of you or your groups, resolved threads, and reactions"
),
+ options: [
+ {
+ events: [NotificationEventType.CreateComment],
+ icon: ,
+ title: t("Comment posted"),
+ description: t(
+ "Receive a notification when a document you are subscribed to or a thread you participated in receives a comment"
+ ),
+ },
+ {
+ events: [
+ NotificationEventType.MentionedInComment,
+ NotificationEventType.MentionedInDocument,
+ ],
+ icon: ,
+ title: t("Mentioned"),
+ description: t(
+ "Receive a notification when someone mentions you in a document or comment"
+ ),
+ },
+ {
+ events: [
+ NotificationEventType.GroupMentionedInDocument,
+ NotificationEventType.GroupMentionedInComment,
+ ],
+ icon: ,
+ title: t("Group mentions"),
+ description: t(
+ "Receive a notification when someone mentions a group you are a member of in a document or comment"
+ ),
+ },
+ {
+ events: [NotificationEventType.ResolveComment],
+ icon: ,
+ title: t("Resolved"),
+ description: t(
+ "Receive a notification when a comment thread you were involved in is resolved"
+ ),
+ },
+ {
+ events: [NotificationEventType.ReactionsCreate],
+ icon: ,
+ title: t("Reaction added"),
+ description: t(
+ "Receive a notification when someone reacts to your comment"
+ ),
+ },
+ ],
},
{
- events: [NotificationEventType.ReactionsCreate],
- icon: ,
- title: t("Reaction added"),
+ id: "workspace",
+ title: t("Workspace"),
description: t(
- "Receive a notification when someone reacts to your comment"
+ "Group membership, accepted invites, and completed exports"
),
+ options: [
+ {
+ events: [NotificationEventType.AddUserToGroup],
+ icon: ,
+ title: t("Group membership"),
+ description: t(
+ "Receive a notification when you are added to or removed from a group"
+ ),
+ },
+ {
+ events: [NotificationEventType.InviteAccepted],
+ icon: ,
+ title: t("Invite accepted"),
+ description: t(
+ "Receive a notification when someone you invited creates an account"
+ ),
+ },
+ {
+ events: [NotificationEventType.ExportCompleted],
+ icon: ,
+ title: t("Export completed"),
+ description: t(
+ "Receive a notification when an export you requested has been completed"
+ ),
+ },
+ ],
},
{
- events: [NotificationEventType.CreateCollection],
- icon: ,
- title: t("Collection created"),
+ id: "product",
+ title: t("Product updates"),
description: t(
- "Receive a notification whenever a new collection is created"
+ "Tips on getting started and announcements of new features"
),
- },
- {
- events: [NotificationEventType.InviteAccepted],
- icon: ,
- title: t("Invite accepted"),
- description: t(
- "Receive a notification when someone you invited creates an account"
- ),
- },
- {
- events: [NotificationEventType.AddUserToDocument],
- icon: ,
- title: t("Invited to document"),
- description: t(
- "Receive a notification when a document is shared with you"
- ),
- },
- {
- events: [NotificationEventType.AddUserToCollection],
- icon: ,
- title: t("Invited to collection"),
- description: t(
- "Receive a notification when you are given access to a collection"
- ),
- },
- {
- events: [NotificationEventType.AddUserToGroup],
- icon: ,
- title: t("Group membership"),
- description: t(
- "Receive a notification when you are added to or removed from a group"
- ),
- },
- {
- events: [NotificationEventType.ExportCompleted],
- icon: ,
- title: t("Export completed"),
- description: t(
- "Receive a notification when an export you requested has been completed"
- ),
- },
- {
- events: [NotificationEventType.RequestDocumentAccess],
- icon: ,
- title: t("Document access requested"),
- description: t(
- "Receive a notification when a user requests access to a document you manage"
- ),
- },
- {
visible: isCloudHosted,
- icon: ,
- events: [NotificationEventType.Onboarding],
- title: t("Getting started"),
- description: t("Tips on getting started with features and functionality"),
- },
- {
- visible: isCloudHosted,
- icon: ,
- events: [NotificationEventType.Features],
- title: t("New features"),
- description: t("Receive an email when new features of note are added"),
+ options: [
+ {
+ icon: ,
+ events: [NotificationEventType.Onboarding],
+ title: t("Getting started"),
+ description: t(
+ "Tips on getting started with features and functionality"
+ ),
+ },
+ {
+ icon: ,
+ events: [NotificationEventType.Features],
+ title: t("New features"),
+ description: t(
+ "Receive an email when new features of note are added"
+ ),
+ },
+ ],
},
];
- const visibleOptions = options.filter((o) => o.visible !== false);
+ const visibleGroups = groups.filter((group) => group.visible !== false);
+ const visibleEvents = visibleGroups.flatMap((group) =>
+ group.options.flatMap((option) => option.events)
+ );
const showSuccessMessage = debounce(() => {
toast.success(t("Notifications saved"));
@@ -177,11 +252,40 @@ function Notifications() {
const handleChange = React.useCallback(
(eventTypes: NotificationEventType[]) => async (checked: boolean) => {
- // Sequential, as each request saves the full settings object.
- for (const eventType of eventTypes) {
- await user.setNotificationEventType(eventType, checked);
+ const changed = eventTypes.filter(
+ (eventType) => user.subscribedToEventType(eventType) !== checked
+ );
+
+ // Update all switches at once, before the requests complete.
+ runInAction(() => {
+ const updated = { ...user.notificationSettings };
+ for (const eventType of changed) {
+ updated[eventType] = checked;
+ }
+ user.notificationSettings = updated;
+ });
+
+ const unsaved = new Set(changed);
+
+ try {
+ // Sequential, as each request saves the full settings object.
+ for (const eventType of changed) {
+ await user.setNotificationEventType(eventType, checked);
+ unsaved.delete(eventType);
+ }
+ showSuccessMessage();
+ } catch (err) {
+ toast.error(errToString(err));
+
+ // Restore the events that were not saved.
+ runInAction(() => {
+ const updated = { ...user.notificationSettings };
+ for (const eventType of unsaved) {
+ updated[eventType] = !checked;
+ }
+ user.notificationSettings = updated;
+ });
}
- showSuccessMessage();
},
[user, showSuccessMessage]
);
@@ -190,10 +294,8 @@ function Notifications() {
async (checked: boolean) => {
runInAction(() => {
const updated = { ...user.notificationSettings };
- for (const option of visibleOptions) {
- for (const eventType of option.events) {
- updated[eventType] = checked;
- }
+ for (const eventType of visibleEvents) {
+ updated[eventType] = checked;
}
user.notificationSettings = updated;
});
@@ -204,12 +306,13 @@ function Notifications() {
);
showSuccessMessage();
},
- [user, visibleOptions, showSuccessMessage]
+ [user, visibleEvents, showSuccessMessage]
);
- const allEnabled = visibleOptions.every((o) =>
- o.events.every((eventType) => user.subscribedToEventType(eventType))
- );
+ const isSubscribed = (eventTypes: NotificationEventType[]) =>
+ eventTypes.every((eventType) => user.subscribedToEventType(eventType));
+
+ const allEnabled = isSubscribed(visibleEvents);
const showSuccessNotice = window.location.search === "?success";
@@ -241,33 +344,55 @@ function Notifications() {
/>
- {options.map((option) => {
- const [name] = option.events;
- const checked = option.events.every((eventType) =>
- user.subscribedToEventType(eventType)
- );
+ {visibleGroups.map((group) => {
+ const groupEvents = group.options.flatMap((option) => option.events);
+ const groupChecked = isSubscribed(groupEvents);
+ const isMixed =
+ !groupChecked &&
+ groupEvents.some((eventType) =>
+ user.subscribedToEventType(eventType)
+ );
return (
-
- {option.description}
-
+
}
- compact
>
-
-
+ {group.options.map((option) => {
+ const [name] = option.events;
+
+ return (
+
+ {option.description}
+
+ }
+ compact
+ >
+
+
+ );
+ })}
+
);
})}
diff --git a/app/scenes/Settings/components/SettingsSection.tsx b/app/scenes/Settings/components/SettingsSection.tsx
index 586571f3a8..280fe0aebb 100644
--- a/app/scenes/Settings/components/SettingsSection.tsx
+++ b/app/scenes/Settings/components/SettingsSection.tsx
@@ -1,7 +1,11 @@
+import * as RadixCollapsible from "@radix-ui/react-collapsible";
+import { ExpandedIcon } from "outline-icons";
import { transparentize } from "polished";
import * as React from "react";
import styled, { css } from "styled-components";
+import { s } from "@shared/styles";
import { breakpoint } from "@shared/styles/breakpoint";
+import { CollapsibleContent } from "~/components/Collapsible";
import Text from "~/components/Text";
interface Props {
@@ -9,6 +13,12 @@ interface Props {
title: React.ReactNode;
/** Optional text shown below the heading. */
description?: React.ReactNode;
+ /** An optional control shown on the right of the heading. */
+ action?: React.ReactNode;
+ /** Whether a click on the heading shows or hides the rows. */
+ collapsible?: boolean;
+ /** Whether a collapsible section is open on first render. Defaults to true. */
+ defaultOpen?: boolean;
/** Whether the section holds destructive actions. */
danger?: boolean;
/** The rows in the section, usually SettingRow components. */
@@ -24,21 +34,53 @@ interface Props {
export function SettingsSection({
title,
description,
+ action,
+ collapsible,
+ defaultOpen = true,
danger,
children,
}: Props) {
const titleId = React.useId();
+ const descriptionNode = description && (
+
+ {description}
+
+ );
+ const rows = {children};
+
+ if (!collapsible) {
+ return (
+
+
+
+ {title}
+ {descriptionNode}
+
+ {action}
+
+ {rows}
+
+ );
+ }
return (
-
- {title}
- {description && (
-
- {description}
-
- )}
- {children}
-
+
+
+
+
+
+
+ {title}
+
+
+
+ {descriptionNode}
+
+ {action}
+
+ {rows}
+
+
);
}
@@ -48,6 +90,23 @@ const Section = styled.section`
${breakpoint("tablet")`
margin-top: 48px;
`}
+
+ /* Less space after a collapsed section. */
+ &[data-state="closed"] + & {
+ margin-top: 24px;
+ }
+`;
+
+const Header = styled.div`
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+`;
+
+const HeaderText = styled.div`
+ flex: 1;
+ min-width: 0;
`;
const Title = styled.h2`
@@ -56,6 +115,40 @@ const Title = styled.h2`
margin: 0;
`;
+const DisclosureIcon = styled(ExpandedIcon)`
+ flex-shrink: 0;
+ color: ${s("textTertiary")};
+ transition: transform 150ms ease-out;
+`;
+
+const Trigger = styled(RadixCollapsible.Trigger)`
+ display: inline-flex;
+ align-items: center;
+ gap: 2px;
+ padding: 0;
+ border: 0;
+ background: none;
+ color: inherit;
+ font: inherit;
+ cursor: var(--pointer);
+
+ &:hover ${DisclosureIcon} {
+ color: ${s("textSecondary")};
+ }
+
+ &[data-state="closed"] ${DisclosureIcon} {
+ transform: rotate(-90deg);
+ }
+
+ [dir="rtl"] &[data-state="closed"] ${DisclosureIcon} {
+ transform: rotate(90deg);
+ }
+`;
+
+const Content = styled(CollapsibleContent)`
+ padding-inline-start: 8px;
+`;
+
const Description = styled(Text)`
margin: 4px 0 8px;
`;
diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json
index 07f2f98578..ae709051d3 100644
--- a/shared/i18n/locales/en_US/translation.json
+++ b/shared/i18n/locales/en_US/translation.json
@@ -1520,9 +1520,21 @@
"Quickly transfer your existing documents, pages, and files from other tools and services into {{appName}}. You can also drag and drop any HTML, Markdown, and text documents directly into Collections in the app.": "Quickly transfer your existing documents, pages, and files from other tools and services into {{appName}}. You can also drag and drop any HTML, Markdown, and text documents directly into Collections in the app.",
"Recent imports": "Recent imports",
"Configure a variety of integrations with third-party services.": "Configure a variety of integrations with third-party services.",
+ "Documents that are published, updated, or shared with you, and access requests": "Documents that are published, updated, or shared with you, and access requests",
"Receive a notification whenever a new document is published": "Receive a notification whenever a new document is published",
"Document updated": "Document updated",
"Receive a notification when a document you are subscribed to is edited": "Receive a notification when a document you are subscribed to is edited",
+ "Invited to document": "Invited to document",
+ "Receive a notification when a document is shared with you": "Receive a notification when a document is shared with you",
+ "Document access requested": "Document access requested",
+ "Receive a notification when a user requests access to a document you manage": "Receive a notification when a user requests access to a document you manage",
+ "New collections and access to collections": "New collections and access to collections",
+ "Collection created": "Collection created",
+ "Receive a notification whenever a new collection is created": "Receive a notification whenever a new collection is created",
+ "Invited to collection": "Invited to collection",
+ "Receive a notification when you are given access to a collection": "Receive a notification when you are given access to a collection",
+ "Comments and mentions": "Comments and mentions",
+ "New comments, mentions of you or your groups, resolved threads, and reactions": "New comments, mentions of you or your groups, resolved threads, and reactions",
"Comment posted": "Comment posted",
"Receive a notification when a document you are subscribed to or a thread you participated in receives a comment": "Receive a notification when a document you are subscribed to or a thread you participated in receives a comment",
"Mentioned": "Mentioned",
@@ -1532,20 +1544,15 @@
"Receive a notification when a comment thread you were involved in is resolved": "Receive a notification when a comment thread you were involved in is resolved",
"Reaction added": "Reaction added",
"Receive a notification when someone reacts to your comment": "Receive a notification when someone reacts to your comment",
- "Collection created": "Collection created",
- "Receive a notification whenever a new collection is created": "Receive a notification whenever a new collection is created",
- "Invite accepted": "Invite accepted",
- "Receive a notification when someone you invited creates an account": "Receive a notification when someone you invited creates an account",
- "Invited to document": "Invited to document",
- "Receive a notification when a document is shared with you": "Receive a notification when a document is shared with you",
- "Invited to collection": "Invited to collection",
- "Receive a notification when you are given access to a collection": "Receive a notification when you are given access to a collection",
+ "Group membership, accepted invites, and completed exports": "Group membership, accepted invites, and completed exports",
"Group membership": "Group membership",
"Receive a notification when you are added to or removed from a group": "Receive a notification when you are added to or removed from a group",
+ "Invite accepted": "Invite accepted",
+ "Receive a notification when someone you invited creates an account": "Receive a notification when someone you invited creates an account",
"Export completed": "Export completed",
"Receive a notification when an export you requested has been completed": "Receive a notification when an export you requested has been completed",
- "Document access requested": "Document access requested",
- "Receive a notification when a user requests access to a document you manage": "Receive a notification when a user requests access to a document you manage",
+ "Product updates": "Product updates",
+ "Tips on getting started and announcements of new features": "Tips on getting started and announcements of new features",
"Getting started": "Getting started",
"Tips on getting started with features and functionality": "Tips on getting started with features and functionality",
"New features": "New features",