Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

receipts view #15

Merged
merged 37 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e17e948
receipts view
iisa Dec 13, 2024
66e8fe8
format date & view
iisa Dec 13, 2024
411cbba
css target host class
iisa Dec 16, 2024
ad736f7
update button class
iisa Dec 16, 2024
55438ef
lint
iisa Dec 16, 2024
a289808
current ver
iisa Dec 16, 2024
e424260
update messaging
iisa Dec 16, 2024
8a83322
demo clears updates
iisa Dec 16, 2024
fc5c59d
v0.0.0-receipts5
iisa Dec 16, 2024
a419eda
import notif toast
iisa Dec 23, 2024
0bf2bae
add update queue
iisa Dec 23, 2024
7ef2da0
receipts6
iisa Dec 23, 2024
a4aa75f
typo
iisa Dec 23, 2024
7bd48cd
recipts7
iisa Dec 23, 2024
1d1c766
show receipts event
iisa Dec 23, 2024
0d868e3
show welcome event
iisa Dec 23, 2024
ede4017
receipts9
iisa Dec 23, 2024
ad0a6d9
cta text change
iisa Dec 23, 2024
d1efc59
receipts10
iisa Dec 23, 2024
54a42ac
receipt sending status now in-line.
iisa Jan 2, 2025
4fdeac9
fix padding
iisa Jan 2, 2025
361fee6
receipts toggling in demo with sent notifs firing
iisa Jan 3, 2025
d8e2e2c
format
iisa Jan 3, 2025
dcfdb34
indent
iisa Jan 3, 2025
1b0d584
main unit test
iisa Jan 3, 2025
b71b4aa
better receipt table
iisa Jan 8, 2025
c249056
test receipt flow
iisa Jan 9, 2025
40585a0
receipt model
iisa Jan 13, 2025
9ee6994
export receipts
iisa Jan 13, 2025
fad4554
move return button towards title
iisa Jan 17, 2025
aa162c0
receipts obj
iisa Jan 17, 2025
9c4eba2
iaux-button element + receipt request flow test updates
iisa Jan 27, 2025
0898ebf
escape id
iisa Jan 27, 2025
d2c8179
use class as type for receipt
iisa Jan 27, 2025
ec2752c
cleanup, from code review
iisa Jan 30, 2025
ca7bd1d
update receipt class, to handle total display
iisa Jan 30, 2025
6dc1d01
fix casing
iisa Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,123 @@
</header>
<div class="dev-tools">
<div id="options">
<button id="toggle-receipts">Toggle receipts</button>
<button id="toggle-buttons">Toggle button types</button>

<p id="interaction-status-area" style="min-height: 50px;margin: 10px;"></p>
</div>
</div>

<div id="demo">
<style>
iaux-monthly-giving-circle {
display: block;
margin: 0 auto;
max-width: 800px;
}
</style>
<iaux-monthly-giving-circle></iaux-monthly-giving-circle>
</div>

<script type="module" src="../dist/src/monthly-giving-circle.js"></script>
<script type="module">
import { Receipt } from '../dist/src/models/receipt.js';

let updateNotices = [];

const receiptsData = [
iisa marked this conversation as resolved.
Show resolved Hide resolved
new Receipt({
amount: 9999.99,
date: (new Date('2019-01-22 14:26:34')).toLocaleString('US-EN', {
year: 'numeric',
month: 'short',
day: 'numeric',
}),
donor: 'John Doe',
paymentMethod: 'Credit Card',
status: 'Completed',
id: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJtYWlsc3luYyIsImlhdCI6MTczNzk3MTgyNy45MDY1NDksIm5iZiI6MTczNzk3MTc2Ny45MDY1NDksImV4cCI6MTczNzk3MjQyNy45MDY1NDksImtleSI6IjEwOTY4MjEiLCJ1c2VyIjoiQGlzYS1hdC10aGUtYXJjaGl2ZSJ9.pMbayUlFgRhm3wDoJG1IPoltliTHDq0xH2W369JtdQA',
token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJtYWlsc3luYyIsImlhdCI6MTczNzk3MTgyNy45MDY1NDksIm5iZiI6MTczNzk3MTc2Ny45MDY1NDksImV4cCI6MTczNzk3MjQyNy45MDY1NDksImtleSI6IjEwOTY4MjEiLCJ1c2VyIjoiQGlzYS1hdC10aGUtYXJjaGl2ZSJ9.pMbayUlFgRhm3wDoJG1IPoltliTHDq0xH2W369JtdQA',
isTest: false,
}),
new Receipt({
amount: 100,
date: (new Date('2022-09-22 14:26:34')).toLocaleString('US-EN', {
year: 'numeric',
month: 'short',
day: 'numeric',
}),
donor: 'John Doe',
paymentMethod: 'Credit Card',
status: 'Completed',
id: 'foo-id-2',
token: 'foo-token-2',
isTest: true,
}),
new Receipt({
amount: 100,
date: (new Date('2023-12-23 14:26:34')).toLocaleString('US-EN', {
year: 'numeric',
month: 'short',
day: 'numeric',
}),
donor: 'John Doe',
paymentMethod: 'Credit Card',
status: 'Completed',
id: 'foo-id-3',
token: 'foo-token-3',
isTest: false,
}),
];


let showReceipts = true;

const mgcComponent = document.querySelector('iaux-monthly-giving-circle');

// load start data
mgcComponent.receipts = receiptsData;

// event handlers
mgcComponent.addEventListener('EmailReceiptRequest', (e) => {
const uxMessageInfoArea = document.getElementById('interaction-status-area');

const { donation } = e.detail;
const randomizer = Math.floor(Math.random() + 0.5);
const successOrFail = randomizer === 1 ? 'success' : 'fail';
const returnTiming = randomizer === 1 ? 3000 : 8000;

uxMessageInfoArea.innerText = `Email receipt request for donation ${donation.id} will return ${successOrFail} in ${returnTiming} ms.`;

const message = successOrFail === 'success' ? 'Email receipt sent' : 'Email receipt failed';

const update = {
message,
status: successOrFail,
donationId: donation.id
};

updateNotices = [update, ...updateNotices];

setTimeout(() => {
mgcComponent.updateReceived(update);
console.log('EmailReceiptRequest index.html ----', update);

Check warning on line 140 in demo/index.html

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
uxMessageInfoArea.innerText = '';
}, returnTiming);
});

// options hooks
document.getElementById('toggle-receipts').addEventListener('click', async () => {
if (showReceipts) {
mgcComponent.receipts = [];
showReceipts = false;
return;
}
mgcComponent.receipts = receiptsData;
await mgcComponent.updateComplete;

showReceipts = true;
});
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { MonthlyGivingCircle } from './src/monthly-giving-circle';
export type { anUpdate } from './src/monthly-giving-circle';
export { Receipt } from './src/models/receipt';
17 changes: 14 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@internetarchive/donation-monthly-portal",
"version": "1.0.0",
"version": "0.0.0-receipts10",
"description": "The Internet Archive Monthly Portal",
"license": "AGPL-3.0-only",
"main": "dist/index.js",
Expand All @@ -27,6 +27,7 @@
"ghpages:generate": "gh-pages -t -d ghpages -m \"Build for $(git log --pretty=format:\"%h %an %ai %s\" -n1) [skip ci]\""
},
"dependencies": {
"@internetarchive/iaux-notification-toast": "^0.0.0-alpha2",
"@internetarchive/icon-donate": "^1.3.4",
"lit": "^2.8.0"
},
Expand All @@ -52,7 +53,7 @@
"madge": "^6.0.0",
"prettier": "^2.7.1",
"rimraf": "^5.0.0",
"sinon": "^17.0.0",
"sinon": "^17.0.1",
"ts-lit-plugin": "^2.0.0",
"tslib": "^2.7.0",
"typescript": "^4.7.4",
Expand Down
26 changes: 26 additions & 0 deletions src/models/receipt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type aReceipt = {
id: string;
amount: number;
date: string;
isTest: boolean;
token: string;
};
iisa marked this conversation as resolved.
Show resolved Hide resolved
export class Receipt {
iisa marked this conversation as resolved.
Show resolved Hide resolved
id: string;

amount: number;

date: string;

isTest: boolean;

token: string;

constructor(receipt: aReceipt) {
this.id = receipt.id;
this.amount = receipt.amount;
this.date = receipt.date;
this.isTest = receipt.isTest;
this.token = receipt.token;
}
}
86 changes: 84 additions & 2 deletions src/monthly-giving-circle.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,104 @@
/* eslint-disable no-debugger */

import { LitElement, html } from 'lit';
import { LitElement, html, TemplateResult, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';

import './welcome-message';
import './presentational/mgc-title';
import './receipts';
import type { IauxMgcReceipts } from './receipts';
import './presentational/iaux-button';

export type anUpdate = {
message: string;
status: 'success' | 'fail';
donationId: string;
};

@customElement('iaux-monthly-giving-circle')
iisa marked this conversation as resolved.
Show resolved Hide resolved
export class MonthlyGivingCircle extends LitElement {
@property({ type: String }) patronName: string = '';

@property({ type: Array }) receipts = [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can become

@property({ type: Array }) receipts: aReceipt[] = [];

so TS knows the type of data its working with and help the developer out during development.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catch, will update. i will keep class and decorate this list


@property({ type: Array }) updates: anUpdate[] = [];

@property({ type: String, reflect: true }) viewToDisplay:
| 'welcome'
| 'receipts' = 'welcome';

protected createRenderRoot() {
return this;
}

get receiptListElement(): IauxMgcReceipts {
return this.querySelector('iaux-mgc-receipts') as IauxMgcReceipts;
}
iisa marked this conversation as resolved.
Show resolved Hide resolved

updateReceived(update: anUpdate) {
this.receiptListElement.emailSent({
id: update.donationId,
emailStatus: update.status,
});
this.updates.unshift(update);
}

get showReceiptsCTA(): TemplateResult {
return html`
<iaux-button
class="link"
style="--button-padding: 0;"
.clickHandler=${() => {
this.viewToDisplay = 'receipts';
this.dispatchEvent(new CustomEvent('ShowReceipts'));
}}
>
View recent donation history
</iaux-button>
`;
}

protected render() {
if (this.viewToDisplay === 'receipts') {
iisa marked this conversation as resolved.
Show resolved Hide resolved
return html`
<iaux-mgc-title titleStyle="default">
<span slot="title">Recent donations</span>
<span slot="action">
<iaux-button
class="link slim"
id="close-receipts"
.clickHandler=${async () => {
this.viewToDisplay = 'welcome';
this.dispatchEvent(new CustomEvent('ShowWelcome'));
this.updates = [];
await this.updateComplete;
}}
>
Back to account settings
</iaux-button>
</span>
</iaux-mgc-title>
<iaux-mgc-receipts
.receipts=${this.receipts}
@EmailReceiptRequest=${(event: CustomEvent) => {
console.log('EmailReceiptRequest', event.detail);

Check warning on line 84 in src/monthly-giving-circle.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
this.dispatchEvent(
new CustomEvent('EmailReceiptRequest', {
detail: { ...event.detail },
})
);
}}
></iaux-mgc-receipts>
`;
}

return html`
<iaux-mgc-title titleStyle="heart"></iaux-mgc-title>
<iaux-mgc-title titleStyle="heart">
<span slot="title">Monthly Giving Circle</span>
<span slot="action"
>${this.receipts.length ? this.showReceiptsCTA : nothing}</span
>
</iaux-mgc-title>
<iaux-mgc-welcome .patronName=${this.patronName}></iaux-mgc-welcome>
`;
}
Expand Down
Loading
Loading