Reimbursement form fixes and improvements #223
@@ -27,6 +27,10 @@ export default class AddReimbursementComponent extends Component {
|
||||
this.exchangeRates.fetchRates();
|
||||
}
|
||||
|
||||
get contributorId () {
|
||||
return this.recipientId || this.kredits.currentUser?.id;
|
||||
}
|
||||
|
||||
get isValidTotal () {
|
||||
return isValidAmount(this.total);
|
||||
}
|
||||
@@ -104,7 +108,7 @@ export default class AddReimbursementComponent extends Component {
|
||||
|
||||
@action
|
||||
updateContributor (event) {
|
||||
this.recipientId = event.target.value;
|
||||
this.recipientId = parseInt(event.target.value);
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -136,12 +140,12 @@ export default class AddReimbursementComponent extends Component {
|
||||
if (!this.kredits.currentUser) { window.alert('You need to connect your RSK account first.'); return false }
|
||||
if (!this.kredits.currentUserIsCore) { window.alert('Only core contributors can submit reimbursements.'); return false }
|
||||
|
||||
const contributor = this.contributors.findBy('id', parseInt(this.recipientId));
|
||||
const contributor = this.contributors.findBy('id', this.contributorId);
|
||||
|
||||
const attributes = {
|
||||
amount: parseInt(parseFloat(this.total) * 100000000), // convert to sats
|
||||
token: config.tokens['BTC'],
|
||||
recipientId: parseInt(this.recipientId),
|
||||
recipientId: this.contributorId,
|
||||
title: `Expenses covered by ${contributor.name}`,
|
||||
description: this.description,
|
||||
url: this.url,
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
<label>
|
||||
<p class="label">Contributor:</p>
|
||||
<p>
|
||||
<select required {{on "change" this.updateContributor}}>
|
||||
<option value="" selected disabled hidden></option>
|
||||
<select id="contributor" required {{on "change" this.updateContributor}}>
|
||||
{{#each this.contributors as |contributor|}}
|
||||
<option value={{contributor.id}} selected={{eq this.contributorId contributor.id}}>{{contributor.name}}</option>
|
||||
{{/each}}
|
||||
|
||||
@@ -2,11 +2,26 @@ import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
import contributors from '../../../fixtures/contributors';
|
||||
|
||||
module('Integration | Component | add-reimbursement', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it works', async function(assert) {
|
||||
hooks.beforeEach(function(assert) {
|
||||
let kredits = this.owner.lookup('service:kredits');
|
||||
kredits.set('contributors', contributors);
|
||||
kredits.set('currentUser', contributors.findBy('id', 3));
|
||||
});
|
||||
|
||||
test('Contributor select menu', async function(assert) {
|
||||
await render(hbs`<AddReimbursement />`);
|
||||
|
||||
assert.equal(this.element.querySelectorAll('select#contributor option').length, contributors.length,
|
||||
'contains correct amount of items');
|
||||
|
||||
assert.equal(this.element.querySelector('select#contributor option:checked').value, "3",
|
||||
'preselects the connected contributor account');
|
||||
});
|
||||
await render(hbs`<AddReimbursement />`);
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user