Skip to content

Commit

Permalink
add domain existence check, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen committed May 2, 2024
1 parent 7dc96e8 commit 1f82e32
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions portal/static/js/src/empro.js
Expand Up @@ -474,7 +474,7 @@ emproObj.prototype.init = function () {

this.initTriggerDomains(
{
maxTryAttempts: !autoShowModal ? 0 : 5, //no need to retry if thank you modal isn't supposed to show
maxTryAttempts: !autoShowModal ? 0 : isDebugging ? 0 : 5, //no need to retry if thank you modal isn't supposed to show
clearCache: autoShowModal,
},
(result) => {
Expand Down Expand Up @@ -519,6 +519,10 @@ emproObj.prototype.processTriggerData = function (data, historyData) {
console.log("No trigger data");
return false;
}

// set visit month related to trigger data
this.visitMonth = data.visit_month;

var self = this;

let processedHistoryData = [];
Expand All @@ -530,8 +534,9 @@ emproObj.prototype.processTriggerData = function (data, historyData) {

console.log("processed history data ", processedHistoryData);

// set visit month related to trigger data
this.visitMonth = data.visit_month;
if (!data || !data.triggers || !data.triggers.domain) {
return;
}

for (let key in data.triggers.domain) {
if (!Object.keys(data.triggers.domain[key]).length) {
Expand Down Expand Up @@ -577,6 +582,7 @@ emproObj.prototype.processTriggerData = function (data, historyData) {
// check if user has chosen to opt out this domain 3 times before
const hasReachedMaxOptOut = processedHistoryData.find(
(item) =>
item[key] &&
parseInt(item[key]["_total_opted_out"]) >= MAX_ALLOWED_OPT_OUT_NUM
);
// if sequence count >= 3, the user can choose to opt_out of respective domain
Expand Down Expand Up @@ -628,15 +634,19 @@ emproObj.prototype.initTriggerDomains = function (params, callbackFunc) {
})
),
]).then((results) => {
const currentTriggerData =
let currentTriggerData =
results[0] && results[0].status === "fulfilled" && results[0].value
? results[0].value
: null;
const historyTriggerData =
results[1] && results[1].status === "fulfilled" && results[1].value
? results[1].value
: null;
if (isDebugging && !currentTriggerData) {
if (
isDebugging &&
(!currentTriggerData ||
(currentTriggerData && !currentTriggerData.triggers))
) {
currentTriggerData = TestTriggersJson;
}
if (!currentTriggerData) {
Expand Down

0 comments on commit 1f82e32

Please sign in to comment.