Files
outline/server/emails/templates/CollectionSharedEmail.tsx
Tom Moor 5693618de4 Add translation hooks to transactional emails (#11785)
* First pass

* fix: Missing translations

* fix: Missing translations

* welcome

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* translations

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-03-20 23:28:51 -04:00

118 lines
3.2 KiB
TypeScript

import * as React from "react";
import { CollectionPermission } from "@shared/types";
import { Collection, UserMembership } from "@server/models";
import type { EmailProps } from "./BaseEmail";
import BaseEmail, { EmailMessageCategory } from "./BaseEmail";
import Body from "./components/Body";
import Button from "./components/Button";
import EmailTemplate from "./components/EmailLayout";
import Header from "./components/Header";
import Heading from "./components/Heading";
type InputProps = EmailProps & {
userId: string;
collectionId: string;
actorName: string;
teamUrl: string;
};
type BeforeSend = {
collection: Collection;
membership: UserMembership;
};
type Props = InputProps & BeforeSend;
/**
* Email sent to a user when someone adds them to a collection.
*/
export default class CollectionSharedEmail extends BaseEmail<
InputProps,
BeforeSend
> {
protected get category() {
return EmailMessageCategory.Notification;
}
protected async beforeSend({ userId, collectionId }: InputProps) {
const collection = await Collection.findByPk(collectionId);
if (!collection) {
return false;
}
const membership = await UserMembership.findOne({
where: {
collectionId,
userId,
},
});
if (!membership) {
return false;
}
return { collection, membership };
}
protected subject({ actorName, collection }: Props) {
return this.t(
"{{ actorName }} invited you to the “{{ collectionName }}” collection",
{ actorName, collectionName: collection.name }
);
}
protected preview({ actorName }: Props): string {
return this.t("{{ actorName }} invited you to a collection", { actorName });
}
protected fromName({ actorName }: Props) {
return actorName;
}
protected renderAsText({ actorName, teamUrl, collection }: Props): string {
return `
${this.t("{{ actorName }} invited you to the “{{ collectionName }}” collection.", { actorName, collectionName: collection.name })}
${this.t("View Collection")}: ${teamUrl}${collection.path}
`;
}
protected render(props: Props) {
const { collection, membership, actorName, teamUrl } = props;
const collectionUrl = `${teamUrl}${collection.path}?ref=notification-email`;
const permission =
membership.permission === CollectionPermission.ReadWrite
? this.t("view and edit")
: membership.permission === CollectionPermission.Admin
? this.t("manage")
: this.t("view");
return (
<EmailTemplate
previewText={this.preview(props)}
goToAction={{
url: collectionUrl,
name: this.t("View Collection"),
}}
>
<Header />
<Body>
<Heading>{collection.name}</Heading>
<p>
{this.t(
"{{ actorName }} invited you to {{ permission }} documents in the",
{ actorName, permission }
)}{" "}
<a href={collectionUrl}>{collection.name}</a> {this.t("collection")}
.
</p>
<p>
<Button href={collectionUrl}>{this.t("View Collection")}</Button>
</p>
</Body>
</EmailTemplate>
);
}
}