Implemented the functionality to add a WL Action
This commit is contained in:
@@ -112,10 +112,39 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
const uncertain = products.error || (products.items || []).some(item => !String(item?.RevnId ?? "").trim())
|
||||
|| records.some(record => record?.status === "error" || record?.hasNext);
|
||||
const principal = authSessionState.principal;
|
||||
const owned = Boolean(principal) && actions.some(action => typeof action.owner === "string" && action.owner.trim() === principal);
|
||||
const owned = Boolean(principal?.trim()) && actions.some(action => typeof action.owner === "string"
|
||||
&& action.owner.trim().toLowerCase() === principal.trim().toLowerCase());
|
||||
const state = owned ? "matched" : pending ? "loading" : uncertain || !principal ? "error" : "missing";
|
||||
return { state, actions, records, principal, pending, uncertain };
|
||||
}
|
||||
async function applySavedAction(optyNumber, revnId, response, submittedAction = {}) {
|
||||
const products = productsContentState.opptyProductsByNumber.get(String(optyNumber));
|
||||
const id = String(revnId);
|
||||
if (!session.enabled || !allowsCrmActivities() || !idsFor(products).includes(id)) return false;
|
||||
const returned = Array.isArray(response) ? response : Array.isArray(response?.actions) ? response.actions : [response?.action || response];
|
||||
const saved = returned.filter(action => action && typeof action === "object" && action.id != null
|
||||
&& (action.revenueId == null || String(action.revenueId) === id));
|
||||
if (!saved.length) return false;
|
||||
const previous = session.records.get(id);
|
||||
const actions = [...(previous?.actions || [])];
|
||||
for (const action of saved) {
|
||||
// The POST can return a display name in owner, unlike the workload GET.
|
||||
const ownerEmail = typeof action.ownerEmail === "string" && action.ownerEmail.trim()
|
||||
? action.ownerEmail.trim() : submittedAction.ownerEmail || action.owner || "";
|
||||
const normalized = { ...action, ownerEmail, owner: ownerEmail };
|
||||
const index = actions.findIndex(item => String(item.id) === String(action.id));
|
||||
if (index === -1) actions.push(normalized);
|
||||
else actions[index] = { ...actions[index], ...normalized };
|
||||
}
|
||||
const record = { status: "ready", actions, hasNext: previous?.hasNext || false,
|
||||
completion: Promise.resolve(), resolveCompletion() {} };
|
||||
session.records.set(id, record);
|
||||
previous?.resolveCompletion?.();
|
||||
session.progress.delete(previous);
|
||||
queueProductsTableRender();
|
||||
if (products.cachedAt) await activityCache.write("actions", id, products.cachedAt, actions, record.hasNext);
|
||||
return true;
|
||||
}
|
||||
function createBadge(optyNumber) {
|
||||
const summary = getSummary(optyNumber);
|
||||
if (!summary) return null;
|
||||
@@ -139,5 +168,5 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
if (state === "missing") badge.append(createActionButton(String(optyNumber)));
|
||||
return badge;
|
||||
}
|
||||
return { reset, reopen, loadProducts, blockProducts, createBadge, getSummary };
|
||||
return { reset, reopen, loadProducts, blockProducts, createBadge, getSummary, applySavedAction };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user