/* © 2026 K2B NETWORK SOLUTIONS LLC. All rights reserved.
Proprietary and confidential. Unauthorized copying, distribution, or use of
this file, via any medium, is strictly prohibited. Original work product. */
/* eslint-disable */
// JBREWS DMS — Deal e-sign (vehicle purchase documents).
// • DealEsignModal — F&I sends a sign request; BOTH mobile AND email are
// required before the request can go out. Shows a copyable link.
// • DealSignScreen — customer signing page (?dealsign=TOKEN): reviews the
// purchase summary, agrees to the purchase terms, signs (draw or type).
// Signing lands the signature on the deal AND the printed Buyer's Order.
// Reuses RoSignaturePad from RoSign.jsx. Real SMS/email needs a provider;
// the send is simulated with a working link.
const dsMoney = (n) => "$" + (Number(n) || 0).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
// Build the full document packet for a deal — everything the customer signs.
// LEASE (B-03): the lease agreement / worksheet / disclosure and the GMF
// leased-vehicle odometer statement go in; the Retail Installment Contract
// stays OUT. New/Used comes from deal.type (set by the desk / postDeal — B-02),
// with the unit's inventory type as the fallback: used → Buyer's Guide (AS-IS).
const dealSignDocs = (deal) => {
const docs = ["Vehicle Buyer's Order", "Odometer Disclosure", "Privacy Notice"];
const isLease = /lease/i.test(String(deal.dealType || deal.mode || ""));
let type = String(deal.type || "");
if (!type && deal.stock && window.DMS && window.DMS._unit) {
const u = window.DMS._unit(deal.stock);
type = u ? (window.DMS._dealTypeOfUnit ? window.DMS._dealTypeOfUnit(u) : String(u.type || "")) : "";
}
if (isLease) {
if (deal.lender) docs.push("Credit Application");
docs.push("Lease Agreement");
docs.push("Lease Worksheet / Lease Disclosure");
docs.push("Leased Vehicle Odometer Disclosure Statement (GMF)");
} else if (deal.lender) { docs.push("Credit Application"); docs.push("Retail Installment Contract"); }
if (/used/i.test(type)) docs.push("Buyer's Guide (AS-IS)");
if ((+deal.vscSale || 0) > 0) docs.push("Service Contract (VSC)");
if ((+deal.gapSale || 0) > 0) docs.push("GAP Waiver Agreement");
if ((+deal.tradeAllow || 0) > 0 || (+deal.tradePayoff || 0) > 0) docs.push("Trade-In Title / Power of Attorney");
return docs;
};
const DEAL_PURCHASE_TERMS =
"The purchaser agrees to purchase the vehicle described herein under the terms " +
"set forth on the Buyer's Order, including any addenda. Purchaser certifies the " +
"information provided is true and complete, acknowledges receipt of all required " +
"disclosures (including the federal Buyer's Guide on used vehicles and the " +
"privacy notice), and understands this order is not binding until accepted by an " +
"authorized dealership manager and, where applicable, financing is approved. " +
"By signing electronically, purchaser agrees an electronic signature has the " +
"same force and effect as a handwritten signature.";
// ── F&I send modal ──────────────────────────────────────────────────────────
const DealEsignModal = ({ deal, act, onClose }) => {
const [phone, setPhone] = React.useState(deal.phone || "");
const [email, setEmail] = React.useState(deal.email || "");
const [sent, setSent] = React.useState(deal.signRequest && deal.signRequest.status === "sent" ? deal.signRequest : null);
const link = sent ? (location.origin + location.pathname + "?dealsign=" + sent.token + ((window.K2BStore && window.K2BStore.pageId()) ? "&s=" + window.K2BStore.pageId() : "")) : ""; // RC35 (brd): the link names its store
const phoneOk = phone.replace(/[^0-9]/g, "").length >= 10;
const emailOk = /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email.trim());
const send = () => {
const r = DMS.requestDealSignature(deal.id, { phone, email });
act(r);
if (r.ok) setSent({ token: r.token, phone, email, status: "sent" });
};
const copy = () => { try { navigator.clipboard.writeText(link); window.k2bToast && window.k2bToast("Link copied.", "ok"); } catch (e) {} };
return (
Close {!sent && Send Request }>}>
{!sent ? (
<>
Send {deal.buyer} a secure link to review and sign the purchase documents for {deal.id} .
For vehicle purchases, both a mobile number and an email are required — the customer gets the link by text and email.
📱 Mobile number · required
setPhone(e.target.value)} placeholder="(573) 555-0134"
style={{ padding: "8px 10px", border: "1px solid " + (phone && !phoneOk ? "#B23A2E" : "#C8CCD2"), borderRadius: 4, fontSize: 13 }} />
✉ Email · required
setEmail(e.target.value)} placeholder="customer@email.com"
style={{ padding: "8px 10px", border: "1px solid " + (email && !emailOk ? "#B23A2E" : "#C8CCD2"), borderRadius: 4, fontSize: 13 }} />
{(!phoneOk || !emailOk) && ⚠ Both a valid mobile number and email are required before the request can be sent.
}
Live SMS/email delivery is wired through your messaging provider in production. In this build the link is generated for you to open the customer's signing screen.
>
) : (
<>
✓ Sign request sent by text to {sent.phone} and by email to {sent.email}.
Signing link
Copy
window.open(link, "_blank")}>Open Customer Signing Screen ↗
When the customer signs, the signature lands on the deal and prints on the Buyer's Order.
>
)}
);
};
// ── Customer signing screen (?dealsign=TOKEN) ──────────────────────────────
const DealSignScreen = ({ token }) => {
const [, force] = React.useReducer(n => n + 1, 0);
React.useEffect(() => (window.DMS && DMS.subscribe) ? DMS.subscribe(force) : undefined, []);
const deal = window.DMS ? DMS.findDealBySignToken(token) : null;
const [sig, setSig] = React.useState("");
const [name, setName] = React.useState(deal ? deal.buyer : "");
const [agree, setAgree] = React.useState(false);
const allDocs = React.useMemo(() => deal ? dealSignDocs(deal) : [], [deal && deal.id]);
const [checked, setChecked] = React.useState(null); // null = all
const docsChecked = checked || allDocs;
const toggleDoc = (doc) => setChecked(cur => { const c = cur || allDocs.slice(); return c.includes(doc) ? c.filter(x => x !== doc) : [...c, doc]; });
if (!deal) return (
🔗
This signing link is invalid or has expired.
);
const signed = deal.esign;
const lease = /lease/i.test(String(deal.dealType || deal.mode || ""));
const rows = [
["Vehicle", deal.vehicle || "—"],
[lease ? "Agreed value (lease)" : "Sale price", dsMoney(deal.salePrice)],
["Trade allowance", deal.tradeAllow ? dsMoney(deal.tradeAllow) : "—"],
["Trade payoff", deal.tradePayoff ? dsMoney(deal.tradePayoff) : "—"],
["Rebates", deal.rebate ? dsMoney(deal.rebate) : "—"],
lease ? ["Due at signing", deal.dueAtSigning != null ? dsMoney(deal.dueAtSigning) : (deal.cashDown ? dsMoney(deal.cashDown) : "—")]
: ["Cash down", deal.cashDown ? dsMoney(deal.cashDown) : "—"],
...(lease ? [["Monthly payment (incl. tax)", deal.payment ? dsMoney(deal.payment) + (deal.term ? " × " + deal.term : "") : "—"]] : []),
[lease ? "Lessor" : "Lender", (lease && deal.lienholder && deal.lienholder.name) ? deal.lienholder.name : (deal.lender || "Cash deal")],
];
const submit = () => {
if (!sig) { window.k2bToast && window.k2bToast("Please sign to continue.", "warn"); return; }
if (!agree) { window.k2bToast && window.k2bToast("Please agree to the purchase terms.", "warn"); return; }
if (!docsChecked.length) { window.k2bToast && window.k2bToast("Select at least one document to sign.", "warn"); return; }
DMS.submitDealSignature(token, { signature: sig, name: name || deal.buyer, docs: docsChecked });
force();
};
return (
{window.K2BStoreBand ?
: null}
{window.K2BStoreLogo ?
: null}
{(window.K2BStore ? window.K2BStore.branding().dba : "")} — Sales
Vehicle Purchase Documents · {deal.id}
{signed ? (
✅
Documents Signed
Thank you, {signed.signedName}. Your F&I manager has been notified — your signed documents are on file.
{(signed.docs || []).map((d, i) => (
✓ {d}
))}
Signed {new Date(signed.at).toLocaleString()}
) : (
<>
{deal.buyer}
Review your purchase
{rows.map(([l, v], i) => (
{l}
{v}
))}
Final figures, taxes and fees appear on your Buyer's Order and finance contract.
Documents in this signing packet
Your signature below applies to each checked document.
{allDocs.map(doc => (
toggleDoc(doc)} style={{ width: 17, height: 17 }} />
{doc}
))}
{DEAL_PURCHASE_TERMS}
setAgree(e.target.checked)} style={{ width: 18, height: 18, marginTop: 1 }} />
I have read and agree to the purchase terms, and I intend my electronic signature to sign each checked document above.
Full legal name
setName(e.target.value)} style={{ width: "100%", boxSizing: "border-box", padding: "8px 10px", border: "1px solid #C8CCD2", borderRadius: 4, fontSize: 14, marginTop: 3, marginBottom: 12 }} />
Sign {docsChecked.length} Document{docsChecked.length !== 1 ? "s" : ""}
>
)}
);
};
Object.assign(window, { DealEsignModal, DealSignScreen, DEAL_PURCHASE_TERMS });