Add proposal form
Closes #6 Form can be prefilled using query params on the route. The params are `recipient`, `amount`, `url` and `ipfsHash`.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
const {
|
||||
Component,
|
||||
inject: {
|
||||
service
|
||||
},
|
||||
computed
|
||||
} = Ember;
|
||||
|
||||
export default Component.extend({
|
||||
|
||||
kredits: service(),
|
||||
|
||||
proposal: null,
|
||||
inProgress: false,
|
||||
|
||||
isValidRecipient: computed('proposal.recipientAddress', function() {
|
||||
return this.get('kredits.web3Instance').isAddress(this.get('proposal.recipientAddress'));
|
||||
}),
|
||||
|
||||
isValidAmount: computed('proposal.amount', function() {
|
||||
// TODO
|
||||
return true;
|
||||
}),
|
||||
|
||||
isValidUrl: computed('proposal.url', function() {
|
||||
// TODO
|
||||
return true;
|
||||
}),
|
||||
|
||||
isValidIpfsHash: computed('proposal.ipfsHash', function() {
|
||||
// TODO
|
||||
return true;
|
||||
}),
|
||||
|
||||
isValid: computed.and('isValidRecipient', 'isValidAmount', 'isValidUrl',
|
||||
'isValidIpfsHash'),
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
if (this.get('isValid')) {
|
||||
this.set('inProgress', true);
|
||||
|
||||
this.get('kredits').addProposal(this.get('proposal'))
|
||||
.then(() => {
|
||||
this.attrs.onSave();
|
||||
}).catch((error) => {
|
||||
Ember.Logger.error('Error creating the proposal', error);
|
||||
alert('Something went wrong.');
|
||||
}).finally(() => {
|
||||
this.set('inProgress', false);
|
||||
});
|
||||
} else {
|
||||
alert('Invalid data. Please review and try again.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
<form {{action "save" on="submit"}}>
|
||||
<p>
|
||||
{{input type="text"
|
||||
placeholder="0xF18E631Ea191aE4ebE70046Fcb01a436554421BA4"
|
||||
value=proposal.recipientAddress
|
||||
class=(if isValidRecipient 'valid' '')}}
|
||||
</p>
|
||||
<p>
|
||||
{{input type="text"
|
||||
placeholder="100"
|
||||
value=proposal.amount
|
||||
class=(if isValidAmount 'valid' '')}}
|
||||
</p>
|
||||
<p>
|
||||
{{input type="text"
|
||||
placeholder="URL"
|
||||
value=proposal.url
|
||||
class=(if isValidUrl 'valid' '')}}
|
||||
</p>
|
||||
<p>
|
||||
{{input type="text"
|
||||
placeholder="IPFS Hash"
|
||||
value=proposal.ipfsHash
|
||||
class=(if isValidIpfsHash 'valid' '')}}
|
||||
</p>
|
||||
<p class="actions">
|
||||
{{input type="submit" value=(if inProgress 'Processing' 'Save') disabled=inProgress}}
|
||||
{{#link-to 'index'}}Back{{/link-to}}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user