190 lines
4.9 KiB
TypeScript
190 lines
4.9 KiB
TypeScript
import type { CollectionConfig } from "payload";
|
|
import { aiEndpointHandler } from "../endpoints/aiEndpoint";
|
|
|
|
export const CrmAccounts: CollectionConfig = {
|
|
slug: "crm-accounts",
|
|
labels: {
|
|
singular: "Account",
|
|
plural: "Accounts",
|
|
},
|
|
admin: {
|
|
useAsTitle: "name",
|
|
defaultColumns: ["name", "status", "leadTemperature", "updatedAt"],
|
|
group: "CRM",
|
|
description:
|
|
"Accounts represent companies or organizations. They are the central hub linking Contacts and Interactions together. Use this to track the overall relationship status.",
|
|
},
|
|
endpoints: [
|
|
{
|
|
path: "/:id/analyze",
|
|
method: "post",
|
|
handler: aiEndpointHandler,
|
|
},
|
|
],
|
|
access: {
|
|
read: ({ req: { user } }) => Boolean(user), // Admin only
|
|
create: ({ req: { user } }) => Boolean(user),
|
|
update: ({ req: { user } }) => Boolean(user),
|
|
delete: ({ req: { user } }) => Boolean(user),
|
|
},
|
|
fields: [
|
|
{
|
|
name: "analyzeButton",
|
|
type: "ui",
|
|
admin: {
|
|
components: {
|
|
Field: "@/src/payload/components/AiAnalyzeButton#AiAnalyzeButton",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "name",
|
|
type: "text",
|
|
required: true,
|
|
label: "Company / Project Name",
|
|
admin: {
|
|
description:
|
|
"Enter the official name of the business or the research project name.",
|
|
},
|
|
},
|
|
{
|
|
name: "website",
|
|
type: "text",
|
|
label: "Website URL",
|
|
admin: {
|
|
description:
|
|
"The main website of the account. Required for triggering the AI Website Analysis.",
|
|
placeholder: "https://example.com",
|
|
},
|
|
},
|
|
{
|
|
type: "row",
|
|
fields: [
|
|
{
|
|
name: "status",
|
|
type: "select",
|
|
options: [
|
|
{ label: "Lead (Prospect)", value: "lead" },
|
|
{ label: "Active Client", value: "client" },
|
|
{ label: "Business Partner", value: "partner" },
|
|
{ label: "Lost / Archive", value: "lost" },
|
|
],
|
|
defaultValue: "lead",
|
|
admin: {
|
|
width: "50%",
|
|
description: "Current lifecycle stage of this business relation.",
|
|
},
|
|
},
|
|
{
|
|
name: "leadTemperature",
|
|
type: "select",
|
|
options: [
|
|
{ label: "❄️ Cold (New Research)", value: "cold" },
|
|
{ label: "🔥 Warm (In Contact)", value: "warm" },
|
|
{ label: "⚡ Hot (Negotiation / Quote)", value: "hot" },
|
|
],
|
|
admin: {
|
|
condition: (data) => {
|
|
return data?.status === "lead";
|
|
},
|
|
width: "50%",
|
|
description: "Indicates how likely this lead is to convert soon.",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: "row",
|
|
fields: [
|
|
{
|
|
name: "industry",
|
|
type: "text",
|
|
admin: {
|
|
width: "50%",
|
|
description: "Industry or category of this account (e.g. Messebauer, Handwerk).",
|
|
},
|
|
},
|
|
{
|
|
name: "websiteStatus",
|
|
type: "select",
|
|
options: [
|
|
{ label: "🟢 Good", value: "gut" },
|
|
{ label: "🟡 OK / Average", value: "ok" },
|
|
{ label: "🔴 Bad / Old", value: "schlecht" },
|
|
{ label: "❓ Unknown", value: "unknown" },
|
|
],
|
|
admin: {
|
|
width: "50%",
|
|
description: "Quality assessment of their current website.",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "notes",
|
|
type: "textarea",
|
|
admin: {
|
|
description: "Internal notes and research findings for this account.",
|
|
},
|
|
},
|
|
{
|
|
name: "assignedTo",
|
|
type: "relationship",
|
|
relationTo: "users",
|
|
label: "Account Manager (User)",
|
|
admin: {
|
|
description: "The internal team member responsible for this account.",
|
|
},
|
|
},
|
|
{
|
|
name: "reports",
|
|
type: "relationship",
|
|
relationTo: "media",
|
|
hasMany: true,
|
|
label: "AI Reports & Documents",
|
|
admin: {
|
|
description:
|
|
"All generated PDF estimates and strategy documents appear here.",
|
|
},
|
|
},
|
|
{
|
|
name: "topics",
|
|
type: "join",
|
|
collection: "crm-topics",
|
|
on: "account",
|
|
admin: {
|
|
description:
|
|
"Projects, deals, or specific topics active for this client.",
|
|
},
|
|
},
|
|
{
|
|
name: "contacts",
|
|
type: "join",
|
|
collection: "crm-contacts",
|
|
on: "account",
|
|
admin: {
|
|
description: "All contacts associated with this account.",
|
|
},
|
|
},
|
|
{
|
|
name: "interactions",
|
|
type: "join",
|
|
collection: "crm-interactions",
|
|
on: "account",
|
|
admin: {
|
|
description:
|
|
"Timeline of all communication logged against this account.",
|
|
},
|
|
},
|
|
{
|
|
name: "projects",
|
|
type: "join",
|
|
collection: "projects",
|
|
on: "account",
|
|
admin: {
|
|
description: "All high-level projects associated with this account.",
|
|
},
|
|
},
|
|
],
|
|
};
|