mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 00:23:13 +00:00
- Vendor CRUD: list page with search, create/edit form with trade specialty chips - Vendor routes, sidebar nav item with truck icon - vendorApi in services/api.js - Dispatch button on WO view page opens DispatchModal - DispatchModal: vendor multi-select filtered by trade, NTE field, description - Dispatches CollapsibleSection with PO table on WO view page - fetchVendorsDropdown and dispatchToVendor API functions - dispatches included in getWorkOrderById response mapping
642 lines
23 KiB
JavaScript
642 lines
23 KiB
JavaScript
import React, { useState, useEffect, useRef } from "react";
|
|
import ReactDOM from "react-dom";
|
|
import { useParams, useNavigate } from "react-router";
|
|
import { toast } from "react-toastify";
|
|
import { getWorkOrderById, addComment, changeWorkOrderStatus, fetchUsers, changeWorkOrderAssignment, fetchVendorsDropdown, dispatchToVendor } from "../api";
|
|
import "./WorkOrderViewPage.css";
|
|
|
|
function AssignDropdown({ value, onAssign }) {
|
|
const [open, setOpen] = useState(false);
|
|
const [users, setUsers] = useState([]);
|
|
const [loaded, setLoaded] = useState(false);
|
|
const btnRef = useRef(null);
|
|
const menuRef = useRef(null);
|
|
const [menuPos, setMenuPos] = useState({ top: 0, left: 0 });
|
|
|
|
useEffect(() => {
|
|
const handleClick = (e) => {
|
|
if (btnRef.current?.contains(e.target)) return;
|
|
if (menuRef.current?.contains(e.target)) return;
|
|
setOpen(false);
|
|
};
|
|
document.addEventListener("mousedown", handleClick);
|
|
return () => document.removeEventListener("mousedown", handleClick);
|
|
}, []);
|
|
|
|
const handleOpen = async () => {
|
|
if (!loaded) {
|
|
try {
|
|
const data = await fetchUsers();
|
|
setUsers(data);
|
|
setLoaded(true);
|
|
} catch { return; }
|
|
}
|
|
if (btnRef.current) {
|
|
const rect = btnRef.current.getBoundingClientRect();
|
|
setMenuPos({ top: rect.bottom + 4, left: rect.left });
|
|
}
|
|
setOpen(!open);
|
|
};
|
|
|
|
const handleSelect = async (userId, userName) => {
|
|
setOpen(false);
|
|
onAssign(userId, userName);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<button ref={btnRef} className="woAssignBtn" onClick={handleOpen}>
|
|
{value || "Unassigned"} <span className="woStatusCaret">▾</span>
|
|
</button>
|
|
{open && ReactDOM.createPortal(
|
|
<div ref={menuRef} className="woAssignMenu" style={{ top: menuPos.top, left: menuPos.left }}>
|
|
<button className={`woAssignOption ${!value ? "active" : ""}`} onClick={() => handleSelect("", "")}>
|
|
Unassigned
|
|
</button>
|
|
{users.map((u) => (
|
|
<button key={u.id} className={`woAssignOption ${value === u.name ? "active" : ""}`} onClick={() => handleSelect(u.id, u.name)}>
|
|
{u.name}
|
|
</button>
|
|
))}
|
|
</div>,
|
|
document.body
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
function CollapsibleSection({ title, defaultOpen = false, children }) {
|
|
const [open, setOpen] = useState(defaultOpen);
|
|
return (
|
|
<div className="woViewSection">
|
|
<h4 className="woSectionToggle" onClick={() => setOpen(!open)}>
|
|
<span className={`woSectionArrow ${open ? "open" : ""}`}>▸</span>
|
|
{title}
|
|
</h4>
|
|
{open && children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function formatDateTime(value) {
|
|
const d = new Date(value.endsWith("Z") ? value : value + "Z");
|
|
if (isNaN(d)) return value;
|
|
const date = d.toLocaleDateString("en-CA");
|
|
const time = d.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit", hour12: false });
|
|
const tz = d.toLocaleTimeString(undefined, { timeZoneName: "short" }).split(" ").pop();
|
|
return `${date} ${time} ${tz}`;
|
|
}
|
|
|
|
function CommentTimeline({ comments }) {
|
|
const bottomRef = useRef(null);
|
|
const sorted = [...(comments || [])].sort((a, b) =>
|
|
new Date(a.createdDate) - new Date(b.createdDate)
|
|
);
|
|
|
|
useEffect(() => {
|
|
bottomRef.current?.scrollIntoView();
|
|
}, [sorted.length]);
|
|
|
|
if (!sorted.length) {
|
|
return <div className="woTabScroll"><p className="woNoComments">No comments yet.</p></div>;
|
|
}
|
|
|
|
return (
|
|
<div className="woTabScroll">
|
|
<div className="woTimeline">
|
|
{sorted.map((c) => (
|
|
<div key={c.id} className="woTimelineItem">
|
|
<div className="woTimelineHeader">
|
|
<span className="woTimelineAuthor">{c.userName || c.commenter || "System"}</span>
|
|
<span className="woTimelineDate">
|
|
{c.createdDate ? formatDateTime(c.createdDate) : ""}
|
|
</span>
|
|
</div>
|
|
<div className="woTimelineBody">{c.commenttext}</div>
|
|
</div>
|
|
))}
|
|
<div ref={bottomRef} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function AuditTimeline({ entries }) {
|
|
const bottomRef = useRef(null);
|
|
const sorted = [...(entries || [])].sort((a, b) =>
|
|
new Date(a.createdAt) - new Date(b.createdAt)
|
|
);
|
|
|
|
useEffect(() => {
|
|
bottomRef.current?.scrollIntoView();
|
|
}, [sorted.length]);
|
|
|
|
if (!sorted.length) {
|
|
return <div className="woTabScroll"><p className="woNoComments">No changes recorded.</p></div>;
|
|
}
|
|
|
|
return (
|
|
<div className="woTabScroll">
|
|
<div className="woTimeline">
|
|
{sorted.map((e) => (
|
|
<div key={e.id} className="woTimelineItem woAuditItem">
|
|
<div className="woTimelineHeader">
|
|
<span className="woTimelineAuthor">{e.userName || "System"}</span>
|
|
<span className="woTimelineDate">
|
|
{e.createdAt ? formatDateTime(e.createdAt) : ""}
|
|
</span>
|
|
</div>
|
|
<div className="woTimelineBody">
|
|
<span className="woAuditField">{e.fieldName}</span>
|
|
{e.oldValue && <span className="woAuditOld">{e.oldValue}</span>}
|
|
<span className="woAuditArrow">→</span>
|
|
<span className="woAuditNew">{e.newValue}</span>
|
|
</div>
|
|
</div>
|
|
))}
|
|
<div ref={bottomRef} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function DispatchModal({ wo, onClose, onDispatched }) {
|
|
const [vendors, setVendors] = useState([]);
|
|
const [selectedIds, setSelectedIds] = useState([]);
|
|
const [nteAmount, setNteAmount] = useState(wo.vendorNTE || "");
|
|
const [description, setDescription] = useState(wo.description || "");
|
|
const [sending, setSending] = useState(false);
|
|
const [loaded, setLoaded] = useState(false);
|
|
|
|
useEffect(() => {
|
|
fetchVendorsDropdown(wo.trade).then((data) => {
|
|
setVendors(data);
|
|
setLoaded(true);
|
|
}).catch(() => setLoaded(true));
|
|
}, [wo.trade]);
|
|
|
|
const toggleVendor = (id) => {
|
|
setSelectedIds(prev => prev.includes(id) ? prev.filter(v => v !== id) : [...prev, id]);
|
|
};
|
|
|
|
const handleSubmit = async () => {
|
|
if (selectedIds.length === 0) { toast.error("Select at least one vendor"); return; }
|
|
setSending(true);
|
|
try {
|
|
await dispatchToVendor(wo.id, {
|
|
VendorIds: selectedIds,
|
|
NTEAmount: nteAmount ? parseFloat(nteAmount) : null,
|
|
Description: description,
|
|
});
|
|
toast.success(`Dispatched to ${selectedIds.length} vendor(s)`);
|
|
onDispatched();
|
|
onClose();
|
|
} catch {
|
|
toast.error("Failed to dispatch");
|
|
} finally {
|
|
setSending(false);
|
|
}
|
|
};
|
|
|
|
return ReactDOM.createPortal(
|
|
<div className="woDispatchOverlay" onClick={onClose}>
|
|
<div className="woDispatchModal" onClick={(e) => e.stopPropagation()}>
|
|
<div className="woDispatchHeader">
|
|
<h3>Dispatch Work Order {wo.internalWONumber}</h3>
|
|
<button className="woDispatchClose" onClick={onClose}>×</button>
|
|
</div>
|
|
<div className="woDispatchBody">
|
|
<div className="woDispatchField">
|
|
<label>Select Vendors</label>
|
|
{!loaded ? <div className="woDispatchLoading">Loading vendors...</div> : vendors.length === 0 ? <div className="woDispatchLoading">No vendors found</div> : (
|
|
<div className="woDispatchVendorList">
|
|
{vendors.map((v) => (
|
|
<label key={v.id} className={`woDispatchVendorItem ${selectedIds.includes(v.id) ? "selected" : ""}`}>
|
|
<input type="checkbox" checked={selectedIds.includes(v.id)} onChange={() => toggleVendor(v.id)} />
|
|
<div>
|
|
<span className="woDispatchVendorName">{v.companyName}</span>
|
|
{v.tradeSpecialties && <span className="woDispatchVendorTrades">{v.tradeSpecialties}</span>}
|
|
</div>
|
|
</label>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="woDispatchField">
|
|
<label>NTE Amount</label>
|
|
<input type="number" className="form-control" value={nteAmount} onChange={(e) => setNteAmount(e.target.value)} placeholder="0.00" step="0.01" min="0" />
|
|
</div>
|
|
<div className="woDispatchField">
|
|
<label>Description</label>
|
|
<textarea className="form-control" value={description} onChange={(e) => setDescription(e.target.value)} rows="4" style={{ resize: "none" }} />
|
|
</div>
|
|
</div>
|
|
<div className="woDispatchFooter">
|
|
<button className="btn btn-default" onClick={onClose} disabled={sending}>Cancel</button>
|
|
<button className="btn btn-primary" onClick={handleSubmit} disabled={sending || selectedIds.length === 0}>
|
|
{sending ? "Dispatching..." : `Dispatch to ${selectedIds.length} Vendor(s)`}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>,
|
|
document.body
|
|
);
|
|
}
|
|
|
|
function CommentInput({ workOrderId, commentType, onCommentAdded }) {
|
|
const [text, setText] = useState("");
|
|
const [sending, setSending] = useState(false);
|
|
|
|
const handleSubmit = async (e) => {
|
|
e.preventDefault();
|
|
if (!text.trim()) return;
|
|
setSending(true);
|
|
try {
|
|
const newComment = await addComment(workOrderId, text.trim(), commentType);
|
|
setText("");
|
|
if (onCommentAdded) onCommentAdded(newComment);
|
|
} catch (err) {
|
|
toast.error("Failed to add comment");
|
|
} finally {
|
|
setSending(false);
|
|
}
|
|
};
|
|
|
|
const handleKeyDown = (e) => {
|
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
e.preventDefault();
|
|
handleSubmit(e);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<form className="woCommentInput" onSubmit={handleSubmit}>
|
|
<textarea
|
|
className="woCommentTextarea"
|
|
value={text}
|
|
onChange={(e) => setText(e.target.value)}
|
|
onKeyDown={handleKeyDown}
|
|
placeholder="Type a comment... (Enter to send, Shift+Enter for new line)"
|
|
rows={2}
|
|
disabled={sending}
|
|
/>
|
|
<button className="btn btn-primary woCommentSend" type="submit" disabled={sending || !text.trim()}>
|
|
{sending ? "Sending..." : "Send"}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
const STATUS_OPTIONS = ["Open", "In Progress", "On Hold", "Done", "Cancelled"];
|
|
|
|
function StatusDropdown({ status, onStatusChange }) {
|
|
const [open, setOpen] = useState(false);
|
|
const btnRef = useRef(null);
|
|
const menuRef = useRef(null);
|
|
const [menuPos, setMenuPos] = useState({ top: 0, left: 0 });
|
|
const statusClass = (status || "").toLowerCase().replace(/\s+/g, "-");
|
|
|
|
useEffect(() => {
|
|
const handleClick = (e) => {
|
|
if (btnRef.current?.contains(e.target)) return;
|
|
if (menuRef.current?.contains(e.target)) return;
|
|
setOpen(false);
|
|
};
|
|
document.addEventListener("mousedown", handleClick);
|
|
return () => document.removeEventListener("mousedown", handleClick);
|
|
}, []);
|
|
|
|
const handleOpen = () => {
|
|
if (btnRef.current) {
|
|
const rect = btnRef.current.getBoundingClientRect();
|
|
setMenuPos({ top: rect.bottom + 4, left: rect.left });
|
|
}
|
|
setOpen(!open);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
ref={btnRef}
|
|
className={`woStatusBadge ${statusClass} woStatusClickable`}
|
|
onClick={handleOpen}
|
|
>
|
|
{status} <span className="woStatusCaret">▾</span>
|
|
</button>
|
|
{open && ReactDOM.createPortal(
|
|
<div
|
|
ref={menuRef}
|
|
className="woStatusMenu"
|
|
style={{ top: menuPos.top, left: menuPos.left }}
|
|
>
|
|
{STATUS_OPTIONS.map((s) => (
|
|
<button
|
|
key={s}
|
|
className={`woStatusOption ${s === status ? "active" : ""}`}
|
|
onClick={() => { onStatusChange(s); setOpen(false); }}
|
|
>
|
|
<span className={`woStatusDot ${s.toLowerCase().replace(/\s+/g, "-")}`} />
|
|
{s}
|
|
</button>
|
|
))}
|
|
</div>,
|
|
document.body
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default function WorkOrderViewPage() {
|
|
const { id } = useParams();
|
|
const navigate = useNavigate();
|
|
const [wo, setWo] = useState(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [activeTab, setActiveTab] = useState("customer");
|
|
const [statusUpdating, setStatusUpdating] = useState(false);
|
|
const [dispatchOpen, setDispatchOpen] = useState(false);
|
|
|
|
const handleStatusChange = async (newStatus) => {
|
|
if (newStatus === wo?.status) return;
|
|
setStatusUpdating(true);
|
|
try {
|
|
await changeWorkOrderStatus(id, newStatus);
|
|
const oldStatus = wo.status;
|
|
setWo((prev) => ({
|
|
...prev,
|
|
status: newStatus,
|
|
auditLog: [
|
|
{
|
|
id: Date.now(),
|
|
fieldName: "Status",
|
|
oldValue: oldStatus,
|
|
newValue: newStatus,
|
|
action: "status_change",
|
|
createdAt: new Date().toISOString(),
|
|
userName: "You",
|
|
},
|
|
...(prev.auditLog || []),
|
|
],
|
|
}));
|
|
toast.success(`Status changed to ${newStatus}`);
|
|
} catch (err) {
|
|
toast.error("Failed to update status");
|
|
} finally {
|
|
setStatusUpdating(false);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
const load = async () => {
|
|
try {
|
|
const data = await getWorkOrderById(id);
|
|
setWo(data);
|
|
} catch (err) {
|
|
toast.error("Failed to load work order");
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
load();
|
|
}, [id]);
|
|
|
|
const handleCommentAdded = (newComment) => {
|
|
setWo((prev) => ({
|
|
...prev,
|
|
comments: [
|
|
...prev.comments,
|
|
{
|
|
id: newComment.id,
|
|
createdDate: newComment.createdDate,
|
|
commenttext: newComment.commenttext,
|
|
commentType: newComment.commentType,
|
|
userName: newComment.userName,
|
|
commenter: null,
|
|
recordType: null,
|
|
},
|
|
],
|
|
}));
|
|
};
|
|
|
|
if (loading) return <div className="woViewPage"><div className="loading">Loading...</div></div>;
|
|
if (!wo) return <div className="woViewPage"><div className="loading">Work order not found.</div></div>;
|
|
|
|
const allComments = wo.comments || [];
|
|
const customerComments = allComments.filter((c) => c.commentType === "customer");
|
|
const vendorComments = allComments.filter((c) => c.commentType === "vendor");
|
|
const internalComments = allComments.filter((c) => c.commentType === "internal");
|
|
const auditLog = wo.auditLog || [];
|
|
|
|
const tabs = [
|
|
{ key: "customer", label: "Customer", count: customerComments.length },
|
|
{ key: "vendor", label: "Vendor", count: vendorComments.length },
|
|
{ key: "internal", label: "Internal", count: internalComments.length },
|
|
{ key: "audit", label: "Audit Log", count: auditLog.length },
|
|
];
|
|
|
|
const showInput = activeTab === "internal" || activeTab === "vendor";
|
|
|
|
return (
|
|
<div className="woViewPage">
|
|
<div className="panel panel-default panel-connected">
|
|
<div className="panel-body">
|
|
<ol className="breadcrumb breadcrumb-alt">
|
|
<li>
|
|
<a href="#" onClick={(e) => { e.preventDefault(); navigate("/workorders"); }}>
|
|
Work Orders
|
|
</a>
|
|
</li>
|
|
<li className="active">{wo.internalWONumber}</li>
|
|
</ol>
|
|
|
|
<div className="woViewHeader">
|
|
<div className="woViewTitle">
|
|
<h2>{wo.title}</h2>
|
|
<StatusDropdown status={wo.status} onStatusChange={handleStatusChange} />
|
|
</div>
|
|
<div className="woViewActions">
|
|
<button className="btn btn-success" onClick={() => setDispatchOpen(true)}>
|
|
Dispatch
|
|
</button>
|
|
<button className="btn btn-primary" onClick={() => navigate(`/workorders/edit/${id}`)}>
|
|
Edit
|
|
</button>
|
|
<button className="btn btn-default" onClick={() => navigate("/workorders")}>
|
|
Back to List
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="woViewGrid">
|
|
<div className="woViewSection">
|
|
<h4>Details</h4>
|
|
<div className="woFieldGrid">
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Internal WO</span>
|
|
<span className="woFieldValue">{wo.internalWONumber}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Customer WO</span>
|
|
<span className="woFieldValue">{wo.workOrderNumber || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Priority</span>
|
|
<span className="woFieldValue">{wo.priority || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Location</span>
|
|
<span className="woFieldValue">{wo.location || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Assigned To</span>
|
|
<span className="woFieldValue">
|
|
<AssignDropdown
|
|
value={wo.assignedTo}
|
|
onAssign={async (userId, userName) => {
|
|
try {
|
|
await changeWorkOrderAssignment(wo.id, userId);
|
|
setWo((prev) => ({ ...prev, assignedTo: userName }));
|
|
toast.success(`Assigned to ${userName || "Unassigned"}`);
|
|
} catch { toast.error("Failed to update assignment"); }
|
|
}}
|
|
/>
|
|
</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Source</span>
|
|
<span className="woFieldValue">{wo.source || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">TT</span>
|
|
<span className="woFieldValue">{wo.tt || "—"}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<CollapsibleSection title="Classification">
|
|
<div className="woFieldGrid">
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Problem</span>
|
|
<span className="woFieldValue">{wo.problem || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Trade</span>
|
|
<span className="woFieldValue">{wo.trade || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Sub-Trade</span>
|
|
<span className="woFieldValue">{wo.subTrade || "—"}</span>
|
|
</div>
|
|
</div>
|
|
</CollapsibleSection>
|
|
|
|
<CollapsibleSection title="Schedule">
|
|
<div className="woFieldGrid">
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Created</span>
|
|
<span className="woFieldValue">
|
|
{wo.createdDateFull ? formatDateTime(wo.createdDateFull) : "—"}
|
|
</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Due Date</span>
|
|
<span className="woFieldValue">{wo.dueDate || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Scheduled</span>
|
|
<span className="woFieldValue">{wo.scheduledDate || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Completed</span>
|
|
<span className="woFieldValue">{wo.completedDate || "—"}</span>
|
|
</div>
|
|
</div>
|
|
</CollapsibleSection>
|
|
|
|
<CollapsibleSection title="Financial">
|
|
<div className="woFieldGrid">
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Vendor NTE</span>
|
|
<span className="woFieldValue">{wo.vendorNTE ? `$${parseFloat(wo.vendorNTE).toFixed(2)}` : "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Customer PO</span>
|
|
<span className="woFieldValue">{wo.po || "—"}</span>
|
|
</div>
|
|
<div className="woField">
|
|
<span className="woFieldLabel">Customer NTE</span>
|
|
<span className="woFieldValue woFieldPlaceholder">Not connected</span>
|
|
</div>
|
|
</div>
|
|
</CollapsibleSection>
|
|
|
|
<CollapsibleSection title={`Dispatches (${(wo.dispatches || []).length})`}>
|
|
{wo.dispatches?.length ? (
|
|
<table className="woDispatchTable">
|
|
<thead>
|
|
<tr><th>PO #</th><th>Vendor</th><th>NTE</th><th>Status</th><th>Date</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
{wo.dispatches.map(d => (
|
|
<tr key={d.id}>
|
|
<td>{d.poNumber}</td>
|
|
<td>{d.vendorName}</td>
|
|
<td>{d.nteAmount != null ? `$${parseFloat(d.nteAmount).toFixed(2)}` : "—"}</td>
|
|
<td><span className={`woDispatchStatus ${(d.status || "").toLowerCase()}`}>{d.status}</span></td>
|
|
<td>{d.dispatchedAt ? formatDateTime(d.dispatchedAt) : "—"}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
) : (
|
|
<p className="woNoComments">No dispatches yet.</p>
|
|
)}
|
|
</CollapsibleSection>
|
|
|
|
<CollapsibleSection title="Description">
|
|
<p className="woDescription">{wo.description || "No description provided."}</p>
|
|
</CollapsibleSection>
|
|
|
|
<div className="woViewSection">
|
|
<h4>Activity</h4>
|
|
<div className="woCommentTabs">
|
|
{tabs.map((tab) => (
|
|
<button
|
|
key={tab.key}
|
|
className={`woCommentTab ${activeTab === tab.key ? "active" : ""}`}
|
|
onClick={() => setActiveTab(tab.key)}
|
|
>
|
|
{tab.label} ({tab.count})
|
|
</button>
|
|
))}
|
|
</div>
|
|
<div className="woTabContainer">
|
|
{activeTab === "customer" && <CommentTimeline comments={customerComments} />}
|
|
{activeTab === "vendor" && <CommentTimeline comments={vendorComments} />}
|
|
{activeTab === "internal" && <CommentTimeline comments={internalComments} />}
|
|
{activeTab === "audit" && <AuditTimeline entries={auditLog} />}
|
|
{showInput && (
|
|
<CommentInput
|
|
workOrderId={parseInt(id)}
|
|
commentType={activeTab}
|
|
onCommentAdded={handleCommentAdded}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{dispatchOpen && (
|
|
<DispatchModal
|
|
wo={wo}
|
|
onClose={() => setDispatchOpen(false)}
|
|
onDispatched={async () => {
|
|
const data = await getWorkOrderById(id);
|
|
setWo(data);
|
|
}}
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|