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 (
{collection.name}

{this.t( "{{ actorName }} invited you to {{ permission }} documents in the", { actorName, permission } )}{" "} {collection.name} {this.t("collection")} .

); } }