Files
mintel.me/apps/web/src/payload/collections/CrmContacts.ts
Marc Mintel 3f6fa36f9b
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 7s
Build & Deploy / 🏗️ Build (push) Failing after 6m25s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 QA (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
feat(crm): implement bulk mail action for contacts
- Add BulkMailButton component for Payload list view
- Add bulkMailEndpoint handler for processing prompts
- Integrate bulk mail action into CrmContacts collection
- Update dev:clean script to skip interactive prompts
2026-03-30 19:27:56 +02:00

146 lines
3.2 KiB
TypeScript

import type { CollectionConfig } from "payload";
import { bulkMailEndpointHandler } from "../endpoints/bulkMailEndpoint";
export const CrmContacts: CollectionConfig = {
slug: "crm-contacts",
labels: {
singular: "Contact",
plural: "Contacts",
},
admin: {
useAsTitle: "fullName",
defaultColumns: ["fullName", "email", "account"],
group: "CRM",
description:
"Contacts are the individual people linked to an Account. A person should only be created once and can be assigned to a company here.",
components: {
views: {
list: {
actions: ["@/src/payload/components/BulkMailButton#BulkMailButton"],
},
},
},
},
endpoints: [
{
path: "/bulk-mail",
method: "post",
handler: bulkMailEndpointHandler,
},
],
access: {
read: ({ req: { user } }) => Boolean(user),
create: ({ req: { user } }) => Boolean(user),
update: ({ req: { user } }) => Boolean(user),
delete: ({ req: { user } }) => Boolean(user),
},
hooks: {
beforeChange: [
({ data }) => {
if (data?.firstName || data?.lastName) {
data.fullName =
`${data.firstName || ""} ${data.lastName || ""}`.trim();
}
return data;
},
],
afterRead: [
({ doc }) => {
if (!doc.fullName && (doc.firstName || doc.lastName)) {
return {
...doc,
fullName: `${doc.firstName || ""} ${doc.lastName || ""}`.trim(),
};
}
return doc;
},
],
},
fields: [
{
name: "fullName",
type: "text",
admin: {
hidden: true,
},
},
{
type: "row",
fields: [
{
name: "firstName",
type: "text",
required: true,
admin: {
width: "50%",
},
},
{
name: "lastName",
type: "text",
required: true,
admin: {
width: "50%",
},
},
],
},
{
name: "email",
type: "email",
required: true,
unique: true,
admin: {
description: "Primary email address for communication tracking.",
},
},
{
type: "row",
fields: [
{
name: "phone",
type: "text",
admin: {
width: "50%",
},
},
{
name: "linkedIn",
type: "text",
admin: {
width: "50%",
placeholder: "https://linkedin.com/in/...",
},
},
],
},
{
name: "role",
type: "text",
label: "Job Title / Role",
admin: {
description: "e.g. CEO, Marketing Manager, Technical Lead",
},
},
{
name: "account",
type: "relationship",
relationTo: "crm-accounts",
label: "Company / Account",
admin: {
description:
"Link this person to an organization from the Accounts collection.",
},
},
{
name: "interactions",
type: "join",
collection: "crm-interactions",
on: "contact",
admin: {
description:
"Timeline of all communication logged directly with this person.",
},
},
],
};