crm finish
This commit is contained in:
@@ -16,6 +16,7 @@ import type {
|
||||
CrmCustomerHierarchyOptionDto,
|
||||
CrmRecordDetailDto,
|
||||
CrmRecordInput,
|
||||
CrmLifecycleStage,
|
||||
CrmRecordStatus,
|
||||
CrmRecordSummaryDto,
|
||||
} from "@mrp/shared/dist/crm/types.js";
|
||||
@@ -121,12 +122,32 @@ export const api = {
|
||||
token
|
||||
);
|
||||
},
|
||||
getCustomers(token: string, filters?: { q?: string; status?: CrmRecordStatus; state?: string }) {
|
||||
deleteAttachment(token: string, fileId: string) {
|
||||
return request<FileAttachmentDto>(
|
||||
`/api/v1/files/${fileId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
},
|
||||
token
|
||||
);
|
||||
},
|
||||
getCustomers(
|
||||
token: string,
|
||||
filters?: {
|
||||
q?: string;
|
||||
status?: CrmRecordStatus;
|
||||
lifecycleStage?: CrmLifecycleStage;
|
||||
state?: string;
|
||||
flag?: "PREFERRED" | "STRATEGIC" | "REQUIRES_APPROVAL" | "BLOCKED";
|
||||
}
|
||||
) {
|
||||
return request<CrmRecordSummaryDto[]>(
|
||||
`/api/v1/crm/customers${buildQueryString({
|
||||
q: filters?.q,
|
||||
status: filters?.status,
|
||||
lifecycleStage: filters?.lifecycleStage,
|
||||
state: filters?.state,
|
||||
flag: filters?.flag,
|
||||
})}`,
|
||||
undefined,
|
||||
token
|
||||
@@ -184,12 +205,23 @@ export const api = {
|
||||
token
|
||||
);
|
||||
},
|
||||
getVendors(token: string, filters?: { q?: string; status?: CrmRecordStatus; state?: string }) {
|
||||
getVendors(
|
||||
token: string,
|
||||
filters?: {
|
||||
q?: string;
|
||||
status?: CrmRecordStatus;
|
||||
lifecycleStage?: CrmLifecycleStage;
|
||||
state?: string;
|
||||
flag?: "PREFERRED" | "STRATEGIC" | "REQUIRES_APPROVAL" | "BLOCKED";
|
||||
}
|
||||
) {
|
||||
return request<CrmRecordSummaryDto[]>(
|
||||
`/api/v1/crm/vendors${buildQueryString({
|
||||
q: filters?.q,
|
||||
status: filters?.status,
|
||||
lifecycleStage: filters?.lifecycleStage,
|
||||
state: filters?.state,
|
||||
flag: filters?.flag,
|
||||
})}`,
|
||||
undefined,
|
||||
token
|
||||
|
||||
@@ -8,6 +8,7 @@ import { api, ApiError } from "../../lib/api";
|
||||
interface CrmAttachmentsPanelProps {
|
||||
ownerType: string;
|
||||
ownerId: string;
|
||||
onAttachmentCountChange?: (count: number) => void;
|
||||
}
|
||||
|
||||
function formatFileSize(sizeBytes: number) {
|
||||
@@ -22,11 +23,12 @@ function formatFileSize(sizeBytes: number) {
|
||||
return `${(sizeBytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
export function CrmAttachmentsPanel({ ownerType, ownerId }: CrmAttachmentsPanelProps) {
|
||||
export function CrmAttachmentsPanel({ ownerType, ownerId, onAttachmentCountChange }: CrmAttachmentsPanelProps) {
|
||||
const { token, user } = useAuth();
|
||||
const [attachments, setAttachments] = useState<FileAttachmentDto[]>([]);
|
||||
const [status, setStatus] = useState("Loading attachments...");
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [deletingAttachmentId, setDeletingAttachmentId] = useState<string | null>(null);
|
||||
|
||||
const canReadFiles = user?.permissions.includes(permissions.filesRead) ?? false;
|
||||
const canWriteFiles = user?.permissions.includes(permissions.filesWrite) ?? false;
|
||||
@@ -40,6 +42,7 @@ export function CrmAttachmentsPanel({ ownerType, ownerId }: CrmAttachmentsPanelP
|
||||
.getAttachments(token, ownerType, ownerId)
|
||||
.then((nextAttachments) => {
|
||||
setAttachments(nextAttachments);
|
||||
onAttachmentCountChange?.(nextAttachments.length);
|
||||
setStatus(
|
||||
nextAttachments.length === 0 ? "No attachments uploaded yet." : `${nextAttachments.length} attachment(s) available.`
|
||||
);
|
||||
@@ -48,7 +51,7 @@ export function CrmAttachmentsPanel({ ownerType, ownerId }: CrmAttachmentsPanelP
|
||||
const message = error instanceof ApiError ? error.message : "Unable to load attachments.";
|
||||
setStatus(message);
|
||||
});
|
||||
}, [canReadFiles, ownerId, ownerType, token]);
|
||||
}, [canReadFiles, onAttachmentCountChange, ownerId, ownerType, token]);
|
||||
|
||||
async function handleUpload(event: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = event.target.files?.[0];
|
||||
@@ -61,7 +64,11 @@ export function CrmAttachmentsPanel({ ownerType, ownerId }: CrmAttachmentsPanelP
|
||||
|
||||
try {
|
||||
const attachment = await api.uploadFile(token, file, ownerType, ownerId);
|
||||
setAttachments((current) => [attachment, ...current]);
|
||||
setAttachments((current) => {
|
||||
const nextAttachments = [attachment, ...current];
|
||||
onAttachmentCountChange?.(nextAttachments.length);
|
||||
return nextAttachments;
|
||||
});
|
||||
setStatus("Attachment uploaded.");
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof ApiError ? error.message : "Unable to upload attachment.";
|
||||
@@ -88,6 +95,30 @@ export function CrmAttachmentsPanel({ ownerType, ownerId }: CrmAttachmentsPanelP
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(attachment: FileAttachmentDto) {
|
||||
if (!token || !canWriteFiles) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDeletingAttachmentId(attachment.id);
|
||||
setStatus(`Deleting ${attachment.originalName}...`);
|
||||
|
||||
try {
|
||||
await api.deleteAttachment(token, attachment.id);
|
||||
setAttachments((current) => {
|
||||
const nextAttachments = current.filter((item) => item.id !== attachment.id);
|
||||
onAttachmentCountChange?.(nextAttachments.length);
|
||||
return nextAttachments;
|
||||
});
|
||||
setStatus("Attachment deleted.");
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof ApiError ? error.message : "Unable to delete attachment.";
|
||||
setStatus(message);
|
||||
} finally {
|
||||
setDeletingAttachmentId(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="min-w-0 rounded-[28px] border border-line/70 bg-surface/90 p-6 shadow-panel 2xl:p-7">
|
||||
<div className="flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between">
|
||||
@@ -135,6 +166,16 @@ export function CrmAttachmentsPanel({ ownerType, ownerId }: CrmAttachmentsPanelP
|
||||
>
|
||||
Open
|
||||
</button>
|
||||
{canWriteFiles ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleDelete(attachment)}
|
||||
disabled={deletingAttachmentId === attachment.id}
|
||||
className="rounded-2xl border border-rose-400/40 px-4 py-2 text-sm font-semibold text-rose-700 disabled:cursor-not-allowed disabled:opacity-60 dark:text-rose-300"
|
||||
>
|
||||
{deletingAttachmentId === attachment.id ? "Deleting..." : "Delete"}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { api, ApiError } from "../../lib/api";
|
||||
import { CrmAttachmentsPanel } from "./CrmAttachmentsPanel";
|
||||
import { CrmContactsPanel } from "./CrmContactsPanel";
|
||||
import { CrmContactEntryForm } from "./CrmContactEntryForm";
|
||||
import { CrmLifecycleBadge } from "./CrmLifecycleBadge";
|
||||
import { CrmContactTypeBadge } from "./CrmContactTypeBadge";
|
||||
import { CrmStatusBadge } from "./CrmStatusBadge";
|
||||
import { type CrmEntity, crmConfigs, emptyCrmContactEntryInput } from "./config";
|
||||
@@ -78,6 +79,13 @@ export function CrmDetailPage({ entity }: CrmDetailPageProps) {
|
||||
contactHistory: [nextEntry, ...current.contactHistory].sort(
|
||||
(left, right) => new Date(right.contactAt).getTime() - new Date(left.contactAt).getTime()
|
||||
),
|
||||
rollups: {
|
||||
lastContactAt: nextEntry.contactAt,
|
||||
contactHistoryCount: (current.rollups?.contactHistoryCount ?? current.contactHistory.length) + 1,
|
||||
contactCount: current.rollups?.contactCount ?? current.contacts?.length ?? 0,
|
||||
attachmentCount: current.rollups?.attachmentCount ?? 0,
|
||||
childCustomerCount: current.rollups?.childCustomerCount,
|
||||
},
|
||||
}
|
||||
: current
|
||||
);
|
||||
@@ -102,7 +110,10 @@ export function CrmDetailPage({ entity }: CrmDetailPageProps) {
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.24em] text-muted">CRM Detail</p>
|
||||
<h3 className="mt-3 text-3xl font-bold text-text">{record.name}</h3>
|
||||
<div className="mt-4">
|
||||
<CrmStatusBadge status={record.status} />
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<CrmStatusBadge status={record.status} />
|
||||
{record.lifecycleStage ? <CrmLifecycleBadge stage={record.lifecycleStage} /> : null}
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-muted">
|
||||
{config.singularLabel} record last updated {new Date(record.updatedAt).toLocaleString()}.
|
||||
@@ -165,6 +176,18 @@ export function CrmDetailPage({ entity }: CrmDetailPageProps) {
|
||||
<div className="mt-8 rounded-2xl border border-line/70 bg-page/70 px-4 py-4 text-sm text-muted">
|
||||
Created {new Date(record.createdAt).toLocaleDateString()}
|
||||
</div>
|
||||
<div className="mt-4 rounded-2xl border border-line/70 bg-page/70 px-4 py-4">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.18em] text-muted">Operational Flags</p>
|
||||
<div className="mt-3 flex flex-wrap gap-2 text-xs font-semibold uppercase tracking-[0.12em]">
|
||||
{record.preferredAccount ? <span className="rounded-full border border-line/70 px-3 py-1 text-text">Preferred</span> : null}
|
||||
{record.strategicAccount ? <span className="rounded-full border border-line/70 px-3 py-1 text-text">Strategic</span> : null}
|
||||
{record.requiresApproval ? <span className="rounded-full border border-amber-400/40 px-3 py-1 text-amber-700 dark:text-amber-300">Requires Approval</span> : null}
|
||||
{record.blockedAccount ? <span className="rounded-full border border-rose-400/40 px-3 py-1 text-rose-700 dark:text-rose-300">Blocked</span> : null}
|
||||
{!record.preferredAccount && !record.strategicAccount && !record.requiresApproval && !record.blockedAccount ? (
|
||||
<span className="rounded-full border border-line/70 px-3 py-1 text-muted">Standard</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{entity === "customer" ? (
|
||||
<div className="mt-4 rounded-2xl border border-line/70 bg-page/70 px-4 py-4">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.18em] text-muted">Reseller Profile</p>
|
||||
@@ -187,6 +210,26 @@ export function CrmDetailPage({ entity }: CrmDetailPageProps) {
|
||||
) : null}
|
||||
</article>
|
||||
</div>
|
||||
<section className="grid gap-4 xl:grid-cols-4">
|
||||
<article className="rounded-[24px] border border-line/70 bg-surface/90 px-5 py-5 shadow-panel">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.18em] text-muted">Last Contact</p>
|
||||
<div className="mt-3 text-lg font-bold text-text">
|
||||
{record.rollups?.lastContactAt ? new Date(record.rollups.lastContactAt).toLocaleDateString() : "None"}
|
||||
</div>
|
||||
</article>
|
||||
<article className="rounded-[24px] border border-line/70 bg-surface/90 px-5 py-5 shadow-panel">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.18em] text-muted">Timeline Entries</p>
|
||||
<div className="mt-3 text-lg font-bold text-text">{record.rollups?.contactHistoryCount ?? record.contactHistory.length}</div>
|
||||
</article>
|
||||
<article className="rounded-[24px] border border-line/70 bg-surface/90 px-5 py-5 shadow-panel">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.18em] text-muted">Account Contacts</p>
|
||||
<div className="mt-3 text-lg font-bold text-text">{record.rollups?.contactCount ?? record.contacts?.length ?? 0}</div>
|
||||
</article>
|
||||
<article className="rounded-[24px] border border-line/70 bg-surface/90 px-5 py-5 shadow-panel">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.18em] text-muted">Attachments</p>
|
||||
<div className="mt-3 text-lg font-bold text-text">{record.rollups?.attachmentCount ?? 0}</div>
|
||||
</article>
|
||||
</section>
|
||||
{entity === "customer" && (record.childCustomers?.length ?? 0) > 0 ? (
|
||||
<section className="rounded-[28px] border border-line/70 bg-surface/90 p-6 shadow-panel 2xl:p-7">
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.24em] text-muted">Hierarchy</p>
|
||||
@@ -212,7 +255,21 @@ export function CrmDetailPage({ entity }: CrmDetailPageProps) {
|
||||
ownerId={record.id}
|
||||
contacts={record.contacts ?? []}
|
||||
onContactsChange={(contacts: CrmContactDto[]) =>
|
||||
setRecord((current) => (current ? { ...current, contacts } : current))
|
||||
setRecord((current) =>
|
||||
current
|
||||
? {
|
||||
...current,
|
||||
contacts,
|
||||
rollups: {
|
||||
lastContactAt: current.rollups?.lastContactAt ?? null,
|
||||
contactHistoryCount: current.rollups?.contactHistoryCount ?? current.contactHistory.length,
|
||||
contactCount: contacts.length,
|
||||
attachmentCount: current.rollups?.attachmentCount ?? 0,
|
||||
childCustomerCount: current.rollups?.childCustomerCount,
|
||||
},
|
||||
}
|
||||
: current
|
||||
)
|
||||
}
|
||||
/>
|
||||
<section className="grid gap-4 2xl:grid-cols-[minmax(360px,0.88fr)_minmax(0,1.12fr)]">
|
||||
@@ -264,7 +321,26 @@ export function CrmDetailPage({ entity }: CrmDetailPageProps) {
|
||||
)}
|
||||
</article>
|
||||
</section>
|
||||
<CrmAttachmentsPanel ownerType={config.fileOwnerType} ownerId={record.id} />
|
||||
<CrmAttachmentsPanel
|
||||
ownerType={config.fileOwnerType}
|
||||
ownerId={record.id}
|
||||
onAttachmentCountChange={(attachmentCount) =>
|
||||
setRecord((current) =>
|
||||
current
|
||||
? {
|
||||
...current,
|
||||
rollups: {
|
||||
lastContactAt: current.rollups?.lastContactAt ?? null,
|
||||
contactHistoryCount: current.rollups?.contactHistoryCount ?? current.contactHistory.length,
|
||||
contactCount: current.rollups?.contactCount ?? current.contacts?.length ?? 0,
|
||||
attachmentCount,
|
||||
childCustomerCount: current.rollups?.childCustomerCount,
|
||||
},
|
||||
}
|
||||
: current
|
||||
)
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,11 @@ export function CrmFormPage({ entity, mode }: CrmFormPageProps) {
|
||||
currencyCode: record.currencyCode ?? "USD",
|
||||
taxExempt: record.taxExempt ?? false,
|
||||
creditHold: record.creditHold ?? false,
|
||||
lifecycleStage: record.lifecycleStage ?? "ACTIVE",
|
||||
preferredAccount: record.preferredAccount ?? false,
|
||||
strategicAccount: record.strategicAccount ?? false,
|
||||
requiresApproval: record.requiresApproval ?? false,
|
||||
blockedAccount: record.blockedAccount ?? false,
|
||||
notes: record.notes,
|
||||
});
|
||||
setStatus(`${config.singularLabel} record loaded.`);
|
||||
|
||||
22
client/src/modules/crm/CrmLifecycleBadge.tsx
Normal file
22
client/src/modules/crm/CrmLifecycleBadge.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { CrmLifecycleStage } from "@mrp/shared/dist/crm/types.js";
|
||||
|
||||
import { crmLifecyclePalette } from "./config";
|
||||
|
||||
interface CrmLifecycleBadgeProps {
|
||||
stage: CrmLifecycleStage;
|
||||
}
|
||||
|
||||
const labels: Record<CrmLifecycleStage, string> = {
|
||||
PROSPECT: "Prospect",
|
||||
ACTIVE: "Active",
|
||||
DORMANT: "Dormant",
|
||||
CHURNED: "Churned",
|
||||
};
|
||||
|
||||
export function CrmLifecycleBadge({ stage }: CrmLifecycleBadgeProps) {
|
||||
return (
|
||||
<span className={`inline-flex items-center rounded-full px-3 py-1 text-xs font-semibold uppercase tracking-[0.14em] ${crmLifecyclePalette[stage]}`}>
|
||||
{labels[stage]}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
import { permissions } from "@mrp/shared";
|
||||
import type { CrmRecordStatus, CrmRecordSummaryDto } from "@mrp/shared/dist/crm/types.js";
|
||||
import type { CrmLifecycleStage, CrmRecordStatus, CrmRecordSummaryDto } from "@mrp/shared/dist/crm/types.js";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import { useAuth } from "../../auth/AuthProvider";
|
||||
import { api, ApiError } from "../../lib/api";
|
||||
import { CrmLifecycleBadge } from "./CrmLifecycleBadge";
|
||||
import { CrmStatusBadge } from "./CrmStatusBadge";
|
||||
import { crmStatusFilters, type CrmEntity, crmConfigs } from "./config";
|
||||
import { crmLifecycleFilters, crmOperationalFilters, crmStatusFilters, type CrmEntity, crmConfigs } from "./config";
|
||||
|
||||
interface CrmListPageProps {
|
||||
entity: CrmEntity;
|
||||
@@ -19,6 +20,10 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [stateFilter, setStateFilter] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState<"ALL" | CrmRecordStatus>("ALL");
|
||||
const [lifecycleFilter, setLifecycleFilter] = useState<"ALL" | CrmLifecycleStage>("ALL");
|
||||
const [operationalFilter, setOperationalFilter] = useState<"ALL" | "PREFERRED" | "STRATEGIC" | "REQUIRES_APPROVAL" | "BLOCKED">(
|
||||
"ALL"
|
||||
);
|
||||
const [status, setStatus] = useState(`Loading ${config.collectionLabel.toLowerCase()}...`);
|
||||
|
||||
const canManage = user?.permissions.includes(permissions.crmWrite) ?? false;
|
||||
@@ -32,6 +37,8 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
q: searchTerm.trim() || undefined,
|
||||
state: stateFilter.trim() || undefined,
|
||||
status: statusFilter === "ALL" ? undefined : statusFilter,
|
||||
lifecycleStage: lifecycleFilter === "ALL" ? undefined : lifecycleFilter,
|
||||
flag: operationalFilter === "ALL" ? undefined : operationalFilter,
|
||||
};
|
||||
|
||||
const loadRecords = entity === "customer" ? api.getCustomers(token, filters) : api.getVendors(token, filters);
|
||||
@@ -45,7 +52,7 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
const message = error instanceof ApiError ? error.message : `Unable to load ${config.collectionLabel.toLowerCase()}.`;
|
||||
setStatus(message);
|
||||
});
|
||||
}, [config.collectionLabel, entity, searchTerm, stateFilter, statusFilter, token]);
|
||||
}, [config.collectionLabel, entity, lifecycleFilter, operationalFilter, searchTerm, stateFilter, statusFilter, token]);
|
||||
|
||||
return (
|
||||
<section className="rounded-[28px] border border-line/70 bg-surface/90 p-8 shadow-panel">
|
||||
@@ -66,7 +73,7 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
</Link>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="mt-6 grid gap-4 rounded-3xl border border-line/70 bg-page/60 p-4 lg:grid-cols-[1.4fr_0.8fr_0.8fr]">
|
||||
<div className="mt-6 grid gap-4 rounded-3xl border border-line/70 bg-page/60 p-4 xl:grid-cols-[1.35fr_0.8fr_0.8fr_0.9fr_0.9fr]">
|
||||
<label className="block">
|
||||
<span className="mb-2 block text-xs font-semibold uppercase tracking-[0.16em] text-muted">Search</span>
|
||||
<input
|
||||
@@ -90,6 +97,20 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="mb-2 block text-xs font-semibold uppercase tracking-[0.16em] text-muted">Lifecycle</span>
|
||||
<select
|
||||
value={lifecycleFilter}
|
||||
onChange={(event) => setLifecycleFilter(event.target.value as "ALL" | CrmLifecycleStage)}
|
||||
className="w-full rounded-2xl border border-line/70 bg-surface px-4 py-3 text-text outline-none transition focus:border-brand"
|
||||
>
|
||||
{crmLifecycleFilters.map((option) => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="mb-2 block text-xs font-semibold uppercase tracking-[0.16em] text-muted">State / Province</span>
|
||||
<input
|
||||
@@ -99,6 +120,22 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
className="w-full rounded-2xl border border-line/70 bg-surface px-4 py-3 text-text outline-none transition focus:border-brand"
|
||||
/>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="mb-2 block text-xs font-semibold uppercase tracking-[0.16em] text-muted">Operational</span>
|
||||
<select
|
||||
value={operationalFilter}
|
||||
onChange={(event) =>
|
||||
setOperationalFilter(event.target.value as "ALL" | "PREFERRED" | "STRATEGIC" | "REQUIRES_APPROVAL" | "BLOCKED")
|
||||
}
|
||||
className="w-full rounded-2xl border border-line/70 bg-surface px-4 py-3 text-text outline-none transition focus:border-brand"
|
||||
>
|
||||
{crmOperationalFilters.map((option) => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div className="mt-6 rounded-2xl border border-line/70 bg-page/60 px-4 py-3 text-sm text-muted">{status}</div>
|
||||
{records.length === 0 ? (
|
||||
@@ -112,9 +149,10 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
<tr>
|
||||
<th className="px-4 py-3">Name</th>
|
||||
<th className="px-4 py-3">Status</th>
|
||||
<th className="px-4 py-3">Email</th>
|
||||
<th className="px-4 py-3">Phone</th>
|
||||
<th className="px-4 py-3">Location</th>
|
||||
<th className="px-4 py-3">Lifecycle</th>
|
||||
<th className="px-4 py-3">Operational</th>
|
||||
<th className="px-4 py-3">Activity</th>
|
||||
<th className="px-4 py-3">Contact</th>
|
||||
<th className="px-4 py-3">Updated</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -135,10 +173,31 @@ export function CrmListPage({ entity }: CrmListPageProps) {
|
||||
<td className="px-4 py-3">
|
||||
<CrmStatusBadge status={record.status} />
|
||||
</td>
|
||||
<td className="px-4 py-3 text-muted">{record.email}</td>
|
||||
<td className="px-4 py-3 text-muted">{record.phone}</td>
|
||||
<td className="px-4 py-3 text-muted">
|
||||
{record.city}, {record.state}, {record.country}
|
||||
{record.lifecycleStage ? <CrmLifecycleBadge stage={record.lifecycleStage} /> : null}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-xs text-muted">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{record.preferredAccount ? <span className="rounded-full border border-line/70 px-2 py-1">Preferred</span> : null}
|
||||
{record.strategicAccount ? <span className="rounded-full border border-line/70 px-2 py-1">Strategic</span> : null}
|
||||
{record.requiresApproval ? <span className="rounded-full border border-line/70 px-2 py-1">Approval</span> : null}
|
||||
{record.blockedAccount ? <span className="rounded-full border border-rose-400/40 px-2 py-1 text-rose-600 dark:text-rose-300">Blocked</span> : null}
|
||||
{!record.preferredAccount && !record.strategicAccount && !record.requiresApproval && !record.blockedAccount ? (
|
||||
<span>Standard</span>
|
||||
) : null}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-xs text-muted">
|
||||
<div>{record.rollups?.contactHistoryCount ?? 0} timeline entries</div>
|
||||
<div>{record.rollups?.attachmentCount ?? 0} attachments</div>
|
||||
{entity === "customer" ? <div>{record.rollups?.childCustomerCount ?? 0} child accounts</div> : null}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-muted">
|
||||
<div>{record.email}</div>
|
||||
<div className="mt-1 text-xs">
|
||||
{record.city}, {record.state}, {record.country}
|
||||
</div>
|
||||
<div className="mt-1 text-xs">{record.phone}</div>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-muted">{new Date(record.updatedAt).toLocaleDateString()}</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { CrmCustomerHierarchyOptionDto, CrmRecordInput } from "@mrp/shared/dist/crm/types.js";
|
||||
|
||||
import { crmStatusOptions } from "./config";
|
||||
import { crmLifecycleOptions, crmStatusOptions } from "./config";
|
||||
import type { CrmEntity } from "./config";
|
||||
|
||||
const fields: Array<{
|
||||
@@ -43,6 +43,20 @@ export function CrmRecordForm({ entity, form, hierarchyOptions = [], onChange }:
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="mb-2 block text-sm font-semibold text-text">Lifecycle stage</span>
|
||||
<select
|
||||
value={form.lifecycleStage ?? "ACTIVE"}
|
||||
onChange={(event) => onChange("lifecycleStage", event.target.value as CrmRecordInput["lifecycleStage"])}
|
||||
className="w-full rounded-2xl border border-line/70 bg-page px-4 py-3 text-text outline-none transition focus:border-brand"
|
||||
>
|
||||
{crmLifecycleOptions.map((option) => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{entity === "customer" ? (
|
||||
<div className="grid gap-4 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)_minmax(0,1fr)]">
|
||||
<label className="block">
|
||||
@@ -124,6 +138,40 @@ export function CrmRecordForm({ entity, form, hierarchyOptions = [], onChange }:
|
||||
<span className="text-sm font-semibold text-text">Credit hold</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="grid gap-4 xl:grid-cols-4">
|
||||
<label className="flex items-center gap-3 rounded-2xl border border-line/70 bg-page px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.preferredAccount ?? false}
|
||||
onChange={(event) => onChange("preferredAccount", event.target.checked)}
|
||||
/>
|
||||
<span className="text-sm font-semibold text-text">Preferred account</span>
|
||||
</label>
|
||||
<label className="flex items-center gap-3 rounded-2xl border border-line/70 bg-page px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.strategicAccount ?? false}
|
||||
onChange={(event) => onChange("strategicAccount", event.target.checked)}
|
||||
/>
|
||||
<span className="text-sm font-semibold text-text">Strategic account</span>
|
||||
</label>
|
||||
<label className="flex items-center gap-3 rounded-2xl border border-line/70 bg-page px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.requiresApproval ?? false}
|
||||
onChange={(event) => onChange("requiresApproval", event.target.checked)}
|
||||
/>
|
||||
<span className="text-sm font-semibold text-text">Requires approval</span>
|
||||
</label>
|
||||
<label className="flex items-center gap-3 rounded-2xl border border-line/70 bg-page px-4 py-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.blockedAccount ?? false}
|
||||
onChange={(event) => onChange("blockedAccount", event.target.checked)}
|
||||
/>
|
||||
<span className="text-sm font-semibold text-text">Blocked account</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="grid gap-4 xl:grid-cols-2 2xl:grid-cols-3">
|
||||
{fields.map((field) => (
|
||||
<label key={String(field.key)} className="block">
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import {
|
||||
crmContactRoles,
|
||||
crmContactEntryTypes,
|
||||
crmLifecycleStages,
|
||||
crmRecordStatuses,
|
||||
type CrmContactInput,
|
||||
type CrmContactRole,
|
||||
type CrmContactEntryInput,
|
||||
type CrmContactEntryType,
|
||||
type CrmLifecycleStage,
|
||||
type CrmRecordInput,
|
||||
type CrmRecordStatus,
|
||||
} from "@mrp/shared/dist/crm/types.js";
|
||||
@@ -59,6 +61,11 @@ export const emptyCrmRecordInput: CrmRecordInput = {
|
||||
currencyCode: "USD",
|
||||
taxExempt: false,
|
||||
creditHold: false,
|
||||
lifecycleStage: "ACTIVE",
|
||||
preferredAccount: false,
|
||||
strategicAccount: false,
|
||||
requiresApproval: false,
|
||||
blockedAccount: false,
|
||||
};
|
||||
|
||||
export const crmStatusOptions: Array<{ value: CrmRecordStatus; label: string }> = [
|
||||
@@ -73,6 +80,29 @@ export const crmStatusFilters: Array<{ value: "ALL" | CrmRecordStatus; label: st
|
||||
...crmStatusOptions,
|
||||
];
|
||||
|
||||
export const crmLifecycleOptions: Array<{ value: CrmLifecycleStage; label: string }> = [
|
||||
{ value: "PROSPECT", label: "Prospect" },
|
||||
{ value: "ACTIVE", label: "Active" },
|
||||
{ value: "DORMANT", label: "Dormant" },
|
||||
{ value: "CHURNED", label: "Churned" },
|
||||
];
|
||||
|
||||
export const crmLifecycleFilters: Array<{ value: "ALL" | CrmLifecycleStage; label: string }> = [
|
||||
{ value: "ALL", label: "All lifecycle stages" },
|
||||
...crmLifecycleOptions,
|
||||
];
|
||||
|
||||
export const crmOperationalFilters: Array<{
|
||||
value: "ALL" | "PREFERRED" | "STRATEGIC" | "REQUIRES_APPROVAL" | "BLOCKED";
|
||||
label: string;
|
||||
}> = [
|
||||
{ value: "ALL", label: "All accounts" },
|
||||
{ value: "PREFERRED", label: "Preferred only" },
|
||||
{ value: "STRATEGIC", label: "Strategic only" },
|
||||
{ value: "REQUIRES_APPROVAL", label: "Requires approval" },
|
||||
{ value: "BLOCKED", label: "Blocked only" },
|
||||
];
|
||||
|
||||
export const crmStatusPalette: Record<CrmRecordStatus, string> = {
|
||||
LEAD: "border border-sky-400/30 bg-sky-500/12 text-sky-700 dark:text-sky-300",
|
||||
ACTIVE: "border border-emerald-400/30 bg-emerald-500/12 text-emerald-700 dark:text-emerald-300",
|
||||
@@ -80,6 +110,13 @@ export const crmStatusPalette: Record<CrmRecordStatus, string> = {
|
||||
INACTIVE: "border border-slate-400/30 bg-slate-500/12 text-slate-700 dark:text-slate-300",
|
||||
};
|
||||
|
||||
export const crmLifecyclePalette: Record<CrmLifecycleStage, string> = {
|
||||
PROSPECT: "border border-sky-400/30 bg-sky-500/12 text-sky-700 dark:text-sky-300",
|
||||
ACTIVE: "border border-emerald-400/30 bg-emerald-500/12 text-emerald-700 dark:text-emerald-300",
|
||||
DORMANT: "border border-amber-400/30 bg-amber-500/12 text-amber-700 dark:text-amber-300",
|
||||
CHURNED: "border border-rose-400/30 bg-rose-500/12 text-rose-700 dark:text-rose-300",
|
||||
};
|
||||
|
||||
export const emptyCrmContactEntryInput: CrmContactEntryInput = {
|
||||
type: "NOTE",
|
||||
summary: "",
|
||||
@@ -119,4 +156,4 @@ export const crmContactRoleOptions: Array<{ value: CrmContactRole; label: string
|
||||
{ value: "OTHER", label: "Other" },
|
||||
];
|
||||
|
||||
export { crmContactEntryTypes, crmContactRoles, crmRecordStatuses };
|
||||
export { crmContactEntryTypes, crmContactRoles, crmLifecycleStages, crmRecordStatuses };
|
||||
|
||||
Reference in New Issue
Block a user