1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00

Make behaviour of ContractSettingsUpdateButton more robust

Also fixes the “Contract could not be updated” notification that would
occur after every attempt to update the contract.
This commit is contained in:
Brett Sun 2015-12-21 11:45:50 +01:00
parent 5a497bae59
commit 3467e9f526

View File

@ -24,37 +24,41 @@ let ContractSettingsUpdateButton = React.createClass({
}, },
submitFile(file) { submitFile(file) {
let contract = this.props.contract;
// override the blob with the key's value // override the blob with the key's value
contract.blob = file.key; const contract = Object.assign(this.props.contract, { blob: file.key });
// send it to the server // send it to the server
ContractListActions ContractListActions
.changeContract(contract) .changeContract(contract)
.then((res) => { .then((res) => {
// Display feedback to the user // Display feedback to the user
let notification = new GlobalNotificationModel(getLangText('Contract %s successfully updated', res.name), 'success', 5000); const notification = new GlobalNotificationModel(getLangText('Contract %s successfully updated', contract.name), 'success', 5000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
// and refresh the contract list to get the updated contracs // and refresh the contract list to get the updated contracs
return ContractListActions.fetchContractList(true); return ContractListActions
}) .fetchContractList(true)
.then(() => { // Also, reset the fineuploader component if fetch is successful so that the user can again 'update' his contract
// Also, reset the fineuploader component so that the user can again 'update' his contract .then(this.refs.fineuploader.reset)
this.refs.fineuploader.reset(); .catch((err) => {
}) const notification = new GlobalNotificationModel(getLangText('Latest contract failed to load'), 'danger', 5000);
.catch((err) => { GlobalNotificationActions.appendGlobalNotification(notification);
console.logGlobal(err);
let notification = new GlobalNotificationModel(getLangText('Contract could not be updated'), 'success', 5000); return Promise.reject(err);
});
}, (err) => {
const notification = new GlobalNotificationModel(getLangText('Contract could not be updated'), 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
});
return Promise.reject(err);
})
.catch(console.logGlobal);
}, },
render() { render() {
return ( return (
<ReactS3FineUploader <ReactS3FineUploader
ref='fineuploader'
fileInputElement={UploadButton({ showLabel: false })} fileInputElement={UploadButton({ showLabel: false })}
keyRoutine={{ keyRoutine={{
url: AppConstants.serverUrl + 's3/key/', url: AppConstants.serverUrl + 's3/key/',