-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
receipts view #15
Changes from 29 commits
e17e948
66e8fe8
411cbba
ad736f7
55438ef
a289808
e424260
8a83322
fc5c59d
a419eda
0bf2bae
7ef2da0
a4aa75f
7bd48cd
1d1c766
0d868e3
ede4017
ad0a6d9
d1efc59
54a42ac
4fdeac9
361fee6
d8e2e2c
dcfdb34
1b0d584
b71b4aa
c249056
40585a0
9ee6994
fad4554
aa162c0
9c4eba2
0898ebf
d2c8179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export { MonthlyGivingCircle } from './src/monthly-giving-circle'; | ||
export type { anUpdate } from './src/monthly-giving-circle'; | ||
export type { aReceipt } from './src/models/receipt'; | ||
export { Receipt } from './src/models/receipt'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export type aReceipt = { | ||
id: string; | ||
amount: number; | ||
date: string; | ||
isTest: boolean; | ||
token: string; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at your demo data, it looks like you're missing |
||
export class Receipt { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you have the separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah ok, leaving it as internal since that is where it really is only used. other references point to the class - commit here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I mean, do you need the class at all since it's just defining the shape of the data? Where you're doing
you can just replace it with
The type is telling typescript everything it needs to know about the receipt. You really only need an extra class if you need extra functionality in the class, which you're not doing in It's also lighter-weight than defining a class. Classes have to be added to the runtime javascript, instantiated and stored in memory, whereas a |
||
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,107 @@ | ||
/* 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/button-style'; | ||
|
||
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 = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can become
so TS knows the type of data its working with and help the developer out during development. |
||
|
||
@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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the
Also, it's optional since you have that conditional of whether to display it or not. |
||
|
||
updateReceived(update: anUpdate) { | ||
this.receiptListElement.emailSent({ | ||
id: update.donationId, | ||
emailStatus: update.status, | ||
}); | ||
this.updates.unshift(update); | ||
} | ||
|
||
get showReceiptsCTA(): TemplateResult { | ||
return html` | ||
<iaux-button-style class="link"> | ||
<button | ||
@click=${() => { | ||
this.viewToDisplay = 'receipts'; | ||
this.dispatchEvent(new CustomEvent('ShowReceipts')); | ||
}} | ||
> | ||
View recent donation history | ||
</button> | ||
</iaux-button-style> | ||
`; | ||
} | ||
|
||
protected render() { | ||
if (this.viewToDisplay === 'receipts') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar suggestion about breaking up this render method to make it easier to read. I didn't notice there are two different versions here that you can display. ie:
|
||
return html` | ||
<iaux-mgc-title titleStyle="default"> | ||
<span slot="title">Recent donations</span> | ||
<span slot="action"> | ||
<iaux-button-style class="link"> | ||
<button | ||
class="close-receipts" | ||
@click=${(event: Event) => { | ||
const btn = event.target as HTMLButtonElement; | ||
btn.disabled = true; | ||
|
||
this.viewToDisplay = 'welcome'; | ||
this.dispatchEvent(new CustomEvent('ShowWelcome')); | ||
this.updates = []; | ||
}} | ||
> | ||
Back to account settings | ||
</button> | ||
</iaux-button-style> | ||
</span> | ||
</iaux-mgc-title> | ||
<iaux-mgc-receipts | ||
.receipts=${this.receipts} | ||
@EmailReceiptRequest=${(event: CustomEvent) => { | ||
console.log('EmailReceiptRequest', event.detail); | ||
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> | ||
`; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { LitElement, html, css } from 'lit'; | ||
import { customElement } from 'lit/decorators.js'; | ||
|
||
import '@internetarchive/icon-donate/icon-donate.js'; | ||
|
||
@customElement('iaux-button-style') | ||
export class MonthlyGivingCircle extends LitElement { | ||
iisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
render() { | ||
return html`<slot></slot>`; | ||
} | ||
|
||
static styles = css` | ||
::slotted(*) { | ||
height: 30px; | ||
border: none; | ||
cursor: pointer; | ||
color: #fff; | ||
line-height: normal; | ||
border-radius: 0.4rem; | ||
text-align: center; | ||
vertical-align: middle; | ||
display: inline-block; | ||
padding: 0.6rem 1.2rem; | ||
border: 1px solid transparent; | ||
|
||
white-space: nowrap; | ||
-webkit-user-select: none; | ||
-moz-user-select: none; | ||
-ms-user-select: none; | ||
-o-user-select: none; | ||
user-select: none; | ||
} | ||
|
||
:host(.transparent) ::slotted(*) { | ||
background-color: transparent; | ||
} | ||
|
||
:host(.slim) ::slotted(*) { | ||
padding: 0; | ||
} | ||
|
||
:host(.primary) ::slotted(*) { | ||
background-color: #194880; | ||
border-color: #c5d1df; | ||
} | ||
|
||
:host(.secondary) ::slotted(*) { | ||
background: #333; | ||
} | ||
|
||
:host(.cancel) ::slotted(*) { | ||
background-color: #e51c26; | ||
border-color: #f8c6c8; | ||
} | ||
|
||
:host(.link) ::slotted(*) { | ||
color: #4b64ff; | ||
border: none; | ||
background: transparent; | ||
display: flex; | ||
align-items: flex-end; | ||
padding: 0; | ||
height: inherit; | ||
} | ||
|
||
:host(.disabled) ::slotted(*) { | ||
cursor: not-allowed; | ||
opacity: 0.5; | ||
color: #222; | ||
} | ||
`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a practical example with types instead of classes, this can become
(or if you're in a TS file,
const receiptsData: aReceipt[] = [ ... ]
)