@internetarchive/donation-monthly-portal 7.1.0 → 7.1.1-payment-method-1
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/index.d.ts +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/edit-plan-form.d.ts +19 -0
- package/dist/src/edit-plan-form.js +68 -1
- package/dist/src/edit-plan-form.js.map +1 -1
- package/dist/src/form-sections/amount.js +3 -1
- package/dist/src/form-sections/amount.js.map +1 -1
- package/dist/src/form-sections/cancel.d.ts +0 -1
- package/dist/src/form-sections/cancel.js +0 -1
- package/dist/src/form-sections/cancel.js.map +1 -1
- package/dist/src/form-sections/date.js +2 -2
- package/dist/src/form-sections/date.js.map +1 -1
- package/dist/src/form-sections/parts/braintree-manager.d.ts +40 -0
- package/dist/src/form-sections/parts/braintree-manager.js +266 -0
- package/dist/src/form-sections/parts/braintree-manager.js.map +1 -0
- package/dist/src/form-sections/parts/credit-card-handler.d.ts +0 -0
- package/dist/src/form-sections/parts/credit-card-handler.js +2 -0
- package/dist/src/form-sections/parts/credit-card-handler.js.map +1 -0
- package/dist/src/form-sections/payment-method.d.ts +56 -0
- package/dist/src/form-sections/payment-method.js +319 -0
- package/dist/src/form-sections/payment-method.js.map +1 -0
- package/dist/src/models/payment-method-request.d.ts +25 -0
- package/dist/src/models/payment-method-request.js +9 -0
- package/dist/src/models/payment-method-request.js.map +1 -0
- package/dist/src/models/plan.d.ts +5 -2
- package/dist/src/models/plan.js +34 -37
- package/dist/src/models/plan.js.map +1 -1
- package/dist/src/monthly-giving-circle.d.ts +5 -1
- package/dist/src/monthly-giving-circle.js +37 -1
- package/dist/src/monthly-giving-circle.js.map +1 -1
- package/dist/src/presentational/donation-section-info.js +3 -2
- package/dist/src/presentational/donation-section-info.js.map +1 -1
- package/package.json +6 -8
- package/src/edit-plan-form.ts +84 -1
- package/src/form-sections/amount.ts +3 -1
- package/src/form-sections/cancel.ts +0 -1
- package/src/form-sections/date.ts +4 -3
- package/src/form-sections/parts/braintree-manager.ts +324 -0
- package/src/form-sections/parts/credit-card-handler.ts +0 -0
- package/src/form-sections/payment-method.ts +355 -0
- package/src/models/payment-method-request.ts +33 -0
- package/src/models/plan.ts +36 -44
- package/src/monthly-giving-circle.ts +38 -2
- package/src/presentational/donation-section-info.ts +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { Receipt } from './src/models/receipt';
|
|
|
4
4
|
export type { AReceipt } from './src/models/receipt';
|
|
5
5
|
export { MonthlyPlan } from './src/models/plan';
|
|
6
6
|
export type { Plan, BtData } from './src/models/plan';
|
|
7
|
+
export type { PaymentMethodRequest } from './src/models/payment-method-request';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { MonthlyGivingCircle } from './src/monthly-giving-circle';\nexport type { APlanUpdate } from './src/monthly-giving-circle';\nexport { Receipt } from './src/models/receipt';\nexport type { AReceipt } from './src/models/receipt';\nexport { MonthlyPlan } from './src/models/plan';\nexport type { Plan, BtData } from './src/models/plan';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { MonthlyGivingCircle } from './src/monthly-giving-circle';\nexport type { APlanUpdate } from './src/monthly-giving-circle';\nexport { Receipt } from './src/models/receipt';\nexport type { AReceipt } from './src/models/receipt';\nexport { MonthlyPlan } from './src/models/plan';\nexport type { Plan, BtData } from './src/models/plan';\nexport type { PaymentMethodRequest } from './src/models/payment-method-request';\n"]}
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
+
import '@internetarchive/donation-form/dist/src/form-elements/badged-input';
|
|
3
|
+
import { PaymentClientsInterface } from '@internetarchive/donation-form/dist/src/braintree-manager/payment-clients.js';
|
|
2
4
|
import type { MonthlyPlan } from './models/plan';
|
|
3
5
|
import './form-sections/amount';
|
|
4
6
|
import './form-sections/date';
|
|
5
7
|
import './form-sections/cancel';
|
|
8
|
+
import './form-sections/payment-method';
|
|
6
9
|
export declare class IauxEditPlanForm extends LitElement {
|
|
7
10
|
plan?: MonthlyPlan;
|
|
11
|
+
patronEmail: string;
|
|
8
12
|
updateAmountHandler?: (plan: MonthlyPlan, amountUpdates: {
|
|
9
13
|
amount: number;
|
|
10
14
|
baseAmount: number;
|
|
11
15
|
coverFees: boolean;
|
|
12
16
|
feeCovered: number;
|
|
13
17
|
}) => void;
|
|
18
|
+
paymentConfig: {
|
|
19
|
+
referrer: string;
|
|
20
|
+
origin: string;
|
|
21
|
+
braintreeAuthToken: string;
|
|
22
|
+
venmoProfileId: string;
|
|
23
|
+
googlePayMerchantId: string;
|
|
24
|
+
environment: string;
|
|
25
|
+
paymentClients: PaymentClientsInterface | undefined;
|
|
26
|
+
endpointManager: object;
|
|
27
|
+
};
|
|
28
|
+
braintreeNumberInput: HTMLDivElement;
|
|
29
|
+
braintreeExpirationDateInput: HTMLDivElement;
|
|
30
|
+
braintreeCVVInput: HTMLDivElement;
|
|
31
|
+
braintreeErrorMessage: HTMLDivElement;
|
|
14
32
|
createRenderRoot(): this;
|
|
33
|
+
paymentMethodUpdates(status: 'success' | 'fail'): void;
|
|
15
34
|
amountUpdates(status: 'success' | 'fail'): void;
|
|
16
35
|
dateUpdates(status: 'success' | 'fail'): void;
|
|
17
36
|
render(): import("lit").TemplateResult<1>;
|
|
@@ -1,13 +1,47 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { LitElement, html } from 'lit';
|
|
3
|
-
import { customElement, property } from 'lit/decorators.js';
|
|
3
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
4
|
+
import '@internetarchive/donation-form/dist/src/form-elements/badged-input';
|
|
5
|
+
import { LazyLoaderService } from '@internetarchive/lazy-loader-service';
|
|
6
|
+
import { HostingEnvironment, } from '@internetarchive/donation-form/dist/src/braintree-manager/braintree-interfaces.js';
|
|
7
|
+
import { PaymentClients, } from '@internetarchive/donation-form/dist/src/braintree-manager/payment-clients.js';
|
|
4
8
|
import './form-sections/amount';
|
|
5
9
|
import './form-sections/date';
|
|
6
10
|
import './form-sections/cancel';
|
|
11
|
+
import './form-sections/payment-method';
|
|
7
12
|
let IauxEditPlanForm = class IauxEditPlanForm extends LitElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.patronEmail = '';
|
|
16
|
+
this.paymentConfig = {
|
|
17
|
+
referrer: '',
|
|
18
|
+
origin: '',
|
|
19
|
+
braintreeAuthToken: 'sandbox_x634jsj7_7zybks4ybp63pbmd',
|
|
20
|
+
venmoProfileId: '1953896702662410263',
|
|
21
|
+
googlePayMerchantId: '',
|
|
22
|
+
environment: 'dev',
|
|
23
|
+
paymentClients: new PaymentClients(new LazyLoaderService(), HostingEnvironment.Development),
|
|
24
|
+
endpointManager: {
|
|
25
|
+
// eslint-disable-next-line arrow-body-style, @typescript-eslint/no-unused-vars
|
|
26
|
+
submitData: async (_request) => {
|
|
27
|
+
// eslint-disable-next-line no-debugger
|
|
28
|
+
debugger;
|
|
29
|
+
},
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
|
+
donationSuccessful: (_response) => {
|
|
32
|
+
// eslint-disable-next-line no-debugger
|
|
33
|
+
debugger;
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
8
38
|
createRenderRoot() {
|
|
9
39
|
return this;
|
|
10
40
|
}
|
|
41
|
+
paymentMethodUpdates(status) {
|
|
42
|
+
const paymentMethodForm = this.querySelector('ia-mgc-edit-payment-method');
|
|
43
|
+
paymentMethodForm.paymentMethodUpdated(status);
|
|
44
|
+
}
|
|
11
45
|
amountUpdates(status) {
|
|
12
46
|
const amountForm = this.querySelector('ia-mgc-edit-plan-amount');
|
|
13
47
|
amountForm.amountUpdated(status);
|
|
@@ -35,6 +69,21 @@ let IauxEditPlanForm = class IauxEditPlanForm extends LitElement {
|
|
|
35
69
|
}}
|
|
36
70
|
></ia-mgc-edit-plan-amount>
|
|
37
71
|
<hr />
|
|
72
|
+
<ia-mgc-edit-payment-method
|
|
73
|
+
.plan=${this.plan}
|
|
74
|
+
.patronEmail=${this.patronEmail}
|
|
75
|
+
.paymentConfig=${this.paymentConfig}
|
|
76
|
+
@UpdatePaymentMethod=${(e) => {
|
|
77
|
+
const { newPaymentMethodRequest } = e.detail;
|
|
78
|
+
if (this.plan) {
|
|
79
|
+
this.dispatchEvent(new CustomEvent('UpdatePaymentMethod', {
|
|
80
|
+
detail: { plan: this.plan, newPaymentMethodRequest },
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
</ia-mgc-edit-payment-method>
|
|
86
|
+
<hr />
|
|
38
87
|
<ia-mgc-edit-date
|
|
39
88
|
@updateDate=${(e) => {
|
|
40
89
|
const { newDate } = e.detail;
|
|
@@ -68,9 +117,27 @@ let IauxEditPlanForm = class IauxEditPlanForm extends LitElement {
|
|
|
68
117
|
__decorate([
|
|
69
118
|
property({ type: Object })
|
|
70
119
|
], IauxEditPlanForm.prototype, "plan", void 0);
|
|
120
|
+
__decorate([
|
|
121
|
+
property({ type: String })
|
|
122
|
+
], IauxEditPlanForm.prototype, "patronEmail", void 0);
|
|
71
123
|
__decorate([
|
|
72
124
|
property({ type: Object })
|
|
73
125
|
], IauxEditPlanForm.prototype, "updateAmountHandler", void 0);
|
|
126
|
+
__decorate([
|
|
127
|
+
property({ type: Object })
|
|
128
|
+
], IauxEditPlanForm.prototype, "paymentConfig", void 0);
|
|
129
|
+
__decorate([
|
|
130
|
+
query('#braintree-creditcard')
|
|
131
|
+
], IauxEditPlanForm.prototype, "braintreeNumberInput", void 0);
|
|
132
|
+
__decorate([
|
|
133
|
+
query('#braintree-expiration')
|
|
134
|
+
], IauxEditPlanForm.prototype, "braintreeExpirationDateInput", void 0);
|
|
135
|
+
__decorate([
|
|
136
|
+
query('#braintree-cvv')
|
|
137
|
+
], IauxEditPlanForm.prototype, "braintreeCVVInput", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
query('#braintree-error-message')
|
|
140
|
+
], IauxEditPlanForm.prototype, "braintreeErrorMessage", void 0);
|
|
74
141
|
IauxEditPlanForm = __decorate([
|
|
75
142
|
customElement('ia-mgc-edit-plan')
|
|
76
143
|
], IauxEditPlanForm);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit-plan-form.js","sourceRoot":"","sources":["../../src/edit-plan-form.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"edit-plan-form.js","sourceRoot":"","sources":["../../src/edit-plan-form.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,oEAAoE,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAEL,kBAAkB,GACnB,MAAM,mFAAmF,CAAC;AAC3F,OAAO,EACL,cAAc,GAEf,MAAM,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,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9C,CAAC;;;;;oBAKS,IAAI,CAAC,UAAU,EAAE;;;KAGhC,CAAC;IACJ,CAAC;IAED,UAAU;QACR,OAAO,6EAA6E,CAAC;IACvF,CAAC;CACF,CAAA;AAlJ6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAAoB;AAEnB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAA0B;AAEzB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6DAQjB;AAEkB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDAgCzB;AAE8B;IAA/B,KAAK,CAAC,uBAAuB,CAAC;8DAAuC;AAEtC;IAA/B,KAAK,CAAC,uBAAuB,CAAC;sEAA+C;AAErD;IAAxB,KAAK,CAAC,gBAAgB,CAAC;2DAAoC;AAEzB;IAAlC,KAAK,CAAC,0BAA0B,CAAC;+DAAwC;AAvD/D,gBAAgB;IAD5B,aAAa,CAAC,kBAAkB,CAAC;GACrB,gBAAgB,CAmJ5B","sourcesContent":["import { LitElement, html } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\n\nimport '@internetarchive/donation-form/dist/src/form-elements/badged-input';\n\nimport { LazyLoaderService } from '@internetarchive/lazy-loader-service';\nimport {\n BraintreeEndpointManagerInterface,\n HostingEnvironment,\n} from '@internetarchive/donation-form/dist/src/braintree-manager/braintree-interfaces.js';\nimport {\n PaymentClients,\n PaymentClientsInterface,\n} from '@internetarchive/donation-form/dist/src/braintree-manager/payment-clients.js';\nimport type { DonationRequest } from '@internetarchive/donation-form-data-models';\n\nimport type { MonthlyPlan } from './models/plan';\nimport './form-sections/amount';\nimport './form-sections/date';\nimport './form-sections/cancel';\nimport './form-sections/payment-method';\nimport type { MGCEditPlanAmount } from './form-sections/amount';\nimport type { MGCEditPlanDate } from './form-sections/date';\nimport type { MGCEditPaymentMethod } from './form-sections/payment-method';\n\n@customElement('ia-mgc-edit-plan')\nexport class IauxEditPlanForm extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n @property({ type: String }) patronEmail: string = '';\n\n @property({ type: Object }) updateAmountHandler?: (\n plan: MonthlyPlan,\n amountUpdates: {\n amount: number;\n baseAmount: number;\n coverFees: boolean;\n feeCovered: number;\n },\n ) => void;\n\n @property({ type: Object }) paymentConfig: {\n referrer: string;\n origin: string;\n braintreeAuthToken: string;\n venmoProfileId: string;\n googlePayMerchantId: string;\n environment: string;\n paymentClients: PaymentClientsInterface | undefined;\n endpointManager: object;\n } = {\n referrer: '',\n origin: '',\n braintreeAuthToken: 'sandbox_x634jsj7_7zybks4ybp63pbmd',\n venmoProfileId: '1953896702662410263',\n googlePayMerchantId: '',\n environment: 'dev',\n paymentClients: new PaymentClients(\n new LazyLoaderService(),\n HostingEnvironment.Development,\n ),\n endpointManager: {\n // eslint-disable-next-line arrow-body-style, @typescript-eslint/no-unused-vars\n submitData: async (_request: DonationRequest) => {\n // eslint-disable-next-line no-debugger\n debugger;\n },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n donationSuccessful: (_response: any) => {\n // eslint-disable-next-line no-debugger\n debugger;\n },\n } as unknown as BraintreeEndpointManagerInterface,\n };\n\n @query('#braintree-creditcard') braintreeNumberInput!: HTMLDivElement;\n\n @query('#braintree-expiration') braintreeExpirationDateInput!: HTMLDivElement;\n\n @query('#braintree-cvv') braintreeCVVInput!: HTMLDivElement;\n\n @query('#braintree-error-message') braintreeErrorMessage!: HTMLDivElement;\n\n createRenderRoot() {\n return this;\n }\n\n paymentMethodUpdates(status: 'success' | 'fail') {\n const paymentMethodForm = this.querySelector(\n 'ia-mgc-edit-payment-method',\n ) as MGCEditPaymentMethod;\n paymentMethodForm!.paymentMethodUpdated(status);\n }\n\n amountUpdates(status: 'success' | 'fail') {\n const amountForm = this.querySelector(\n 'ia-mgc-edit-plan-amount',\n ) as MGCEditPlanAmount;\n amountForm!.amountUpdated(status);\n }\n\n dateUpdates(status: 'success' | 'fail') {\n const dateForm = this.querySelector('ia-mgc-edit-date') as MGCEditPlanDate;\n dateForm!.dateUpdated(status);\n }\n\n render() {\n return html`\n <section class=\"mgc-edit-plan\">\n <ia-mgc-edit-plan-amount\n .plan=${this.plan}\n @updateAmount=${(e: CustomEvent) => {\n const { amount, baseAmount, coverFees, feeCovered } = e.detail;\n if (this.plan) {\n this.updateAmountHandler?.(this.plan, {\n amount,\n baseAmount,\n coverFees,\n feeCovered,\n });\n }\n }}\n ></ia-mgc-edit-plan-amount>\n <hr />\n <ia-mgc-edit-payment-method\n .plan=${this.plan}\n .patronEmail=${this.patronEmail}\n .paymentConfig=${this.paymentConfig}\n @UpdatePaymentMethod=${(e: CustomEvent) => {\n const { newPaymentMethodRequest } = e.detail;\n if (this.plan) {\n this.dispatchEvent(\n new CustomEvent('UpdatePaymentMethod', {\n detail: { plan: this.plan, newPaymentMethodRequest },\n }),\n );\n }\n }}\n >\n </ia-mgc-edit-payment-method>\n <hr />\n <ia-mgc-edit-date\n @updateDate=${(e: CustomEvent) => {\n const { newDate } = e.detail;\n if (this.plan) {\n this.dispatchEvent(\n new CustomEvent('updateDate', {\n detail: { plan: this.plan, newDate },\n }),\n );\n }\n }}\n .plan=${this.plan}\n ></ia-mgc-edit-date>\n <hr />\n <ia-mgc-cancel-plan\n .plan=${this.plan}\n @cancelPlan=${() => {\n this.dispatchEvent(new Event('cancelPlan'));\n }}\n ></ia-mgc-cancel-plan>\n <hr />\n <p class=\"email-edit-plan\">\n Need to update your plan further? Please email us at\n <a href=${this.mailToText()}>donations@archive.org</a>.\n </p>\n </section>\n `;\n }\n\n mailToText(): string {\n return `mailto:donations@archive.org?subject=I'd like to update my monthly donation`;\n }\n}\n"]}
|
|
@@ -54,7 +54,9 @@ let MGCEditPlanAmount = class MGCEditPlanAmount extends LitElement {
|
|
|
54
54
|
this.clearInputField();
|
|
55
55
|
this.updateStatus = status;
|
|
56
56
|
this.updateMessage =
|
|
57
|
-
status === 'success'
|
|
57
|
+
status === 'success'
|
|
58
|
+
? 'Amount updated'
|
|
59
|
+
: 'Failed to update date, please try again';
|
|
58
60
|
if (status === 'success') {
|
|
59
61
|
this.closeForm();
|
|
60
62
|
await this.updateComplete;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../../src/form-sections/amount.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,IAAI,EAEJ,OAAO,EACP,GAAG,GAEJ,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,wCAAwC,CAAC;AAChD,OAAO,EACL,mBAAmB,EACnB,YAAY,GACb,MAAM,4CAA4C,CAAC;AAGpD,OAAO,yCAAyC,CAAC;AACjD,OAAO,8BAA8B,CAAC;AAEtC,OAAO,qCAAqC,CAAC;AAGtC,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU;IAA1C;;QAMuB,cAAS,GAAW,CAAC,CAAC;QAEN,qBAAgB,GAAY,KAAK,CAAC;QAEjD,cAAS,GAAY,KAAK,CAAC;QAE5B,kBAAa,GAAW,EAAE,CAAC;QAE3B,iBAAY,GAAW,EAAE,CAAC;QAE1B,iBAAY,GAA4B,EAAE,CAAC;IA6TzE,CAAC;IAzTC,OAAO,CAAC,OAAuB;QAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,OAAO,CAAC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7B,aAAa,CAAC,yBAAyB,CAAC;GAC5B,iBAAiB,CA6U7B","sourcesContent":["import {\n LitElement,\n html,\n PropertyValues,\n nothing,\n css,\n TemplateResult,\n} from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport '@internetarchive/donation-form-section';\nimport {\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\n\nimport type { MonthlyPlan } from '../models/plan';\nimport '../presentational/donation-section-info';\nimport '../presentational/mgc-button';\nimport type { MGCButton } from '../presentational/mgc-button';\nimport '../presentational/mgc-update-status';\n\n@customElement('ia-mgc-edit-plan-amount')\nexport class MGCEditPlanAmount extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n // captures the changes made to the amount && calculates the total amount with fees\n @property({ type: Object }) donationPaymentInfo?: DonationPaymentInfo;\n\n @property({ type: Number }) newAmount: number = 0;\n\n @property({ type: Boolean, reflect: true }) currentlyEditing: boolean = false;\n\n @property({ type: Boolean }) coverFees: boolean = false;\n\n @property({ type: String }) updateMessage: string = '';\n\n @property({ type: String }) errorMessage: string = '';\n\n @property({ type: String }) updateStatus: 'success' | 'fail' | '' = '';\n\n @query('form') form!: HTMLFormElement;\n\n updated(changed: PropertyValues) {\n if (changed.has('plan') && this.plan) {\n this.captureAmountChanges();\n }\n if (changed.has('coverFees')) {\n this.captureAmountChanges();\n }\n if (changed.has('currentlyEditing') && this.currentlyEditing) {\n this.form.focus();\n }\n\n if (changed.has('donationPaymentInfo') && !this.donationPaymentInfo) {\n this.captureAmountChanges();\n }\n }\n\n protected render() {\n return html`\n <section>\n <donation-form-section badgemode=\"hidebadge\" headline=\"Amount\">\n ${!this.currentlyEditing\n ? html`<ia-mgc-form-section-info\n @editingRequested=${() => {\n this.currentlyEditing = true;\n this.clearStatusMessaging();\n }}\n ><span>USD $${this.plan?.amountFormatted}</span>\n </ia-mgc-form-section-info>`\n : nothing}\n ${this.currentlyEditing ? this.editAmountForm : nothing}\n </donation-form-section>\n </section>\n `;\n }\n\n /* External Function that is called by consumer to tell the form there has been data update */\n async amountUpdated(status: 'success' | 'fail') {\n this.clearInputField();\n\n this.updateStatus = status;\n this.updateMessage =\n status === 'success' ? 'Amount updated' : 'Failed. Try again.';\n\n if (status === 'success') {\n this.closeForm();\n await this.updateComplete;\n\n this.updateStatus = status;\n this.updateMessage = 'Amount updated';\n\n return;\n }\n\n (\n this.form.querySelector('ia-mgc-button#update-amount') as MGCButton\n ).isDisabled = false;\n\n this.captureAmountChanges();\n\n await this.updateComplete;\n }\n\n /* Dispatches amount change request */\n requestAmountUpdate(e: Event): void {\n e.preventDefault();\n\n const input = this.form.querySelector(\n 'input[name=\"amount\"]',\n ) as HTMLInputElement;\n this.newAmount = Number(input.value);\n\n this.captureAmountChanges(this.newAmount);\n\n console.log('<plan-amount> - update amount', {\n newValue: this.newAmount,\n oldValue: this.plan?.plan.amount,\n display: this.donationPaymentInfo?.amount,\n });\n const newAmount = Number(\n DonationPaymentInfo.calculateTotal(\n Number(this.donationPaymentInfo?.amount),\n this.coverFees,\n ),\n );\n this.dispatchEvent(\n new CustomEvent('updateAmount', {\n detail: {\n plan: this.plan,\n amount: newAmount,\n baseAmount: this.donationPaymentInfo?.amount,\n coverFees: this.coverFees,\n feeCovered: this.donationPaymentInfo?.feeAmountCovered,\n },\n }),\n );\n }\n\n /* captures form changes */\n captureAmountChanges(newAmount?: number) {\n if (!this.donationPaymentInfo && this.plan) {\n this.donationPaymentInfo = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: 0,\n coverFees: true,\n });\n return;\n }\n\n let newPlan;\n if (newAmount) {\n newPlan = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: newAmount,\n coverFees: true,\n });\n } else {\n const amount = this.donationPaymentInfo\n ? this.donationPaymentInfo.amount\n : this.plan!.amount;\n\n newPlan = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount,\n coverFees: true,\n });\n }\n\n this.donationPaymentInfo = newPlan;\n }\n\n closeForm() {\n this.clearInputField();\n this.clearStatusMessaging();\n this.currentlyEditing = false;\n this.coverFees = false;\n this.errorMessage = '';\n }\n\n clearInputField() {\n const input = this.form.querySelector(\n 'input[name=\"amount\"]',\n ) as HTMLInputElement;\n input.value = '';\n this.newAmount = 0;\n this.donationPaymentInfo = undefined;\n }\n\n handleSubmit(e: Event, iaButton?: MGCButton) {\n e.preventDefault();\n this.clearStatusMessaging();\n\n const button =\n iaButton ?? (this.form.querySelector('#update-amount') as MGCButton);\n if (button) this.updateButtonState(button);\n\n if (!this.newAmount) {\n this.errorMessage = 'Please enter a new amount';\n if (button) button.isDisabled = false;\n return;\n }\n\n const input = this.form.querySelector(\n 'input[name=\"amount\"]',\n ) as HTMLInputElement;\n const requestedAmount = Number(input.value) ?? 0;\n const amountTooLow = requestedAmount < 1;\n const amountTooHigh = requestedAmount >= 9999;\n\n if (amountTooLow) {\n this.errorMessage = 'Please enter a valid amount';\n }\n\n if (amountTooHigh) {\n this.errorMessage =\n 'Amount must be less than $9,999. Would you like to donate more? Please contact us at donations@archive.org';\n }\n\n if (amountTooHigh || amountTooLow) {\n if (button) this.updateButtonState(button);\n return;\n }\n\n this.requestAmountUpdate(e);\n }\n\n private async updateButtonState(iaButton: MGCButton) {\n // eslint-disable-next-line no-param-reassign\n (iaButton as MGCButton).isDisabled = true;\n await iaButton?.updateComplete;\n }\n\n async clearStatusMessaging() {\n this.errorMessage = '';\n this.updateMessage = '';\n this.updateStatus = '';\n await this.updateComplete;\n }\n\n /* DISPLAY */\n totalAmountWithFees(): number {\n if (this.newAmount === 0) {\n return 0;\n }\n\n return DonationPaymentInfo.calculateTotal(this.newAmount, this.coverFees);\n }\n\n get coveredFeesText() {\n return `I'll generously add $${this.donationPaymentInfo?.feeAmountCovered} to cover fees.`;\n }\n\n get editAmountForm(): TemplateResult {\n return html`\n <section>\n <form\n id=\"edit-plan-amount\"\n @submit=${(e: Event) => this.handleSubmit(e)}\n >\n <p>Current donation amount: $${this.plan?.amountFormatted}</p>\n <div>\n $\n <input\n min=\"1\"\n max=\"9999\"\n type=\"number\"\n id=\"amount\"\n name=\"amount\"\n ?required=${true}\n @focus=${() => this.clearStatusMessaging()}\n @input=${(e: Event) => {\n const newAmount = Number((e.target as HTMLInputElement).value);\n this.captureAmountChanges(newAmount);\n this.newAmount = newAmount;\n }}\n />\n / month\n </div>\n <div>\n <div class=\"checkbox-option-container\">\n <input\n type=\"checkbox\"\n id=\"cover-fees\"\n tabindex=\"0\"\n @change=${(e: Event) => {\n const input = e.target as HTMLInputElement;\n const coverFees = input.checked;\n this.coverFees = coverFees;\n this.captureAmountChanges();\n }}\n />\n <label for=\"cover-fees\">${this.coveredFeesText}</label>\n </div>\n <p>Total: USD $${this.totalAmountWithFees()}</p>\n <div class=\"cta-container\">\n <ia-mgc-button\n class=\"ia-button secondary\"\n .clickHandler=${(e: Event) => {\n e.preventDefault();\n this.closeForm();\n }}\n >\n Cancel\n </ia-mgc-button>\n <ia-mgc-button\n id=\"update-amount\"\n class=\"ia-button primary\"\n type=\"submit\"\n ?isDisabled=${!this.newAmount}\n .clickHandler=${(e: Event, iaButton: MGCButton) =>\n this.handleSubmit(e, iaButton)}\n >\n Update\n </ia-mgc-button>\n <ia-mgc-update-status .status=${this.updateStatus}\n >${this.updateMessage}</ia-mgc-update-status\n >\n </div>\n </div>\n <p class=\"error\">${this.errorMessage}</p>\n </form>\n </section>\n `;\n }\n\n static styles = css`\n input#amount {\n width: 50px;\n }\n\n .cta-container {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-content: center;\n justify-content: flex-start;\n align-items: center;\n gap: 10px;\n }\n\n p.error {\n color: var(--mgc-warning-color-dark, #bb0505);\n }\n\n ia-mgc-update-status {\n display: inline-block;\n margin-left: 1rem;\n }\n\n .checkbox-option-container {\n margin: 10px 0;\n display: flex;\n }\n `;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../../src/form-sections/amount.ts"],"names":[],"mappings":";AAAA,OAA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CAAC,EAAE,QAAQ,CAAC;;;;8CAIF,IAAI,CAAC,YAAY;mBAC5C,IAAI,CAAC,aAAa;;;;6BAIR,IAAI,CAAC,YAAY;;;KAGzC,CAAC;IACJ,CAAC;;AAEM,wBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BlB,AA5BY,CA4BX;AA7U0B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAoB;AAGnB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8DAA2C;AAE1C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDAAuB;AAEN;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2DAAmC;AAEjD;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;oDAA4B;AAE5B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAA4B;AAE3B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDAA2B;AAE1B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDAA4C;AAExD;IAAd,KAAK,CAAC,MAAM,CAAC;+CAAwB;AAlB3B,iBAAiB;IAD7B,aAAa,CAAC,yBAAyB,CAAC;GAC5B,iBAAiB,CA+U7B","sourcesContent":["import {\n LitElement,\n html,\n PropertyValues,\n nothing,\n css,\n TemplateResult,\n} from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport '@internetarchive/donation-form-section';\nimport {\n DonationPaymentInfo,\n DonationType,\n} from '@internetarchive/donation-form-data-models';\n\nimport type { MonthlyPlan } from '../models/plan';\nimport '../presentational/donation-section-info';\nimport '../presentational/mgc-button';\nimport type { MGCButton } from '../presentational/mgc-button';\nimport '../presentational/mgc-update-status';\n\n@customElement('ia-mgc-edit-plan-amount')\nexport class MGCEditPlanAmount extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n // captures the changes made to the amount && calculates the total amount with fees\n @property({ type: Object }) donationPaymentInfo?: DonationPaymentInfo;\n\n @property({ type: Number }) newAmount: number = 0;\n\n @property({ type: Boolean, reflect: true }) currentlyEditing: boolean = false;\n\n @property({ type: Boolean }) coverFees: boolean = false;\n\n @property({ type: String }) updateMessage: string = '';\n\n @property({ type: String }) errorMessage: string = '';\n\n @property({ type: String }) updateStatus: 'success' | 'fail' | '' = '';\n\n @query('form') form!: HTMLFormElement;\n\n updated(changed: PropertyValues) {\n if (changed.has('plan') && this.plan) {\n this.captureAmountChanges();\n }\n if (changed.has('coverFees')) {\n this.captureAmountChanges();\n }\n if (changed.has('currentlyEditing') && this.currentlyEditing) {\n this.form.focus();\n }\n\n if (changed.has('donationPaymentInfo') && !this.donationPaymentInfo) {\n this.captureAmountChanges();\n }\n }\n\n protected render() {\n return html`\n <section>\n <donation-form-section badgemode=\"hidebadge\" headline=\"Amount\">\n ${!this.currentlyEditing\n ? html`<ia-mgc-form-section-info\n @editingRequested=${() => {\n this.currentlyEditing = true;\n this.clearStatusMessaging();\n }}\n ><span>USD $${this.plan?.amountFormatted}</span>\n </ia-mgc-form-section-info>`\n : nothing}\n ${this.currentlyEditing ? this.editAmountForm : nothing}\n </donation-form-section>\n </section>\n `;\n }\n\n /* External Function that is called by consumer to tell the form there has been data update */\n async amountUpdated(status: 'success' | 'fail') {\n this.clearInputField();\n\n this.updateStatus = status;\n this.updateMessage =\n status === 'success'\n ? 'Amount updated'\n : 'Failed to update date, please try again';\n\n if (status === 'success') {\n this.closeForm();\n await this.updateComplete;\n\n this.updateStatus = status;\n this.updateMessage = 'Amount updated';\n\n return;\n }\n\n (\n this.form.querySelector('ia-mgc-button#update-amount') as MGCButton\n ).isDisabled = false;\n\n this.captureAmountChanges();\n\n await this.updateComplete;\n }\n\n /* Dispatches amount change request */\n requestAmountUpdate(e: Event): void {\n e.preventDefault();\n\n const input = this.form.querySelector(\n 'input[name=\"amount\"]',\n ) as HTMLInputElement;\n this.newAmount = Number(input.value);\n\n this.captureAmountChanges(this.newAmount);\n\n console.log('<plan-amount> - update amount', {\n newValue: this.newAmount,\n oldValue: this.plan?.plan.amount,\n display: this.donationPaymentInfo?.amount,\n });\n const newAmount = Number(\n DonationPaymentInfo.calculateTotal(\n Number(this.donationPaymentInfo?.amount),\n this.coverFees,\n ),\n );\n this.dispatchEvent(\n new CustomEvent('updateAmount', {\n detail: {\n plan: this.plan,\n amount: newAmount,\n baseAmount: this.donationPaymentInfo?.amount,\n coverFees: this.coverFees,\n feeCovered: this.donationPaymentInfo?.feeAmountCovered,\n },\n }),\n );\n }\n\n /* captures form changes */\n captureAmountChanges(newAmount?: number) {\n if (!this.donationPaymentInfo && this.plan) {\n this.donationPaymentInfo = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: 0,\n coverFees: true,\n });\n return;\n }\n\n let newPlan;\n if (newAmount) {\n newPlan = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount: newAmount,\n coverFees: true,\n });\n } else {\n const amount = this.donationPaymentInfo\n ? this.donationPaymentInfo.amount\n : this.plan!.amount;\n\n newPlan = new DonationPaymentInfo({\n donationType: DonationType.Monthly,\n amount,\n coverFees: true,\n });\n }\n\n this.donationPaymentInfo = newPlan;\n }\n\n closeForm() {\n this.clearInputField();\n this.clearStatusMessaging();\n this.currentlyEditing = false;\n this.coverFees = false;\n this.errorMessage = '';\n }\n\n clearInputField() {\n const input = this.form.querySelector(\n 'input[name=\"amount\"]',\n ) as HTMLInputElement;\n input.value = '';\n this.newAmount = 0;\n this.donationPaymentInfo = undefined;\n }\n\n handleSubmit(e: Event, iaButton?: MGCButton) {\n e.preventDefault();\n this.clearStatusMessaging();\n\n const button =\n iaButton ?? (this.form.querySelector('#update-amount') as MGCButton);\n if (button) this.updateButtonState(button);\n\n if (!this.newAmount) {\n this.errorMessage = 'Please enter a new amount';\n if (button) button.isDisabled = false;\n return;\n }\n\n const input = this.form.querySelector(\n 'input[name=\"amount\"]',\n ) as HTMLInputElement;\n const requestedAmount = Number(input.value) ?? 0;\n const amountTooLow = requestedAmount < 1;\n const amountTooHigh = requestedAmount >= 9999;\n\n if (amountTooLow) {\n this.errorMessage = 'Please enter a valid amount';\n }\n\n if (amountTooHigh) {\n this.errorMessage =\n 'Amount must be less than $9,999. Would you like to donate more? Please contact us at donations@archive.org';\n }\n\n if (amountTooHigh || amountTooLow) {\n if (button) this.updateButtonState(button);\n return;\n }\n\n this.requestAmountUpdate(e);\n }\n\n private async updateButtonState(iaButton: MGCButton) {\n // eslint-disable-next-line no-param-reassign\n (iaButton as MGCButton).isDisabled = true;\n await iaButton?.updateComplete;\n }\n\n async clearStatusMessaging() {\n this.errorMessage = '';\n this.updateMessage = '';\n this.updateStatus = '';\n await this.updateComplete;\n }\n\n /* DISPLAY */\n totalAmountWithFees(): number {\n if (this.newAmount === 0) {\n return 0;\n }\n\n return DonationPaymentInfo.calculateTotal(this.newAmount, this.coverFees);\n }\n\n get coveredFeesText() {\n return `I'll generously add $${this.donationPaymentInfo?.feeAmountCovered} to cover fees.`;\n }\n\n get editAmountForm(): TemplateResult {\n return html`\n <section>\n <form\n id=\"edit-plan-amount\"\n @submit=${(e: Event) => this.handleSubmit(e)}\n >\n <p>Current donation amount: $${this.plan?.amountFormatted}</p>\n <div>\n $\n <input\n min=\"1\"\n max=\"9999\"\n type=\"number\"\n id=\"amount\"\n name=\"amount\"\n ?required=${true}\n @focus=${() => this.clearStatusMessaging()}\n @input=${(e: Event) => {\n const newAmount = Number((e.target as HTMLInputElement).value);\n this.captureAmountChanges(newAmount);\n this.newAmount = newAmount;\n }}\n />\n / month\n </div>\n <div>\n <div class=\"checkbox-option-container\">\n <input\n type=\"checkbox\"\n id=\"cover-fees\"\n tabindex=\"0\"\n @change=${(e: Event) => {\n const input = e.target as HTMLInputElement;\n const coverFees = input.checked;\n this.coverFees = coverFees;\n this.captureAmountChanges();\n }}\n />\n <label for=\"cover-fees\">${this.coveredFeesText}</label>\n </div>\n <p>Total: USD $${this.totalAmountWithFees()}</p>\n <div class=\"cta-container\">\n <ia-mgc-button\n class=\"ia-button secondary\"\n .clickHandler=${(e: Event) => {\n e.preventDefault();\n this.closeForm();\n }}\n >\n Cancel\n </ia-mgc-button>\n <ia-mgc-button\n id=\"update-amount\"\n class=\"ia-button primary\"\n type=\"submit\"\n ?isDisabled=${!this.newAmount}\n .clickHandler=${(e: Event, iaButton: MGCButton) =>\n this.handleSubmit(e, iaButton)}\n >\n Update\n </ia-mgc-button>\n <ia-mgc-update-status .status=${this.updateStatus}\n >${this.updateMessage}</ia-mgc-update-status\n >\n </div>\n </div>\n <p class=\"error\">${this.errorMessage}</p>\n </form>\n </section>\n `;\n }\n\n static styles = css`\n input#amount {\n width: 50px;\n }\n\n .cta-container {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-content: center;\n justify-content: flex-start;\n align-items: center;\n gap: 10px;\n }\n\n p.error {\n color: var(--mgc-warning-color-dark, #bb0505);\n }\n\n ia-mgc-update-status {\n display: inline-block;\n margin-left: 1rem;\n }\n\n .checkbox-option-container {\n margin: 10px 0;\n display: flex;\n }\n `;\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LitElement, TemplateResult, PropertyValues, nothing } from 'lit';
|
|
2
2
|
import type { MonthlyPlan } from '../models/plan';
|
|
3
|
-
import '@internetarchive/donation-form/dist/src/form-elements/contact-form/contact-form.js';
|
|
4
3
|
import '@internetarchive/donation-form-section';
|
|
5
4
|
export declare class IauxMgcCancelPlan extends LitElement {
|
|
6
5
|
plan?: MonthlyPlan;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { LitElement, html, nothing, css, } from 'lit';
|
|
3
3
|
import { customElement, property, query } from 'lit/decorators.js';
|
|
4
|
-
import '@internetarchive/donation-form/dist/src/form-elements/contact-form/contact-form.js';
|
|
5
4
|
import '@internetarchive/donation-form-section';
|
|
6
5
|
let IauxMgcCancelPlan = class IauxMgcCancelPlan extends LitElement {
|
|
7
6
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/form-sections/cancel.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,IAAI,EAGJ,OAAO,EACP,GAAG,GACJ,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"cancel.js","sourceRoot":"","sources":["../../../src/form-sections/cancel.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,IAAI,EAGJ,OAAO,EACP,GAAG,GACJ,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAKnE,OAAO,wCAAwC,CAAC;AAGzC,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU;IAA1C;;QAGuC,0BAAqB,GAAG,IAAI,CAAC;QAE7B,yBAAoB,GAAG,KAAK,CAAC;IAsJ3E,CAAC;IAlJC,OAAO,CAAC,OAAuB;QAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,CAAQ;QAC3B,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,MAAM;;QACR,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CAAC,qBAAqB;eACnC,UAAU,IAAI,CAAC,MAAM,EAAE;;0BAEZ,CAAC,CAAQ,EAAE,QAAmB,EAAE,EAAE;YAChD,6CAA6C;YAC7C,QAAQ,CAAC,UAAU,GAAG,IAAI,CAAC;YAC3B,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;;;;KAIN,CAAC;IACJ,CAAC;;AAEM,wBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDlB,AAhDY,CAgDX;AAzJ0B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+CAAoB;AAEH;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gEAA8B;AAE7B;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;+DAA8B;AAE1D;IAAd,KAAK,CAAC,MAAM,CAAC;+CAAwB;AAP3B,iBAAiB;IAD7B,aAAa,CAAC,oBAAoB,CAAC;GACvB,iBAAiB,CA2J7B","sourcesContent":["import {\n LitElement,\n html,\n TemplateResult,\n PropertyValues,\n nothing,\n css,\n} from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport type { MonthlyPlan } from '../models/plan';\n\nimport type { MGCButton } from '../presentational/mgc-button';\n\nimport '@internetarchive/donation-form-section';\n\n@customElement('ia-mgc-cancel-plan')\nexport class IauxMgcCancelPlan extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n @property({ type: Boolean, reflect: true }) patronWantsToKeepPlan = true;\n\n @property({ type: Boolean, reflect: true }) initialCancelRequest = false;\n\n @query('form') form!: HTMLFormElement;\n\n updated(changed: PropertyValues) {\n if (changed.has('plan')) {\n console.log('plan updated', this.plan);\n }\n }\n\n async cancelThisPlan(e: Event) {\n e.preventDefault();\n this.patronWantsToKeepPlan = false;\n this.dispatchEvent(new Event('cancelPlan'));\n }\n\n get formId(): string {\n return `cancel-donation-form-${this.plan?.id}`;\n }\n\n protected render() {\n if (this.initialCancelRequest) {\n return this.confirmCancelation;\n }\n\n return html`\n <donation-form-section\n badgemode=\"hidebadge\"\n headline=\"Cancel recurring donation (requires confirmation)\"\n >\n <div class=\"warning\">\n <p>\n You can also pause your recurring donation by setting the next\n donation date up to 12 months in the future.\n </p>\n <ia-mgc-button\n class=\"link cancel\"\n .clickHandler=${(e: Event, iaButton: MGCButton) => {\n // eslint-disable-next-line no-param-reassign\n iaButton.isDisabled = true;\n if (this.initialCancelRequest) {\n this.initialCancelRequest = false;\n this.patronWantsToKeepPlan = true;\n return;\n }\n this.initialCancelRequest = true;\n }}\n >Let's cancel my donation</ia-mgc-button\n >\n </div>\n </donation-form-section>\n\n ${this.initialCancelRequest ? this.confirmCancelation : nothing}\n `;\n }\n\n get confirmCancelation(): TemplateResult | typeof nothing {\n return html`\n <section class=\"cancel-donation\">\n <donation-form-section badgemode=\"hidebadge\" headline=\"Cancel recurring donation\">\n\n <ia-mgc-button class='text exit-cancel' @click=${() => {\n this.initialCancelRequest = false;\n this.patronWantsToKeepPlan = true;\n }}>X</ia-mgc-button>\n\n <p>Canceling ends your monthly recurring donation to the Internet Archive, effective immediately. You will not be charged moving forward.</p>\n <p>Canceling does not affect your account or access to the Internet Archive, although you will no longer have access to any of the Monthly Giving Circle perks.</p>\n <p>If you have any questions regarding donations, contact us at <a href=\"mailto:donations@archive.org\">donations@archive.org</a></p>\n\n <form id=${this.formId} @submit=${(e: Event) => this.cancelThisPlan(e)}>\n <div class=\"checkbox-option-container\">\n <input\n id=${`confirm-${this.formId}`}\n type=\"checkbox\"\n required\n @change=${async (e: Event) => {\n e.preventDefault();\n this.patronWantsToKeepPlan = !(e.target as HTMLInputElement)\n .checked;\n await this.updateComplete;\n }}>\n <label for=${`confirm-${this.formId}`}><b>I'm sure I want to cancel my subscription</b></label>\n </div>\n\n <ia-mgc-button\n class=\"cancel\"\n .isDisabled=${this.patronWantsToKeepPlan}\n id=${`submit-${this.formId}`}\n type=\"submit\"\n .clickHandler=${(e: Event, iaButton: MGCButton) => {\n // eslint-disable-next-line no-param-reassign\n iaButton.isDisabled = true;\n this.cancelThisPlan(e);\n }}\n >I'm sure I want to cancel my recurring donation.</ia-mgc-button>\n </form>\n </section>\n `;\n }\n\n static styles = css`\n :host {\n --formSectionTitleFontSize: 1.4rem;\n }\n .warning > * {\n margin: 5px 0;\n }\n\n .cancel-donation {\n display: block;\n border: 2px solid #d9534f;\n background-color: #ffeeee;\n }\n\n .cancel-donation > * {\n padding: 5px;\n position: relative;\n }\n\n ia-mgc-button.exit-cancel {\n --button-border: 1px solid;\n --button-border-radius: 50%;\n position: absolute;\n top: -5px;\n right: -10px;\n }\n\n ia-mgc-button.link.cancel {\n --link-cancel-color: var(--mgc-warning-color-dark, #bb0505);\n }\n\n ia-mgc-button {\n --button-height: auto;\n }\n\n ia-mgc-button > * {\n text-align: left;\n text-wrap: wrap;\n }\n\n h3 {\n position: relative;\n }\n\n .checkbox-option-container {\n display: flex;\n margin: 10px 0;\n }\n `;\n}\n"]}
|
|
@@ -158,8 +158,8 @@ let MGCEditPlanDate = class MGCEditPlanDate extends LitElement {
|
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
// Check if there has been a donation in the last month
|
|
161
|
-
const lastDonationDate = ((_b = this.plan) === null || _b === void 0 ? void 0 : _b.payment.lastBillingDate.date)
|
|
162
|
-
? new Date(
|
|
161
|
+
const lastDonationDate = ((_b = this.plan) === null || _b === void 0 ? void 0 : _b.payment) && ((_c = this.plan.payment.lastBillingDate) === null || _c === void 0 ? void 0 : _c.date)
|
|
162
|
+
? new Date(this.plan.payment.lastBillingDate.date)
|
|
163
163
|
: null;
|
|
164
164
|
if (lastDonationDate) {
|
|
165
165
|
const lastDonationMonth = lastDonationDate.getMonth();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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AAK,CAAC,MAAM,CAAC;6CAAwB;AAEC;IAAtC,KAAK,CAAC,8BAA8B,CAAC;yDAA8B;AAGpE;IADC,KAAK,CAAC,8BAA8B,CAAC;kDACT;AAtBlB,eAAe;IAD3B,aAAa,CAAC,kBAAkB,CAAC;GACrB,eAAe,CAwW3B","sourcesContent":["import {\n LitElement,\n html,\n PropertyValues,\n nothing,\n css,\n TemplateResult,\n} from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport '@internetarchive/donation-form-section';\n\nimport type { MonthlyPlan } from '../models/plan';\nimport '../presentational/mgc-button';\nimport type { MGCButton } from '../presentational/mgc-button';\nimport '../presentational/mgc-update-status';\nimport '../presentational/donation-section-info';\n\ntype InvalidDateErrorCode =\n | 'invalid_date'\n | 'date_too_early'\n | 'second_donation_this_month'\n | 'date_out_of_range'\n | 'same_next_billing_date'\n | '';\n\nenum InvalidDateErrorMessages {\n invalid_date = 'Please enter a valid date format (YYYY-MM-DD)',\n date_too_early = 'Date must be at least tomorrow.',\n second_donation_this_month = 'The date you selected will result in an additional donation for this month.',\n date_out_of_range = 'New donation date must be within the next 12 months.',\n same_next_billing_date = '',\n}\n@customElement('ia-mgc-edit-date')\nexport class MGCEditPlanDate extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n @property({ type: String }) newDate?: string;\n\n @property({ type: Boolean, reflect: true }) currentlyEditing: boolean = false;\n\n @property({ type: Boolean }) allowEditing: boolean = false;\n\n @property({ type: String }) updateMessage: string = '';\n\n @property({ type: String }) errorMessage: string = '';\n\n @property({ type: String }) warningMessage: string = '';\n\n @property({ type: String }) updateStatus: 'success' | 'fail' | '' = '';\n\n @query('form') form!: HTMLFormElement;\n\n @query('form ia-mgc-button#edit-date') formSubmitButton!: MGCButton;\n\n @query('form input[name=\"edit-date\"]')\n dateInput!: HTMLInputElement;\n\n willUpdate(changed: PropertyValues) {\n if (this.dateInput && changed.has('plan') && this.plan) {\n this.dateInput.setAttribute('min', this.minDate);\n this.dateInput.setAttribute('max', this.maxDate);\n }\n }\n\n updated(changed: PropertyValues) {\n if (changed.has('currentlyEditing') && this.currentlyEditing) {\n this.dateInput.focus();\n }\n }\n\n protected render() {\n return html`\n <section>\n <donation-form-section\n badgemode=\"hidebadge\"\n headline=\"Change next donation date\"\n >\n ${!this.currentlyEditing\n ? html`<ia-mgc-form-section-info\n @editingRequested=${() => {\n this.currentlyEditing = true;\n this.clearStatusMessaging();\n }}\n ><span>${this.plan?.nextBillingDateLocale}</span>\n </ia-mgc-form-section-info>`\n : nothing}\n ${this.currentlyEditing ? this.editDateForm : nothing}\n </donation-form-section>\n </section>\n `;\n }\n\n /* External Function that is called by consumer to tell the form there has been data update */\n async dateUpdated(status: 'success' | 'fail') {\n this.clearInputField();\n\n this.updateStatus = status;\n this.updateMessage =\n status === 'success'\n ? 'Date updated'\n : 'Failed to update date, please try again';\n\n if (status === 'success') {\n this.closeForm();\n await this.updateComplete;\n return;\n }\n\n this.allowEditing = false;\n await this.updateComplete;\n }\n\n /* Dispatches edit-date change request */\n requestDateUpdate(e: Event): void {\n e.preventDefault();\n this.dispatchEvent(\n new CustomEvent('updateDate', {\n detail: {\n plan: this.plan,\n newDate: this.newDate,\n },\n }),\n );\n }\n\n closeForm() {\n this.clearInputField();\n this.clearStatusMessaging();\n this.currentlyEditing = false;\n this.allowEditing = false;\n }\n\n clearInputField() {\n this.dateInput.value = '';\n this.newDate = undefined;\n }\n\n formatDateToYYYYMMDD(date: Date): string {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed\n const dateNum = String(date.getDate()).padStart(2, '0');\n return `${year}-${month}-${dateNum}`;\n }\n\n async clearStatusMessaging() {\n this.errorMessage = '';\n this.warningMessage = '';\n this.updateMessage = '';\n this.updateStatus = '';\n await this.updateComplete;\n }\n\n /* @param string dateString - YYYYY-MM-DD */\n validateChosenDate(dateString: string): {\n valid: boolean;\n errorCode: InvalidDateErrorCode | '';\n } {\n if (!dateString) {\n return {\n valid: false,\n errorCode: 'invalid_date',\n };\n }\n\n let validDate;\n try {\n validDate = new Date(`${dateString}T00:00:00`);\n } catch (error) {\n return {\n valid: false,\n errorCode: 'invalid_date',\n };\n }\n\n // Check if minimum date is at least tomorrow\n const today = new Date();\n today.setHours(0, 0, 0, 0);\n const tomorrow = new Date(today);\n tomorrow.setDate(today.getDate() + 1); // Set to tomorrow\n\n const chosenDate = new Date(validDate);\n chosenDate.setHours(0, 0, 0, 0);\n\n // check input value against next billing date\n const isNextBillingDate = this.plan?.nextBillingDate\n ? this.formatDateToYYYYMMDD(new Date(this.plan.nextBillingDate)) ===\n this.formatDateToYYYYMMDD(chosenDate)\n : false;\n if (isNextBillingDate) {\n return {\n valid: false,\n errorCode: 'same_next_billing_date',\n };\n }\n\n if (chosenDate < today) {\n return {\n valid: false,\n errorCode: 'date_too_early',\n };\n }\n\n // Check if the new date is within the next 12 months\n const twelveMonthsFromNow = new Date(today);\n twelveMonthsFromNow.setFullYear(twelveMonthsFromNow.getFullYear() + 1);\n\n if (chosenDate > twelveMonthsFromNow) {\n return {\n valid: false,\n errorCode: 'date_out_of_range',\n };\n }\n\n // Check if there has been a donation in the last month\n const lastDonationDate = this.plan?.payment.lastBillingDate.date\n ? new Date(this.plan?.payment.lastBillingDate.date)\n : null;\n\n if (lastDonationDate) {\n const lastDonationMonth = lastDonationDate.getMonth();\n const lastDonationYear = lastDonationDate.getFullYear();\n\n const thisYear = validDate.getFullYear();\n const thisMonth = validDate.getMonth();\n const isInLastMonth =\n thisYear === lastDonationYear && thisMonth === lastDonationMonth;\n\n if (isInLastMonth) {\n return {\n valid: true,\n errorCode: 'second_donation_this_month',\n };\n }\n }\n\n return {\n valid: true,\n errorCode: '',\n };\n }\n\n /* DISPLAY */\n get minDate(): string {\n const today = new Date();\n const tomorrow = new Date(today);\n tomorrow.setDate(today.getDate() + 1); // Set to tomorrow\n const year = tomorrow.getFullYear();\n const month = String(tomorrow.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed\n const dateString = String(tomorrow.getDate()).padStart(2, '0');\n return `${year}-${month}-${dateString}`;\n }\n\n get maxDate(): string {\n const today = new Date();\n const year = today.getFullYear() + 1; // Allow up to one year in the future\n const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed\n const dateString = String(today.getDate()).padStart(2, '0');\n return `${year}-${month}-${dateString}`;\n }\n\n get editDateForm(): TemplateResult {\n const nextBillingDateYYYYMMDD = this.plan?.nextBillingDate\n ? this.formatDateToYYYYMMDD(new Date(this.plan.nextBillingDate))\n : '';\n const inputValueToUse = this.dateInput?.value ?? nextBillingDateYYYYMMDD;\n return html`\n <section>\n <form id=\"edit-date\">\n <p id=\"form-info-last-donation-date\">\n Last donation date: ${this.plan?.lastBillingDateLocale}\n </p>\n\n <p id=\"form-info-next-donation-date\">\n Next donation date: ${this.plan?.nextBillingDateLocale}\n </p>\n <div class=\"date-holder\">\n <input\n required\n type=\"date\"\n id=\"edit-date\"\n name=\"edit-date\"\n min=${this.minDate}\n max=${this.maxDate}\n .value=${inputValueToUse}\n @focus=${() => this.clearStatusMessaging()}\n @change=${async () => {\n this.clearStatusMessaging();\n await this.updateComplete;\n\n const inputValue = this.dateInput.value;\n const { valid, errorCode } =\n this.validateChosenDate(inputValue);\n\n this.allowEditing = valid;\n\n if (errorCode) {\n if (errorCode === 'second_donation_this_month') {\n this.errorMessage = InvalidDateErrorMessages[errorCode];\n this.warningMessage =\n 'You have already made a donation this month.';\n } else {\n this.errorMessage = InvalidDateErrorMessages[errorCode];\n this.newDate = undefined;\n return;\n }\n }\n\n const chosenDate = new Date(`${inputValue}T00:00:00`);\n const newDate = new Date(chosenDate).toISOString();\n this.newDate = newDate;\n }}\n />\n </div>\n <div>\n <div class=\"cta-container\">\n <ia-mgc-button\n class=\"ia-button secondary\"\n .clickHandler=${(e: Event) => {\n e.preventDefault();\n this.closeForm();\n }}\n >\n Cancel\n </ia-mgc-button>\n <ia-mgc-button\n id=\"edit-date\"\n class=\"ia-button primary\"\n type=\"submit\"\n .isDisabled=${!this.allowEditing}\n .clickHandler=${async (e: Event, iaButton: MGCButton) => {\n this.clearStatusMessaging();\n\n if (!this.newDate) {\n this.errorMessage = 'Please enter a valid date';\n return;\n }\n\n // eslint-disable-next-line no-param-reassign\n (iaButton as MGCButton).isDisabled = true;\n await iaButton.updateComplete;\n\n this.requestDateUpdate(e);\n }}\n >\n Update\n </ia-mgc-button>\n <ia-mgc-update-status .status=${this.updateStatus}\n >${this.updateMessage}</ia-mgc-update-status\n >\n </div>\n </div>\n <p class=\"error error-msg\">\n ${this.warningMessage\n ? html`<span>${this.warningMessage}</span><br />`\n : ''}\n ${this.errorMessage}\n </p>\n </form>\n </section>\n `;\n }\n\n static styles = css`\n input[name='edit-date'] {\n margin: 10px 0;\n min-width: 140px;\n font-family: inherit;\n }\n\n .cta-container {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-content: center;\n justify-content: flex-start;\n align-items: center;\n gap: 10px;\n }\n\n p.error {\n color: var(--mgc-warning-color-dark, #bb0505);\n }\n\n ia-mgc-update-status {\n display: inline-block;\n margin-left: 1rem;\n }\n\n .checkbox-option-container {\n margin: 10px 0;\n display: flex;\n }\n `;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/form-sections/date.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,IAAI,EAEJ,OAAO,EACP,GAAG,GAEJ,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,wCAAwC,CAAC;AAGhD,OAAO,8BAA8B,CAAC;AAEtC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,yCAAyC,CAAC;AAUjD,IAAK,wBAMJ;AAND,WAAK,wBAAwB;IAC3B,0FAA8D,CAAA;IAC9D,8EAAkD,CAAA;IAClD,sIAA0G,CAAA;IAC1G,sGAA0E,CAAA;IAC1E,u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AA,SAAS,IAAI,CAAC,cAAc,eAAe;YACjD,CAAC,CAAC,EAAE;cACJ,IAAI,CAAC,YAAY;;;;KAI1B,CAAC;IACJ,CAAC;;AAEM,sBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BlB,AA9BY,CA8BX;AAvW0B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAAoB;AAEnB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAAkB;AAED;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;yDAAmC;AAEjD;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;qDAA+B;AAE/B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAA4B;AAE3B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAA2B;AAE1B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uDAA6B;AAE5B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAA4C;AAExD;IAAd,KAAK,CAAC,MAAM,CAAC;6CAAwB;AAEC;IAAtC,KAAK,CAAC,8BAA8B,CAAC;yDAA8B;AAGpE;IADC,KAAK,CAAC,8BAA8B,CAAC;kDACT;AAtBlB,eAAe;IAD3B,aAAa,CAAC,kBAAkB,CAAC;GACrB,eAAe,CAyW3B","sourcesContent":["import {\n LitElement,\n html,\n PropertyValues,\n nothing,\n css,\n TemplateResult,\n} from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport '@internetarchive/donation-form-section';\n\nimport type { MonthlyPlan } from '../models/plan';\nimport '../presentational/mgc-button';\nimport type { MGCButton } from '../presentational/mgc-button';\nimport '../presentational/mgc-update-status';\nimport '../presentational/donation-section-info';\n\ntype InvalidDateErrorCode =\n | 'invalid_date'\n | 'date_too_early'\n | 'second_donation_this_month'\n | 'date_out_of_range'\n | 'same_next_billing_date'\n | '';\n\nenum InvalidDateErrorMessages {\n invalid_date = 'Please enter a valid date format (YYYY-MM-DD)',\n date_too_early = 'Date must be at least tomorrow.',\n second_donation_this_month = 'The date you selected will result in an additional donation for this month.',\n date_out_of_range = 'New donation date must be within the next 12 months.',\n same_next_billing_date = '',\n}\n@customElement('ia-mgc-edit-date')\nexport class MGCEditPlanDate extends LitElement {\n @property({ type: Object }) plan?: MonthlyPlan;\n\n @property({ type: String }) newDate?: string;\n\n @property({ type: Boolean, reflect: true }) currentlyEditing: boolean = false;\n\n @property({ type: Boolean }) allowEditing: boolean = false;\n\n @property({ type: String }) updateMessage: string = '';\n\n @property({ type: String }) errorMessage: string = '';\n\n @property({ type: String }) warningMessage: string = '';\n\n @property({ type: String }) updateStatus: 'success' | 'fail' | '' = '';\n\n @query('form') form!: HTMLFormElement;\n\n @query('form ia-mgc-button#edit-date') formSubmitButton!: MGCButton;\n\n @query('form input[name=\"edit-date\"]')\n dateInput!: HTMLInputElement;\n\n willUpdate(changed: PropertyValues) {\n if (this.dateInput && changed.has('plan') && this.plan) {\n this.dateInput.setAttribute('min', this.minDate);\n this.dateInput.setAttribute('max', this.maxDate);\n }\n }\n\n updated(changed: PropertyValues) {\n if (changed.has('currentlyEditing') && this.currentlyEditing) {\n this.dateInput.focus();\n }\n }\n\n protected render() {\n return html`\n <section>\n <donation-form-section\n badgemode=\"hidebadge\"\n headline=\"Change next donation date\"\n >\n ${!this.currentlyEditing\n ? html`<ia-mgc-form-section-info\n @editingRequested=${() => {\n this.currentlyEditing = true;\n this.clearStatusMessaging();\n }}\n ><span>${this.plan?.nextBillingDateLocale}</span>\n </ia-mgc-form-section-info>`\n : nothing}\n ${this.currentlyEditing ? this.editDateForm : nothing}\n </donation-form-section>\n </section>\n `;\n }\n\n /* External Function that is called by consumer to tell the form there has been data update */\n async dateUpdated(status: 'success' | 'fail') {\n this.clearInputField();\n\n this.updateStatus = status;\n this.updateMessage =\n status === 'success'\n ? 'Date updated'\n : 'Failed to update date, please try again';\n\n if (status === 'success') {\n this.closeForm();\n await this.updateComplete;\n return;\n }\n\n this.allowEditing = false;\n await this.updateComplete;\n }\n\n /* Dispatches edit-date change request */\n requestDateUpdate(e: Event): void {\n e.preventDefault();\n this.dispatchEvent(\n new CustomEvent('updateDate', {\n detail: {\n plan: this.plan,\n newDate: this.newDate,\n },\n }),\n );\n }\n\n closeForm() {\n this.clearInputField();\n this.clearStatusMessaging();\n this.currentlyEditing = false;\n this.allowEditing = false;\n }\n\n clearInputField() {\n this.dateInput.value = '';\n this.newDate = undefined;\n }\n\n formatDateToYYYYMMDD(date: Date): string {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed\n const dateNum = String(date.getDate()).padStart(2, '0');\n return `${year}-${month}-${dateNum}`;\n }\n\n async clearStatusMessaging() {\n this.errorMessage = '';\n this.warningMessage = '';\n this.updateMessage = '';\n this.updateStatus = '';\n await this.updateComplete;\n }\n\n /* @param string dateString - YYYYY-MM-DD */\n validateChosenDate(dateString: string): {\n valid: boolean;\n errorCode: InvalidDateErrorCode | '';\n } {\n if (!dateString) {\n return {\n valid: false,\n errorCode: 'invalid_date',\n };\n }\n\n let validDate;\n try {\n validDate = new Date(`${dateString}T00:00:00`);\n } catch (error) {\n return {\n valid: false,\n errorCode: 'invalid_date',\n };\n }\n\n // Check if minimum date is at least tomorrow\n const today = new Date();\n today.setHours(0, 0, 0, 0);\n const tomorrow = new Date(today);\n tomorrow.setDate(today.getDate() + 1); // Set to tomorrow\n\n const chosenDate = new Date(validDate);\n chosenDate.setHours(0, 0, 0, 0);\n\n // check input value against next billing date\n const isNextBillingDate = this.plan?.nextBillingDate\n ? this.formatDateToYYYYMMDD(new Date(this.plan.nextBillingDate)) ===\n this.formatDateToYYYYMMDD(chosenDate)\n : false;\n if (isNextBillingDate) {\n return {\n valid: false,\n errorCode: 'same_next_billing_date',\n };\n }\n\n if (chosenDate < today) {\n return {\n valid: false,\n errorCode: 'date_too_early',\n };\n }\n\n // Check if the new date is within the next 12 months\n const twelveMonthsFromNow = new Date(today);\n twelveMonthsFromNow.setFullYear(twelveMonthsFromNow.getFullYear() + 1);\n\n if (chosenDate > twelveMonthsFromNow) {\n return {\n valid: false,\n errorCode: 'date_out_of_range',\n };\n }\n\n // Check if there has been a donation in the last month\n const lastDonationDate =\n this.plan?.payment && this.plan.payment.lastBillingDate?.date\n ? new Date(this.plan.payment.lastBillingDate.date)\n : null;\n\n if (lastDonationDate) {\n const lastDonationMonth = lastDonationDate.getMonth();\n const lastDonationYear = lastDonationDate.getFullYear();\n\n const thisYear = validDate.getFullYear();\n const thisMonth = validDate.getMonth();\n const isInLastMonth =\n thisYear === lastDonationYear && thisMonth === lastDonationMonth;\n\n if (isInLastMonth) {\n return {\n valid: true,\n errorCode: 'second_donation_this_month',\n };\n }\n }\n\n return {\n valid: true,\n errorCode: '',\n };\n }\n\n /* DISPLAY */\n get minDate(): string {\n const today = new Date();\n const tomorrow = new Date(today);\n tomorrow.setDate(today.getDate() + 1); // Set to tomorrow\n const year = tomorrow.getFullYear();\n const month = String(tomorrow.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed\n const dateString = String(tomorrow.getDate()).padStart(2, '0');\n return `${year}-${month}-${dateString}`;\n }\n\n get maxDate(): string {\n const today = new Date();\n const year = today.getFullYear() + 1; // Allow up to one year in the future\n const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed\n const dateString = String(today.getDate()).padStart(2, '0');\n return `${year}-${month}-${dateString}`;\n }\n\n get editDateForm(): TemplateResult {\n const nextBillingDateYYYYMMDD = this.plan?.nextBillingDate\n ? this.formatDateToYYYYMMDD(new Date(this.plan.nextBillingDate))\n : '';\n const inputValueToUse = this.dateInput?.value ?? nextBillingDateYYYYMMDD;\n return html`\n <section>\n <form id=\"edit-date\">\n <p id=\"form-info-last-donation-date\">\n Last donation date: ${this.plan?.lastBillingDateLocale}\n </p>\n\n <p id=\"form-info-next-donation-date\">\n Next donation date: ${this.plan?.nextBillingDateLocale}\n </p>\n <div class=\"date-holder\">\n <input\n required\n type=\"date\"\n id=\"edit-date\"\n name=\"edit-date\"\n min=${this.minDate}\n max=${this.maxDate}\n .value=${inputValueToUse}\n @focus=${() => this.clearStatusMessaging()}\n @change=${async () => {\n this.clearStatusMessaging();\n await this.updateComplete;\n\n const inputValue = this.dateInput.value;\n const { valid, errorCode } =\n this.validateChosenDate(inputValue);\n\n this.allowEditing = valid;\n\n if (errorCode) {\n if (errorCode === 'second_donation_this_month') {\n this.errorMessage = InvalidDateErrorMessages[errorCode];\n this.warningMessage =\n 'You have already made a donation this month.';\n } else {\n this.errorMessage = InvalidDateErrorMessages[errorCode];\n this.newDate = undefined;\n return;\n }\n }\n\n const chosenDate = new Date(`${inputValue}T00:00:00`);\n const newDate = new Date(chosenDate).toISOString();\n this.newDate = newDate;\n }}\n />\n </div>\n <div>\n <div class=\"cta-container\">\n <ia-mgc-button\n class=\"ia-button secondary\"\n .clickHandler=${(e: Event) => {\n e.preventDefault();\n this.closeForm();\n }}\n >\n Cancel\n </ia-mgc-button>\n <ia-mgc-button\n id=\"edit-date\"\n class=\"ia-button primary\"\n type=\"submit\"\n .isDisabled=${!this.allowEditing}\n .clickHandler=${async (e: Event, iaButton: MGCButton) => {\n this.clearStatusMessaging();\n\n if (!this.newDate) {\n this.errorMessage = 'Please enter a valid date';\n return;\n }\n\n // eslint-disable-next-line no-param-reassign\n (iaButton as MGCButton).isDisabled = true;\n await iaButton.updateComplete;\n\n this.requestDateUpdate(e);\n }}\n >\n Update\n </ia-mgc-button>\n <ia-mgc-update-status .status=${this.updateStatus}\n >${this.updateMessage}</ia-mgc-update-status\n >\n </div>\n </div>\n <p class=\"error error-msg\">\n ${this.warningMessage\n ? html`<span>${this.warningMessage}</span><br />`\n : ''}\n ${this.errorMessage}\n </p>\n </form>\n </section>\n `;\n }\n\n static styles = css`\n input[name='edit-date'] {\n margin: 10px 0;\n min-width: 140px;\n font-family: inherit;\n }\n\n .cta-container {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-content: center;\n justify-content: flex-start;\n align-items: center;\n gap: 10px;\n }\n\n p.error {\n color: var(--mgc-warning-color-dark, #bb0505);\n }\n\n ia-mgc-update-status {\n display: inline-block;\n margin-left: 1rem;\n }\n\n .checkbox-option-container {\n margin: 10px 0;\n display: flex;\n }\n `;\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LitElement, CSSResult, PropertyValueMap } from 'lit';
|
|
2
|
+
import { BraintreeManagerInterface, HostingEnvironment } from '@internetarchive/donation-form';
|
|
3
|
+
import type { BraintreeEndpointManagerInterface } from '@internetarchive/donation-form/dist/src/braintree-manager/braintree-interfaces.js';
|
|
4
|
+
import type { PaymentClientsInterface } from '@internetarchive/donation-form/dist/src/braintree-manager/payment-clients.js';
|
|
5
|
+
import type { MonthlyPlan } from '../../models/plan';
|
|
6
|
+
type PaymentConfig = {
|
|
7
|
+
braintreeAuthToken?: string;
|
|
8
|
+
endpointManager?: BraintreeEndpointManagerInterface;
|
|
9
|
+
paymentClients?: PaymentClientsInterface;
|
|
10
|
+
environment?: HostingEnvironment;
|
|
11
|
+
venmoProfileId?: string;
|
|
12
|
+
googlePayMerchantId?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare class MGCBraintreeManager extends LitElement {
|
|
15
|
+
plan?: MonthlyPlan;
|
|
16
|
+
displayCreditCard: boolean;
|
|
17
|
+
patronEmail: string;
|
|
18
|
+
paymentConfig?: PaymentConfig;
|
|
19
|
+
braintreeManager?: BraintreeManagerInterface;
|
|
20
|
+
private elementConnected;
|
|
21
|
+
get braintreeInputs(): {
|
|
22
|
+
errorMessage: HTMLDivElement | null;
|
|
23
|
+
number: HTMLDivElement | null;
|
|
24
|
+
cvv: HTMLDivElement | null;
|
|
25
|
+
expirationDate: HTMLDivElement | null;
|
|
26
|
+
};
|
|
27
|
+
createRenderRoot(): this;
|
|
28
|
+
disconnectedCallback(): void;
|
|
29
|
+
connectedCallback(): void;
|
|
30
|
+
protected updated(changed: PropertyValueMap<any> | Map<PropertyKey, unknown>): void;
|
|
31
|
+
validateCreditCardFields(): Promise<any>;
|
|
32
|
+
setupCreditCardHandler(): Promise<void>;
|
|
33
|
+
render(): import("lit").TemplateResult<1>;
|
|
34
|
+
lightDomCSS(): CSSResult;
|
|
35
|
+
get creditCardTemplate(): import("lit").TemplateResult<1>;
|
|
36
|
+
private setupBraintreeManager;
|
|
37
|
+
get contactForm(): HTMLFormElement | null;
|
|
38
|
+
setupPaymentHandlers(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|