Skip to content

Commit

Permalink
"Save and continue editing" button on risk of bias form (#645)
Browse files Browse the repository at this point in the history
* Added 'Save and continue' button to rob form

* add a toast

Co-authored-by: Andy Shapiro <[email protected]>
  • Loading branch information
rabstejnek and shapiromatron authored Jul 12, 2022
1 parent eeb904d commit 0906eb7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
38 changes: 29 additions & 9 deletions frontend/riskofbias/robStudyForm/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,35 @@ class Root extends Component {
})}
<div className="well">
<Completeness number={store.numIncompleteScores} />
<button
className="btn btn-primary space"
type="button"
onClick={store.submitScores}>
Save changes
</button>
<button className="ml-3 btn btn-light" onClick={store.cancelSubmitScores}>
Cancel
</button>
{store.changedSavedDiv ? (
<div className="alert alert-info">
<p className="mb-0">
<i className="fa fa-save mr-2" />
Changes saved!
</p>
</div>
) : null}
<div className="d-flex justify-content-between">
<button
className="btn btn-primary"
type="button"
onClick={() => store.submitScores(false)}>
Save and continue editing
</button>
<div>
<button
className="btn btn-light mr-3"
onClick={store.cancelSubmitScores}>
Cancel
</button>
<button
className="btn btn-primary"
type="button"
onClick={() => store.submitScores(true)}>
Save and return
</button>
</div>
</div>
</div>
</form>
</div>
Expand Down
15 changes: 13 additions & 2 deletions frontend/riskofbias/robStudyForm/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class RobFormStore extends StudyRobStore {
@action.bound cancelSubmitScores() {
window.location.href = this.config.cancelUrl;
}
@action.bound submitScores() {
@action.bound submitScores(redirect) {
const payload = {
id: this.config.riskofbias.id,
scores: this.editableScores.map(score => {
Expand Down Expand Up @@ -172,7 +172,11 @@ class RobFormStore extends StudyRobStore {
return fetch(url, opts)
.then(response => {
if (response.ok) {
window.location.href = this.config.cancelUrl;
if (redirect) {
window.location.href = this.config.cancelUrl;
} else {
this.setChangedSavedDiv();
}
} else {
response.text().then(text => {
this.error = text;
Expand All @@ -183,6 +187,13 @@ class RobFormStore extends StudyRobStore {
this.error = error;
});
}
@observable changedSavedDiv = false;
@action.bound setChangedSavedDiv() {
this.changedSavedDiv = true;
setTimeout(() => {
this.changedSavedDiv = false;
}, 2000);
}
@action.bound createScoreOverride(payload) {
let url = `${this.config.riskofbias.scores_url}?assessment_id=${this.config.assessment_id}`,
csrf = this.config.csrf,
Expand Down

0 comments on commit 0906eb7

Please sign in to comment.