Skip to content

Commit 748708a

Browse files
authored
Edit Date & Cancel (#23)
1 parent d48499b commit 748708a

File tree

11 files changed

+768
-20
lines changed

11 files changed

+768
-20
lines changed

demo/index.html

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
max-width: 800px;
6060
}
6161
</style>
62-
<ia-monthly-giving-circle></ia-monthly-giving-circle>
62+
<ia-monthly-giving-circle canEdit></ia-monthly-giving-circle>
6363
</div>
6464

6565
<script type="module" src="../dist/src/monthly-giving-circle.js"></script>
@@ -68,6 +68,42 @@
6868

6969
let updateNotices = [];
7070

71+
const nextPaymentIn25Days = new Date();
72+
nextPaymentIn25Days.setDate(nextPaymentIn25Days.getDate() + 25);
73+
nextPaymentIn25Days.setMinutes(0);
74+
nextPaymentIn25Days.setSeconds(0);
75+
nextPaymentIn25Days.setMilliseconds(0);
76+
console.log('nextPaymentIn25Days', nextPaymentIn25Days.toISOString());
77+
78+
const lastPaymentInTheSameMonth = new Date();
79+
lastPaymentInTheSameMonth.setMinutes(0);
80+
lastPaymentInTheSameMonth.setSeconds(0);
81+
lastPaymentInTheSameMonth.setMilliseconds(0);
82+
lastPaymentInTheSameMonth.setDate(1);
83+
console.log('lastPaymentInTheSameMonth', lastPaymentInTheSameMonth.toISOString());
84+
85+
const nextMonth = new Date();
86+
nextMonth.setMonth(nextMonth.getMonth() + 1);
87+
88+
const nextPaymentFirstOfMonth = new Date(nextMonth);
89+
nextPaymentFirstOfMonth.setMinutes(0);
90+
nextPaymentFirstOfMonth.setSeconds(0);
91+
nextPaymentFirstOfMonth.setMilliseconds(0);
92+
nextPaymentFirstOfMonth.setDate(1);
93+
console.log('nextPaymentFirstOfMonth', nextPaymentFirstOfMonth.toISOString());
94+
95+
const today = new Date();
96+
today.setHours(0, 0, 0, 0);
97+
98+
const lastMonth = new Date();
99+
lastMonth.setHours(0, 0, 0, 0);
100+
lastMonth.setDate(0);
101+
102+
const lastDayOfCurrentMonth = new Date();
103+
lastDayOfCurrentMonth.setHours(0, 0, 0, 0);
104+
lastDayOfCurrentMonth.setMonth(lastDayOfCurrentMonth.getMonth() + 1);
105+
lastDayOfCurrentMonth.setDate(0);
106+
71107
const plans = {
72108
"41": {
73109
"token": "Acbdcdcadsfdasf.1234alphanumeric.3foobarXyZ",
@@ -76,8 +112,13 @@
76112
"is_test": true,
77113
"btdata": {
78114
"billingDayOfMonth": 22,
115+
"lastBillingDate": {
116+
"date": lastMonth.toISOString(),
117+
"timezone_type": 3,
118+
"timezone": "UTC"
119+
},
79120
"nextBillingDate": {
80-
"date": "2024-08-22 00:00:00.000000",
121+
"date": lastDayOfCurrentMonth.toISOString(),
81122
"timezone_type": 3,
82123
"timezone": "UTC"
83124
},
@@ -97,8 +138,13 @@
97138
"is_test": true,
98139
"btdata": {
99140
"billingDayOfMonth": 9,
141+
"lastBillingDate": {
142+
"date": lastPaymentInTheSameMonth.toISOString(),
143+
"timezone_type": 3,
144+
"timezone": "UTC"
145+
},
100146
"nextBillingDate": {
101-
"date": "2024-09-09 00:00:00.000000",
147+
"date": nextPaymentFirstOfMonth.toISOString(),
102148
"timezone_type": 3,
103149
"timezone": "UTC"
104150
},
@@ -278,6 +324,39 @@
278324
}, returnTiming);
279325
})
280326

327+
mgcComponent.addEventListener('updateDate', (e) => {
328+
const { newDate, plan } = e.detail;
329+
330+
331+
const heads = coinFlip() === 1;
332+
const successOrFail = heads ? 'success' : 'fail';
333+
const returnTiming = heads ? 3000 : 8000;
334+
335+
uxMessageInfoArea.innerText = `Updating next billing date for plan: ${newDate}, plan: ${JSON.stringify(plan.id)} -- Update will return ${successOrFail} in ${returnTiming} ms`;
336+
const message = successOrFail === 'success' ? 'Date updated' : 'Date failed to update';
337+
338+
if (heads) {
339+
plan.setNextBillingDate(newDate);
340+
}
341+
342+
const update = {
343+
message,
344+
status: successOrFail,
345+
plan,
346+
donationId: plan.id,
347+
action: 'dateUpdate'
348+
};
349+
350+
updateNotices = [update, ...updateNotices];
351+
352+
353+
setTimeout(() => {
354+
mgcComponent.updateReceived(update);
355+
console.log('Amount Update Request --- index.html ----', update);
356+
uxMessageInfoArea.innerText = '';
357+
}, returnTiming);
358+
});
359+
281360
// options hooks
282361
document.getElementById('toggle-receipts').addEventListener('click', async () => {
283362
if (showReceipts) {

src/edit-plan-form.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { LitElement, html } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33

44
import type { MonthlyPlan } from './models/plan';
5-
import './form-sections/cancel';
65
import './form-sections/amount';
6+
import './form-sections/date';
7+
import './form-sections/cancel';
78
import type { MGCEditPlanAmount } from './form-sections/amount';
9+
import type { MGCEditPlanDate } from './form-sections/date';
810

911
@customElement('ia-mgc-edit-plan')
1012
export class IauxEditPlanForm extends LitElement {
1113
@property({ type: Object }) plan?: MonthlyPlan;
1214

13-
@property({ type: Object }) cancelPlanHandler?: (plan: MonthlyPlan) => void;
14-
1515
@property({ type: Object }) updateAmountHandler?: (
1616
plan: MonthlyPlan,
1717
amountUpdates: {
@@ -33,6 +33,11 @@ export class IauxEditPlanForm extends LitElement {
3333
amountForm!.amountUpdated(status);
3434
}
3535

36+
dateUpdates(status: 'success' | 'fail') {
37+
const dateForm = this.querySelector('ia-mgc-edit-date') as MGCEditPlanDate;
38+
dateForm!.dateUpdated(status);
39+
}
40+
3641
render() {
3742
return html`
3843
<section class="mgc-edit-plan">
@@ -51,6 +56,27 @@ export class IauxEditPlanForm extends LitElement {
5156
}}
5257
></ia-mgc-edit-plan-amount>
5358
<hr />
59+
<ia-mgc-edit-date
60+
@updateDate=${(e: CustomEvent) => {
61+
const { newDate } = e.detail;
62+
if (this.plan) {
63+
this.dispatchEvent(
64+
new CustomEvent('updateDate', {
65+
detail: { plan: this.plan, newDate },
66+
})
67+
);
68+
}
69+
}}
70+
.plan=${this.plan}
71+
></ia-mgc-edit-date>
72+
<hr />
73+
<ia-mgc-cancel-plan
74+
.plan=${this.plan}
75+
@cancelPlan=${() => {
76+
this.dispatchEvent(new Event('cancelPlan'));
77+
}}
78+
></ia-mgc-cancel-plan>
79+
<hr />
5480
<p class="email-edit-plan">
5581
Need to update your plan further? Please email us at
5682
<a href=${this.mailToText}>[email protected]</a>.

src/form-sections/amount.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ export class MGCEditPlanAmount extends LitElement {
223223
<div>
224224
$
225225
<input
226+
min="1"
227+
max="9999"
226228
type="number"
227229
id="amount"
228230
name="amount"

0 commit comments

Comments
 (0)