diff --git a/app/components/Breadcrumb.tsx b/app/components/Breadcrumb.tsx index a80041a288..06ebe877bd 100644 --- a/app/components/Breadcrumb.tsx +++ b/app/components/Breadcrumb.tsx @@ -37,7 +37,11 @@ function Breadcrumb( return ( {topLevelItems.map((item, index) => ( - + {item.icon} {item.to ? ( Promise | void; + /** Callback when the dialog is submitted. Return false to prevent closing. */ + onSubmit: () => Promise | void; /** Text to display on the submit button */ submitText?: string; /** Text to display while the form is saving */ @@ -38,7 +38,10 @@ const ConfirmationDialog: React.FC = ({ ev.preventDefault(); setIsSaving(true); try { - await onSubmit(); + const res = await onSubmit(); + if (res === false) { + return; + } dialogs.closeAllModals(); } catch (err) { toast.error(err.message); diff --git a/app/components/ContextMenu/MenuItem.tsx b/app/components/ContextMenu/MenuItem.tsx index 2a3e76dd56..96d8c964c1 100644 --- a/app/components/ContextMenu/MenuItem.tsx +++ b/app/components/ContextMenu/MenuItem.tsx @@ -109,6 +109,8 @@ const Title = styled.div` ${ellipsis()} flex-grow: 1; display: flex; + align-items: center; + gap: 8px; `; type MenuAnchorProps = { diff --git a/app/components/DocumentMeta.tsx b/app/components/DocumentMeta.tsx index bc4160461f..5eee8d17dd 100644 --- a/app/components/DocumentMeta.tsx +++ b/app/components/DocumentMeta.tsx @@ -185,9 +185,9 @@ const DocumentMeta: React.FC = ({ {showCollection && collection && (  {t("in")}  - + - + )} {showParentDocuments && nestedDocumentsCount > 0 && ( @@ -210,6 +210,10 @@ const DocumentMeta: React.FC = ({ ); }; +const Strong = styled.strong` + font-weight: 550; +`; + const Container = styled(Flex)<{ rtl?: boolean }>` justify-content: ${(props) => (props.rtl ? "flex-end" : "flex-start")}; color: ${s("textTertiary")}; diff --git a/app/components/Sidebar/Sidebar.tsx b/app/components/Sidebar/Sidebar.tsx index ba786a7053..dd7ef44910 100644 --- a/app/components/Sidebar/Sidebar.tsx +++ b/app/components/Sidebar/Sidebar.tsx @@ -197,6 +197,7 @@ const Sidebar = React.forwardRef(function _Sidebar( return ( { if (isActive && linkRef.current && scrollIntoViewIfNeeded !== false) { - // If the page has an anchor hash then this means we're linking to an - // anchor in the document – smooth scrolling the sidebar may the scrolling - // to the anchor of the document so we must avoid it. - if (!window.location.hash) { - scrollIntoView(linkRef.current, { - scrollMode: "if-needed", - behavior: "auto", - }); - } + scrollIntoView(linkRef.current, { + scrollMode: "if-needed", + behavior: "auto", + boundary: (parent) => parent.id !== "sidebar", + }); } }, [linkRef, scrollIntoViewIfNeeded, isActive]); diff --git a/app/components/Tooltip.tsx b/app/components/Tooltip.tsx index c155ed58e0..caa7e058fa 100644 --- a/app/components/Tooltip.tsx +++ b/app/components/Tooltip.tsx @@ -47,8 +47,8 @@ function Tooltip({ {typeof shortcut === "string" ? ( shortcut .split("+") - .map((key) => ( - + .map((key, i) => ( + {key.length === 1 ? key.toUpperCase() : key} )) diff --git a/app/components/UserDialogs.tsx b/app/components/UserDialogs.tsx index 74aac725eb..cbf6028583 100644 --- a/app/components/UserDialogs.tsx +++ b/app/components/UserDialogs.tsx @@ -1,10 +1,14 @@ import * as React from "react"; -import { useTranslation } from "react-i18next"; +import { Trans, useTranslation } from "react-i18next"; +import { toast } from "sonner"; import { UserRole } from "@shared/types"; import User from "~/models/User"; import ConfirmationDialog from "~/components/ConfirmationDialog"; import Input from "~/components/Input"; +import useCurrentUser from "~/hooks/useCurrentUser"; import useStores from "~/hooks/useStores"; +import { client } from "~/utils/ApiClient"; +import Text from "./Text"; type Props = { user: User; @@ -85,7 +89,11 @@ export function UserSuspendDialog({ user, onSubmit }: Props) { }; return ( - + {t( "Are you sure you want to suspend {{ userName }}? Suspended users will be prevented from logging in.", { @@ -123,6 +131,68 @@ export function UserChangeNameDialog({ user, onSubmit }: Props) { onChange={handleChange} error={!name ? t("Name can't be empty") : undefined} value={name} + autoSelect + required + flex + /> + + ); +} + +export function UserChangeEmailDialog({ user, onSubmit }: Props) { + const { t } = useTranslation(); + const actor = useCurrentUser(); + const [email, setEmail] = React.useState(user.email); + const [error, setError] = React.useState(); + + const handleSubmit = async () => { + try { + await client.post(`/users.updateEmail`, { id: user.id, email }); + onSubmit(); + toast.info( + actor.id === user.id + ? t("Check your email to verify the new address.") + : t("The email will be changed once verified.") + ); + return true; + } catch (err) { + setError(err.message); + return false; + } + }; + + const handleChange = (ev: React.ChangeEvent) => { + setEmail(ev.target.value); + }; + + return ( + + + {actor.id === user.id ? ( + + You will receive an email to verify your new address. It must be + unique in the workspace. + + ) : ( + + A confirmation email will be sent to the new address before it is + changed. + + )} + + diff --git a/app/editor/components/MentionMenu.tsx b/app/editor/components/MentionMenu.tsx index 5e676d92be..8f7c33028d 100644 --- a/app/editor/components/MentionMenu.tsx +++ b/app/editor/components/MentionMenu.tsx @@ -13,10 +13,10 @@ import Flex from "~/components/Flex"; import useRequest from "~/hooks/useRequest"; import useStores from "~/hooks/useStores"; import { client } from "~/utils/ApiClient"; -import MentionMenuItem from "./MentionMenuItem"; import SuggestionsMenu, { Props as SuggestionsMenuProps, } from "./SuggestionsMenu"; +import SuggestionsMenuItem from "./SuggestionsMenuItem"; interface MentionItem extends MenuItem { name: string; @@ -122,11 +122,10 @@ function MentionMenu({ search, isActive, ...rest }: Props) { search={search} onSelect={handleSelect} renderMenuItem={(item, _index, options) => ( - & { - label: string; -}; - -export default function MentionMenuItem({ - label, - ...rest -}: MentionMenuItemProps) { - return ; -} diff --git a/app/editor/components/SuggestionsMenuItem.tsx b/app/editor/components/SuggestionsMenuItem.tsx index 4aa57a62d2..a64d4a8df6 100644 --- a/app/editor/components/SuggestionsMenuItem.tsx +++ b/app/editor/components/SuggestionsMenuItem.tsx @@ -15,6 +15,8 @@ export type Props = { icon?: React.ReactElement; /** The title of the item */ title: React.ReactNode; + /** An optional subtitle for the item */ + subtitle?: React.ReactNode; /** A string representing the keyboard shortcut for the item */ shortcut?: string; }; @@ -24,6 +26,7 @@ function SuggestionsMenuItem({ disabled, onClick, title, + subtitle, shortcut, icon, }: Props) { @@ -53,11 +56,17 @@ function SuggestionsMenuItem({ icon={icon} > {title} + {subtitle && {subtitle}} {shortcut && {shortcut}} ); } +const Subtitle = styled.span<{ $active?: boolean }>` + color: ${(props) => + props.$active ? props.theme.white50 : props.theme.textTertiary}; +`; + const Shortcut = styled.span<{ $active?: boolean }>` color: ${(props) => props.$active ? props.theme.white50 : props.theme.textTertiary}; diff --git a/app/editor/extensions/EmojiMenu.tsx b/app/editor/extensions/EmojiMenu.tsx index ea8524b888..557a057283 100644 --- a/app/editor/extensions/EmojiMenu.tsx +++ b/app/editor/extensions/EmojiMenu.tsx @@ -1,6 +1,7 @@ import { action } from "mobx"; import * as React from "react"; import { WidgetProps } from "@shared/editor/lib/Extension"; +import { isBrowser } from "@shared/utils/browser"; import Suggestion from "~/editor/extensions/Suggestion"; import EmojiMenu from "../components/EmojiMenu"; @@ -13,10 +14,9 @@ const languagesUsingColon = ["fr"]; export default class EmojiMenuExtension extends Suggestion { get defaultOptions() { - const languageIsUsingColon = - typeof window === "undefined" - ? false - : languagesUsingColon.includes(window.navigator.language.slice(0, 2)); + const languageIsUsingColon = isBrowser + ? languagesUsingColon.includes(window.navigator.language.slice(0, 2)) + : false; return { openRegex: new RegExp( diff --git a/app/editor/menus/formatting.tsx b/app/editor/menus/formatting.tsx index 283cd9b3ee..3baf9e0044 100644 --- a/app/editor/menus/formatting.tsx +++ b/app/editor/menus/formatting.tsx @@ -241,7 +241,11 @@ export default function formattingMenuItems( shortcut: `${metaDisplay}+⌥+M`, icon: , label: isCodeBlock ? dictionary.comment : undefined, - active: isMarkActive(schema.marks.comment, { resolved: false }), + active: isMarkActive( + schema.marks.comment, + { resolved: false }, + { exact: true } + ), visible: !isMobile || !isEmpty, }, { diff --git a/app/hooks/usePersistedState.ts b/app/hooks/usePersistedState.ts index 2c2fc941e7..d75a79d43b 100644 --- a/app/hooks/usePersistedState.ts +++ b/app/hooks/usePersistedState.ts @@ -1,6 +1,7 @@ import * as React from "react"; import { Primitive } from "utility-types"; import Storage from "@shared/utils/Storage"; +import { isBrowser } from "@shared/utils/browser"; import Logger from "~/utils/Logger"; import useEventListener from "./useEventListener"; @@ -41,7 +42,7 @@ export default function usePersistedState( options?: Options ): [T, (value: T) => void] { const [storedValue, setStoredValue] = React.useState(() => { - if (typeof window === "undefined") { + if (!isBrowser) { return defaultValue; } return Storage.get(key) ?? defaultValue; diff --git a/app/menus/UserMenu.tsx b/app/menus/UserMenu.tsx index 8a1026c24e..5cc58638da 100644 --- a/app/menus/UserMenu.tsx +++ b/app/menus/UserMenu.tsx @@ -11,6 +11,7 @@ import Template from "~/components/ContextMenu/Template"; import { UserSuspendDialog, UserChangeNameDialog, + UserChangeEmailDialog, } from "~/components/UserDialogs"; import { actionToMenuItem } from "~/actions"; import { @@ -49,6 +50,22 @@ function UserMenu({ user }: Props) { [dialogs, t, user] ); + const handleChangeEmail = React.useCallback( + (ev: React.SyntheticEvent) => { + ev.preventDefault(); + dialogs.openModal({ + title: t("Change email"), + content: ( + + ), + }); + }, + [dialogs, t, user] + ); + const handleSuspend = React.useCallback( (ev: React.SyntheticEvent) => { ev.preventDefault(); @@ -117,7 +134,13 @@ function UserMenu({ user }: Props) { type: "button", title: `${t("Change name")}…`, onClick: handleChangeName, - visible: can.update && user.role !== "admin", + visible: can.update, + }, + { + type: "button", + title: `${t("Change email")}…`, + onClick: handleChangeEmail, + visible: can.update, }, { type: "button", @@ -144,6 +167,7 @@ function UserMenu({ user }: Props) { { type: "button", title: `${t("Suspend user")}…`, + dangerous: true, onClick: handleSuspend, visible: !user.isInvited && !user.isSuspended, }, diff --git a/app/models/Group.ts b/app/models/Group.ts index d59c20d217..328f308c10 100644 --- a/app/models/Group.ts +++ b/app/models/Group.ts @@ -10,6 +10,9 @@ class Group extends Model { @observable name: string; + @observable + externalId: string | undefined; + @observable memberCount: number; diff --git a/app/scenes/Document/components/Header.tsx b/app/scenes/Document/components/Header.tsx index 9bbe3b1626..e8ca318dcc 100644 --- a/app/scenes/Document/components/Header.tsx +++ b/app/scenes/Document/components/Header.tsx @@ -199,6 +199,7 @@ function DocumentHeader({ if (shareId) { return ( diff --git a/app/scenes/Settings/Notifications.tsx b/app/scenes/Settings/Notifications.tsx index 162b09d825..479c6564eb 100644 --- a/app/scenes/Settings/Notifications.tsx +++ b/app/scenes/Settings/Notifications.tsx @@ -19,19 +19,22 @@ import { toast } from "sonner"; import { NotificationEventType } from "@shared/types"; import Flex from "~/components/Flex"; import Heading from "~/components/Heading"; -import Input from "~/components/Input"; import Notice from "~/components/Notice"; import Scene from "~/components/Scene"; import Switch from "~/components/Switch"; import Text from "~/components/Text"; import env from "~/env"; +import useCurrentTeam from "~/hooks/useCurrentTeam"; import useCurrentUser from "~/hooks/useCurrentUser"; +import usePolicy from "~/hooks/usePolicy"; import isCloudHosted from "~/utils/isCloudHosted"; import SettingRow from "./components/SettingRow"; function Notifications() { const user = useCurrentUser(); + const team = useCurrentTeam(); const { t } = useTranslation(); + const can = usePolicy(team.id); const options = [ { @@ -161,17 +164,7 @@ function Notifications() { Manage when and where you receive email notifications. - {env.EMAIL_ENABLED ? ( - - - - ) : ( + {env.EMAIL_ENABLED && can.manage && ( The email integration is currently disabled. Please set the diff --git a/app/scenes/Settings/Profile.tsx b/app/scenes/Settings/Profile.tsx index 5c5f127b53..cc04c58f09 100644 --- a/app/scenes/Settings/Profile.tsx +++ b/app/scenes/Settings/Profile.tsx @@ -8,14 +8,18 @@ import Heading from "~/components/Heading"; import Input from "~/components/Input"; import Scene from "~/components/Scene"; import Text from "~/components/Text"; +import { UserChangeEmailDialog } from "~/components/UserDialogs"; +import env from "~/env"; import useCurrentUser from "~/hooks/useCurrentUser"; +import useStores from "~/hooks/useStores"; import ImageInput from "./components/ImageInput"; import SettingRow from "./components/SettingRow"; const Profile = () => { const user = useCurrentUser(); + const { dialogs } = useStores(); const form = React.useRef(null); - const [name, setName] = React.useState(user.name || ""); + const [name, setName] = React.useState(user.name); const { t } = useTranslation(); const handleSubmit = async (ev: React.SyntheticEvent) => { @@ -29,6 +33,15 @@ const Profile = () => { } }; + const handleChangeEmail = () => { + dialogs.openModal({ + title: t("Change email"), + content: ( + + ), + }); + }; + const handleNameChange = (ev: React.ChangeEvent) => { setName(ev.target.value); }; @@ -81,6 +94,17 @@ const Profile = () => { /> + {env.EMAIL_ENABLED && ( + + + + )} + diff --git a/app/utils/viewTransition.ts b/app/utils/viewTransition.ts index 95dcef9461..586e84fb5f 100644 --- a/app/utils/viewTransition.ts +++ b/app/utils/viewTransition.ts @@ -4,7 +4,7 @@ * * @param callback The callback to call inside the view transition. */ -export const startViewTransition = (callback: UpdateCallback) => { +export const startViewTransition = (callback: ViewTransitionUpdateCallback) => { if (self.document.startViewTransition) { self.document.startViewTransition(callback); } else { diff --git a/package.json b/package.json index fa5b42c5f3..80f16c0c2f 100644 --- a/package.json +++ b/package.json @@ -124,7 +124,7 @@ "glob": "^8.1.0", "http-errors": "2.0.0", "i18next": "^22.5.1", - "i18next-fs-backend": "^2.3.2", + "i18next-fs-backend": "^2.6.0", "i18next-http-backend": "^2.5.0", "invariant": "^2.2.4", "ioredis": "^5.4.1", @@ -150,7 +150,7 @@ "markdown-it": "^13.0.2", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^2.0.0", - "mermaid": "11.4.0", + "mermaid": "11.4.1", "mime-types": "^2.1.35", "mobx": "^4.15.4", "mobx-react": "^6.3.1", @@ -179,7 +179,7 @@ "prosemirror-inputrules": "^1.4.0", "prosemirror-keymap": "^1.2.2", "prosemirror-markdown": "^1.13.1", - "prosemirror-model": "^1.23.0", + "prosemirror-model": "^1.24.0", "prosemirror-schema-list": "^1.4.1", "prosemirror-state": "^1.4.3", "prosemirror-tables": "^1.4.0", @@ -237,7 +237,7 @@ "tmp": "^0.2.3", "turndown": "^7.2.0", "umzug": "^3.8.1", - "utility-types": "^3.10.0", + "utility-types": "^3.11.0", "uuid": "^8.3.2", "validator": "13.12.0", "vite": "^5.4.11", @@ -333,9 +333,9 @@ "discord-api-types": "^0.37.102", "eslint": "^8.57.0", "eslint-config-prettier": "^8.10.0", - "eslint-import-resolver-typescript": "^3.6.3", + "eslint-import-resolver-typescript": "^3.7.0", "eslint-plugin-es": "^4.1.0", - "eslint-plugin-import": "^2.29.1", + "eslint-plugin-import": "^2.31.0", "eslint-plugin-jsx-a11y": "^6.10.2", "eslint-plugin-lodash": "^7.4.0", "eslint-plugin-node": "^11.1.0", @@ -348,14 +348,14 @@ "jest-environment-jsdom": "^29.7.0", "jest-fetch-mock": "^3.0.3", "lint-staged": "^13.3.0", - "nodemon": "^3.1.7", + "nodemon": "^3.1.9", "postinstall-postinstall": "^2.1.0", "prettier": "^2.8.8", "react-refresh": "^0.14.2", "rimraf": "^2.5.4", "rollup-plugin-webpack-stats": "^0.4.1", "terser": "^5.36.0", - "typescript": "^5.6.3", + "typescript": "^5.7.2", "vite-plugin-static-copy": "^0.17.0", "yarn-deduplicate": "^6.0.2" }, diff --git a/server/commands/documentImporter.ts b/server/commands/documentImporter.ts index 432d343968..d8d1d3138e 100644 --- a/server/commands/documentImporter.ts +++ b/server/commands/documentImporter.ts @@ -1,5 +1,4 @@ import emojiRegex from "emoji-regex"; -import escapeRegExp from "lodash/escapeRegExp"; import truncate from "lodash/truncate"; import parseTitle from "@shared/utils/parseTitle"; import { DocumentValidation } from "@shared/validations"; @@ -51,10 +50,7 @@ async function documentImporter({ if (text.trim().startsWith("# ")) { const result = parseTitle(text); title = result.title; - text = text - .trim() - .replace(new RegExp(`#\\s+${escapeRegExp(title)}`), "") - .trimStart(); + text = text.replace(/^.+(\n|$)/, ""); } // Replace any
generated by the turndown plugin with escaped newlines diff --git a/server/commands/documentLoader.ts b/server/commands/documentLoader.ts index 4262e54b06..24132ce9a0 100644 --- a/server/commands/documentLoader.ts +++ b/server/commands/documentLoader.ts @@ -171,15 +171,19 @@ export default async function loadDocument({ throw AuthorizationError(); } - const childDocumentIds = - (await share.document?.findAllChildDocumentIds({ - archivedAt: { - [Op.is]: null, - }, - })) ?? []; + // If the document is not a direct child of the shared document then we + // need to check if it is nested within the shared document somewhere. + if (document.parentDocumentId !== share.documentId) { + const childDocumentIds = + (await share.document?.findAllChildDocumentIds({ + archivedAt: { + [Op.is]: null, + }, + })) ?? []; - if (!childDocumentIds.includes(document.id)) { - throw AuthorizationError(); + if (!childDocumentIds.includes(document.id)) { + throw AuthorizationError(); + } } } diff --git a/server/commands/groupCreator.ts b/server/commands/groupCreator.ts index 6151cd1b7b..052deaef4b 100644 --- a/server/commands/groupCreator.ts +++ b/server/commands/groupCreator.ts @@ -3,6 +3,7 @@ import { Event, Group, type User } from "@server/models"; type Props = { name: string; + externalId: string | undefined; actor: User; ip: string; transaction?: Transaction; @@ -10,6 +11,7 @@ type Props = { export default async function groupCreator({ name, + externalId, actor, ip, transaction, @@ -17,6 +19,7 @@ export default async function groupCreator({ const group = await Group.create( { name, + externalId, teamId: actor.teamId, createdById: actor.id, }, diff --git a/server/commands/groupUpdater.ts b/server/commands/groupUpdater.ts index 98ddb966fc..b694604212 100644 --- a/server/commands/groupUpdater.ts +++ b/server/commands/groupUpdater.ts @@ -3,7 +3,8 @@ import { Event, type Group, type User } from "@server/models"; type Props = { group: Group; - name: string; + name: string | undefined; + externalId: string | undefined; actor: User; ip: string; transaction?: Transaction; @@ -12,11 +13,17 @@ type Props = { export default async function groupUpdater({ group, name, + externalId, actor, ip, transaction, }: Props): Promise { - group.name = name; + if (name) { + group.name = name; + } + if (externalId) { + group.externalId = externalId; + } if (group.changed()) { await group.save({ transaction }); diff --git a/server/commands/userProvisioner.test.ts b/server/commands/userProvisioner.test.ts index f4ac0920be..88bc6259f8 100644 --- a/server/commands/userProvisioner.test.ts +++ b/server/commands/userProvisioner.test.ts @@ -437,7 +437,7 @@ describe("userProvisioner", () => { } expect(error && error.toString()).toContain( - "The domain is not allowed for this team" + "The domain is not allowed for this workspace" ); }); }); diff --git a/server/commands/userProvisioner.ts b/server/commands/userProvisioner.ts index 905bddbef0..f6221358a7 100644 --- a/server/commands/userProvisioner.ts +++ b/server/commands/userProvisioner.ts @@ -1,6 +1,5 @@ import { InferCreationAttributes } from "sequelize"; import { UserRole } from "@shared/types"; -import { parseEmail } from "@shared/utils/email"; import InviteAcceptedEmail from "@server/emails/templates/InviteAcceptedEmail"; import { DomainNotAllowedError, @@ -227,8 +226,7 @@ export default async function userProvisioner({ // If the team settings do not allow this domain, // throw an error and fail user creation. - const { domain } = parseEmail(email); - if (team && !(await team.isDomainAllowed(domain))) { + if (team && !(await team.isDomainAllowed(email))) { throw DomainNotAllowedError(); } diff --git a/server/emails/mailer.tsx b/server/emails/mailer.tsx index 1141fca96f..b2a1296ed7 100644 --- a/server/emails/mailer.tsx +++ b/server/emails/mailer.tsx @@ -125,7 +125,18 @@ export class Mailer { if (!transporter) { Logger.info( "email", - `Attempted to send email "${data.subject}" to ${data.to} but no transport configured.` + [ + `Attempted to send email but no transport configured.`, + ``, + `--------------`, + `From: ${data.from.address}`, + `To: ${data.to}`, + `Subject: ${data.subject}`, + `Preview: ${data.previewText}`, + `--------------`, + ``, + data.text, + ].join("\n") ); return; } diff --git a/server/emails/templates/BaseEmail.tsx b/server/emails/templates/BaseEmail.tsx index 13c9e1a4a9..0744bfb51f 100644 --- a/server/emails/templates/BaseEmail.tsx +++ b/server/emails/templates/BaseEmail.tsx @@ -55,7 +55,7 @@ export default abstract class BaseEmail< if (!env.SMTP_FROM_EMAIL) { Logger.info( "email", - `Email ${this.constructor.name} not sent due to missing SMTP configuration` + `Email ${this.constructor.name} not sent due to missing SMTP_FROM_EMAIL configuration` ); return; } diff --git a/server/emails/templates/CommentCreatedEmail.tsx b/server/emails/templates/CommentCreatedEmail.tsx index cc90937d53..3396caa272 100644 --- a/server/emails/templates/CommentCreatedEmail.tsx +++ b/server/emails/templates/CommentCreatedEmail.tsx @@ -24,7 +24,7 @@ type InputProps = EmailProps & { type BeforeSend = { document: Document; - collection: Collection; + collection: Collection | null; body: string | undefined; isFirstComment: boolean; isReply: boolean; @@ -52,14 +52,10 @@ export default class CommentCreatedEmail extends BaseEmail< return false; } - const collection = await document.$get("collection"); - if (!collection) { - return false; - } - - const [comment, team] = await Promise.all([ + const [comment, team, collection] = await Promise.all([ Comment.findByPk(commentId), document.$get("team"), + document.$get("collection"), ]); if (!comment || !team) { return false; @@ -129,7 +125,7 @@ export default class CommentCreatedEmail extends BaseEmail< return ` ${actorName} ${isReply ? "replied to a thread in" : "commented on"} "${ document.title - }"${collection.name ? `in the ${collection.name} collection` : ""}. + }"${collection?.name ? `in the ${collection.name} collection` : ""}. Open Thread: ${teamUrl}${document.url}?commentId=${commentId} `; @@ -160,7 +156,7 @@ Open Thread: ${teamUrl}${document.url}?commentId=${commentId}

{actorName} {isReply ? "replied to a thread in" : "commented on"}{" "} {document.title}{" "} - {collection.name ? `in the ${collection.name} collection` : ""}. + {collection?.name ? `in the ${collection.name} collection` : ""}.

{body && ( <> diff --git a/server/emails/templates/ConfirmUpdateEmail.tsx b/server/emails/templates/ConfirmUpdateEmail.tsx new file mode 100644 index 0000000000..05b903513b --- /dev/null +++ b/server/emails/templates/ConfirmUpdateEmail.tsx @@ -0,0 +1,73 @@ +import * as React from "react"; +import env from "@server/env"; +import BaseEmail, { EmailMessageCategory, EmailProps } from "./BaseEmail"; +import Body from "./components/Body"; +import Button from "./components/Button"; +import EmailTemplate from "./components/EmailLayout"; +import EmptySpace from "./components/EmptySpace"; +import Footer from "./components/Footer"; +import Header from "./components/Header"; +import Heading from "./components/Heading"; + +type Props = EmailProps & { + code: string; + previous: string | null; + teamUrl: string; +}; + +/** + * Email sent to a user when they request to change their email. + */ +export default class ConfirmUpdateEmail extends BaseEmail { + protected get category() { + return EmailMessageCategory.Authentication; + } + + protected subject() { + return `Your email update request`; + } + + protected preview() { + return `Here’s your email change confirmation.`; + } + + protected renderAsText({ teamUrl, code, previous, to }: Props): string { + return ` +You requested to update your ${env.APP_NAME} account email. Please +follow the link below to confirm the change ${ + previous ? `from ${previous} ` : "" + }to ${to}. + + ${this.updateLink(teamUrl, code)} + `; + } + + protected render({ teamUrl, code, previous, to }: Props) { + return ( + +
+ + + Your email update request +

+ You requested to update your {env.APP_NAME} account email. Please + click below to confirm the change{" "} + {previous ? `from ${previous} ` : ""}to {to}. +

+ +

+ +

+ + +