@4site/engrid-scripts 0.22.12 → 0.22.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/events/donation-amount.js +2 -0
- package/dist/frequency-upsell.js +1 -0
- package/dist/interfaces/frequency-upsell-options.d.ts +1 -0
- package/dist/interfaces/frequency-upsell-options.js +1 -0
- package/dist/swap-amounts.d.ts +4 -8
- package/dist/swap-amounts.js +63 -48
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -33,6 +33,8 @@ export class DonationAmount {
|
|
|
33
33
|
this.amount = ENGrid.cleanAmount(otherField.value);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
// Load the current amount
|
|
37
|
+
this.load();
|
|
36
38
|
}
|
|
37
39
|
static getInstance(radios = "transaction.donationAmt", other = "transaction.donationAmt.other") {
|
|
38
40
|
if (!DonationAmount.instance) {
|
package/dist/frequency-upsell.js
CHANGED
|
@@ -89,6 +89,7 @@ export class FrequencyUpsell {
|
|
|
89
89
|
this.upsellModal.updateModalContent();
|
|
90
90
|
this.logger.log("Frequency upsell modal opened");
|
|
91
91
|
(_a = this.upsellModal) === null || _a === void 0 ? void 0 : _a.open();
|
|
92
|
+
this.options.onOpen();
|
|
92
93
|
this.modalSeen = true;
|
|
93
94
|
this._form.submit = false;
|
|
94
95
|
return false;
|
|
@@ -7,6 +7,7 @@ export interface FrequencyUpsellOptions {
|
|
|
7
7
|
upsellAmount: (currentAmount: number) => number;
|
|
8
8
|
upsellFromFrequency: Array<"onetime" | "monthly" | "quarterly" | "semi_annual" | "annual">;
|
|
9
9
|
customClass: string;
|
|
10
|
+
onOpen: () => void;
|
|
10
11
|
onAccept: () => void;
|
|
11
12
|
onDecline: () => void;
|
|
12
13
|
}
|
package/dist/swap-amounts.d.ts
CHANGED
|
@@ -33,14 +33,10 @@ export declare class SwapAmounts {
|
|
|
33
33
|
constructor();
|
|
34
34
|
loadAmountsFromUrl(): void;
|
|
35
35
|
swapAmounts(): void;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
selected: boolean;
|
|
41
|
-
label: string;
|
|
42
|
-
value: string;
|
|
43
|
-
}[];
|
|
36
|
+
/**
|
|
37
|
+
* Convert the internal config object into the structure Engaging Networks expects
|
|
38
|
+
*/
|
|
39
|
+
private toEnAmountList;
|
|
44
40
|
shouldRun(): boolean;
|
|
45
41
|
ignoreCurrentValue(): boolean;
|
|
46
42
|
}
|
package/dist/swap-amounts.js
CHANGED
|
@@ -34,79 +34,94 @@ export class SwapAmounts {
|
|
|
34
34
|
this.logger = new EngridLogger("SwapAmounts", "purple", "white", "💰");
|
|
35
35
|
this._amount = DonationAmount.getInstance();
|
|
36
36
|
this._frequency = DonationFrequency.getInstance();
|
|
37
|
-
this.defaultChange = false;
|
|
38
|
-
this.swapped = false;
|
|
37
|
+
this.defaultChange = false; // Tracks if user changed away from default after swap
|
|
38
|
+
this.swapped = false; // Tracks if we've already executed at least one swap
|
|
39
39
|
this.loadAmountsFromUrl();
|
|
40
40
|
if (!this.shouldRun())
|
|
41
41
|
return;
|
|
42
|
+
// Respond when frequency changes
|
|
42
43
|
this._frequency.onFrequencyChange.subscribe(() => this.swapAmounts());
|
|
44
|
+
// Track if donor moves away from the swapped default amount
|
|
43
45
|
this._amount.onAmountChange.subscribe(() => {
|
|
44
|
-
|
|
46
|
+
const configs = window.EngridAmounts;
|
|
47
|
+
if (!configs)
|
|
45
48
|
return;
|
|
46
|
-
|
|
47
|
-
if (!
|
|
49
|
+
const freq = this._frequency.frequency;
|
|
50
|
+
if (!(freq in configs))
|
|
48
51
|
return;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
52
|
+
if (!this.swapped)
|
|
53
|
+
return; // ignore early changes before initial swap
|
|
54
|
+
const currentConfig = configs[freq];
|
|
55
|
+
this.defaultChange = this._amount.amount !== currentConfig.default;
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
loadAmountsFromUrl() {
|
|
57
59
|
const urlParams = new URLSearchParams(window.location.search);
|
|
58
60
|
const amounts = urlParams.get("engrid-amounts");
|
|
59
61
|
if (amounts) {
|
|
60
|
-
this.defaultChange = true;
|
|
61
|
-
const amountArray = amounts
|
|
62
|
-
|
|
62
|
+
this.defaultChange = true; // if amounts come from URL, treat as user-set
|
|
63
|
+
const amountArray = amounts
|
|
64
|
+
.split(",")
|
|
65
|
+
.map((amt) => amt.trim())
|
|
66
|
+
.filter(Boolean);
|
|
67
|
+
if (!amountArray.length)
|
|
68
|
+
return;
|
|
69
|
+
const urlDefaultParam = ENGrid.getUrlParameter("transaction.donationAmt");
|
|
70
|
+
const parsedFirst = parseFloat(amountArray[0]);
|
|
71
|
+
const defaultAmount = (urlDefaultParam && parseFloat(urlDefaultParam)) ||
|
|
72
|
+
parsedFirst;
|
|
63
73
|
const amountsObj = {};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
amountArray.forEach((raw) => {
|
|
75
|
+
const numeric = parseFloat(raw);
|
|
76
|
+
amountsObj[raw] = isNaN(numeric) ? raw : numeric;
|
|
77
|
+
});
|
|
78
|
+
// Ensure Other choice always present at the end
|
|
69
79
|
amountsObj["Other"] = "other";
|
|
80
|
+
const config = {
|
|
81
|
+
amounts: amountsObj,
|
|
82
|
+
default: defaultAmount,
|
|
83
|
+
};
|
|
70
84
|
window.EngridAmounts = {
|
|
71
|
-
onetime:
|
|
72
|
-
monthly:
|
|
85
|
+
onetime: config,
|
|
86
|
+
monthly: config,
|
|
73
87
|
};
|
|
74
88
|
}
|
|
75
89
|
}
|
|
76
90
|
swapAmounts() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
const configs = window.EngridAmounts;
|
|
92
|
+
if (!configs)
|
|
93
|
+
return;
|
|
94
|
+
const freq = this._frequency.frequency;
|
|
95
|
+
const config = configs[freq];
|
|
96
|
+
if (!config)
|
|
97
|
+
return;
|
|
98
|
+
const ignoreCurrentValue = this.ignoreCurrentValue();
|
|
99
|
+
window.EngagingNetworks.require._defined.enjs.swapList("donationAmt", this.toEnAmountList(config), { ignoreCurrentValue });
|
|
100
|
+
this._amount.load();
|
|
101
|
+
this.logger.log("Amounts Swapped To", config, { ignoreCurrentValue });
|
|
102
|
+
this.swapped = true;
|
|
87
103
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
return ret;
|
|
104
|
+
/**
|
|
105
|
+
* Convert the internal config object into the structure Engaging Networks expects
|
|
106
|
+
*/
|
|
107
|
+
toEnAmountList(config) {
|
|
108
|
+
return Object.entries(config.amounts).map(([label, value]) => ({
|
|
109
|
+
selected: value === config.default,
|
|
110
|
+
label,
|
|
111
|
+
value: value.toString(),
|
|
112
|
+
}));
|
|
98
113
|
}
|
|
99
114
|
shouldRun() {
|
|
100
|
-
return
|
|
115
|
+
return !!window.EngridAmounts;
|
|
101
116
|
}
|
|
102
117
|
ignoreCurrentValue() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
: true;
|
|
118
|
+
const urlParam = ENGrid.getUrlParameter("transaction.donationAmt");
|
|
119
|
+
if (urlParam !== null) {
|
|
120
|
+
const urlAmount = parseFloat(urlParam);
|
|
121
|
+
return this._amount.amount !== urlAmount;
|
|
108
122
|
}
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
// If submission failed or donor manually changed away from default, respect current value
|
|
124
|
+
const submissionFailed = window.EngagingNetworks.require._defined.enjs.checkSubmissionFailed();
|
|
125
|
+
return !(submissionFailed || this.defaultChange);
|
|
111
126
|
}
|
|
112
127
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.22.
|
|
1
|
+
export declare const AppVersion = "0.22.14";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.22.
|
|
1
|
+
export const AppVersion = "0.22.14";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4site/engrid-scripts",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.14",
|
|
4
4
|
"description": "Scripts for the ENGRID Project",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"strongly-typed-events": "^2.0.9"
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/4site-interactive-studios/engrid#readme",
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "83a15dbeaa859e1952497ae2e932a630df690eb8",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|