This commit is contained in:
2026-03-14 18:46:06 -05:00
parent f1fd2ed979
commit c0cc546e33
15 changed files with 979 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
import type { CrmRecordInput } from "@mrp/shared/dist/crm/types.js";
import type { CrmCustomerHierarchyOptionDto, CrmRecordInput } from "@mrp/shared/dist/crm/types.js";
import { useEffect, useState } from "react";
import { Link, useNavigate, useParams } from "react-router-dom";
@@ -19,11 +19,23 @@ export function CrmFormPage({ entity, mode }: CrmFormPageProps) {
const recordId = entity === "customer" ? customerId : vendorId;
const config = crmConfigs[entity];
const [form, setForm] = useState<CrmRecordInput>(emptyCrmRecordInput);
const [hierarchyOptions, setHierarchyOptions] = useState<CrmCustomerHierarchyOptionDto[]>([]);
const [status, setStatus] = useState(
mode === "create" ? `Create a new ${config.singularLabel.toLowerCase()} record.` : `Loading ${config.singularLabel.toLowerCase()}...`
);
const [isSaving, setIsSaving] = useState(false);
useEffect(() => {
if (entity !== "customer" || !token) {
return;
}
api
.getCustomerHierarchyOptions(token, mode === "edit" ? recordId : undefined)
.then(setHierarchyOptions)
.catch(() => setHierarchyOptions([]));
}, [entity, mode, recordId, token]);
useEffect(() => {
if (mode !== "edit" || !token || !recordId) {
return;
@@ -44,6 +56,13 @@ export function CrmFormPage({ entity, mode }: CrmFormPageProps) {
postalCode: record.postalCode,
country: record.country,
status: record.status,
isReseller: record.isReseller ?? false,
resellerDiscountPercent: record.resellerDiscountPercent ?? 0,
parentCustomerId: record.parentCustomerId ?? null,
paymentTerms: record.paymentTerms ?? "Net 30",
currencyCode: record.currencyCode ?? "USD",
taxExempt: record.taxExempt ?? false,
creditHold: record.creditHold ?? false,
notes: record.notes,
});
setStatus(`${config.singularLabel} record loaded.`);
@@ -107,7 +126,7 @@ export function CrmFormPage({ entity, mode }: CrmFormPageProps) {
</div>
</section>
<section className="space-y-5 rounded-[28px] border border-line/70 bg-surface/90 p-6 shadow-panel 2xl:p-7">
<CrmRecordForm form={form} onChange={updateField} />
<CrmRecordForm entity={entity} form={form} hierarchyOptions={hierarchyOptions} onChange={updateField} />
<div className="flex flex-col gap-3 rounded-2xl border border-line/70 bg-page/70 px-4 py-4 sm:flex-row sm:items-center sm:justify-between">
<span className="min-w-0 text-sm text-muted">{status}</span>
<button