feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Cache advisors for a week / allow them to refresh said cache
This commit is contained in:
@@ -61,7 +61,7 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
const getAdvisorNumber = (a) => a?.advisorId;
|
||||
const getAdvisorLabel = (a) => `${a?.firstName} ${a?.lastName}`?.trim();
|
||||
|
||||
const fetchRrAdvisors = () => {
|
||||
const fetchRrAdvisors = (refresh = false) => {
|
||||
if (!wsssocket) return;
|
||||
setAdvLoading(true);
|
||||
|
||||
@@ -78,8 +78,8 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
|
||||
wsssocket.once("rr-get-advisors:result", onResult);
|
||||
|
||||
// Emit with the correct event name + parse the ack shape
|
||||
wsssocket.emit("rr-get-advisors", { departmentType: "B" }, (ack) => {
|
||||
// Emit with refresh flag: server will bypass/rebuild cache when true
|
||||
wsssocket.emit("rr-get-advisors", { departmentType: "B", refresh }, (ack) => {
|
||||
if (ack?.ok) {
|
||||
const list = ack.result ?? [];
|
||||
setAdvisors(Array.isArray(list) ? list : []);
|
||||
@@ -92,7 +92,7 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (dms === "rr") fetchRrAdvisors();
|
||||
if (dms === "rr") fetchRrAdvisors(false);
|
||||
}, [dms, bodyshop?.id]);
|
||||
|
||||
const handlePayerSelect = (value, index) => {
|
||||
@@ -217,7 +217,7 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
|
||||
{dms === "rr" && (
|
||||
<Form.Item label=" " colon={false}>
|
||||
<Button onClick={fetchRrAdvisors} icon={<ReloadOutlined />} loading={advLoading}>
|
||||
<Button onClick={() => fetchRrAdvisors(true)} icon={<ReloadOutlined />} loading={advLoading}>
|
||||
{t("general.actions.refresh")}
|
||||
</Button>
|
||||
</Form.Item>
|
||||
|
||||
Reference in New Issue
Block a user