Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 2 additions & 5 deletions app/components/donation/credit-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Ember from 'ember';
const {
Component,
computed,
computed: { and, not, or },
computed: { and, not },
inject: { service }
} = Ember;

Expand All @@ -20,10 +20,8 @@ export default Component.extend({
*/
stripe: service(),

cardInvalid: not('cardValid'),
cardValid: and('isCardNumberValid', 'isCVCValid', 'isExpiryValid'),

isBusyOrInvalid: or('isBusy', 'cardInvalid'),
isInvalid: not('cardValid'),

date: computed('month', 'year', function() {
let month = this.get('month');
Expand Down Expand Up @@ -81,7 +79,6 @@ export default Component.extend({

actions: {
submit() {
this.set('isSubmitting', true);
let cardAttrs = this.getProperties('cvc', 'cardNumber', 'year', 'month');
let onSubmit = this.get('submit');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was actually useless property we don't need anymore, so I would keep this one change in no matter what.

Expand Down
1 change: 1 addition & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@import "components/comment-item";
@import "components/create-comment-form";
@import "components/donation/card-item";
@import "components/donation/donation-container";
@import "components/donations/donation-progress";
@import "components/donations/donation-status";
@import "components/donation-goal";
Expand Down
10 changes: 10 additions & 0 deletions app/styles/components/donation/donation-container.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.donation-container {
.loading-indicator {
text-align: center;

div {
display: inline-block;
vertical-align: middle;
}
}
}
16 changes: 6 additions & 10 deletions app/templates/components/donation/credit-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
</div>

<div class="input-group">

<div class="row">
<label>
<span>Expiration</span>
Expand All @@ -40,14 +39,11 @@
</div>
</div>

<button
class="button {{unless isBusyOrInvalid "default"}} large submit-card"
disabled={{isBusyOrInvalid}}
{{action "submit"}}>
{{#if isBusy}}Processing...{{else}}Donate{{/if}}
<button class="button {{unless isInvalid "default"}} large submit-card" disabled={{isInvalid}} {{action "submit"}}>
Donate
</button>

{{#unless isBusy}}
{{!validation errors can be passed in from parent, using a block}}
{{yield}}
{{/unless}}

{{!validation errors can be passed in from parent, using a block}}
{{yield}}

28 changes: 17 additions & 11 deletions app/templates/components/donation/donation-container.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@
</p>
</div>

{{#if card}}
{{donation/card-item card=card}}
{{#if isBusy}}
<div class="loading-indicator">
<div class="spinner small"></div>
<div>Processing...</div>
</div>
{{else}}
{{#donation/credit-card isBusy=isBusy submit=(action saveAndDonate)}}
{{#if card}}
{{donation/card-item card=card}}
{{else}}
{{#donation/credit-card submit=(action saveAndDonate)}}
{{!show errors}}
{{yield}}
{{/donation/credit-card}}
{{/if}}

{{#if card}}
<button class="button default large donate" {{action donate}}>Donate</button>
{{!show errors}}
{{yield}}
{{/donation/credit-card}}
{{/if}}

{{#if card}}
<button class="button {{unless isBusy "default"}} large donate" {{action donate}} disabled={{isBusy}}>Donate</button>
{{!show errors}}
{{yield}}
{{/if}}
{{/if}}

<footer>
Your donation will repeat automatically each month.
You can cancel or edit your donation at any time.
Expand Down
17 changes: 0 additions & 17 deletions tests/integration/components/donation/credit-card-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,6 @@ test('it sends submit with credit card fields when button is clicked', function(
page.clickSubmit();
});

test('it renders button as disabled and "Processing" when busy', function(assert) {
assert.expect(2);

stubService(this, 'stripe', {
card: {
validateCardNumber: () => true,
validateCVC: () => true,
validateExpiry: () => true
}
});

page.render(hbs`{{donation/credit-card isBusy=true submit=submitHandler}}`);

assert.ok(page.submitDisabled, 'Submit button is disabled');
assert.equal(page.submitButtonText, 'Processing...', 'Submit button changed text');
});

test('it renders button as disabled and "Donate" when card is invalid', function(assert) {
assert.expect(2);

Expand Down