From 01f28d9f3a2c70f8b72365229fe9f211634a4972 Mon Sep 17 00:00:00 2001 From: jeremiG Date: Sat, 29 Dec 2018 04:26:11 -0500 Subject: [PATCH] fix(add_interest): Only proceed if successful Change the current implementation to not close the modal and show the UI as if the job was successfully started when the user already has the max number of jobs. Fixes: #3281 --- app/assets/v2/js/pages/bounty_details.js | 16 ++++++++++++---- app/assets/v2/js/shared.js | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/assets/v2/js/pages/bounty_details.js b/app/assets/v2/js/pages/bounty_details.js index 0f16dd1f523..780523ba94e 100644 --- a/app/assets/v2/js/pages/bounty_details.js +++ b/app/assets/v2/js/pages/bounty_details.js @@ -621,13 +621,21 @@ var show_interest_modal = function() { return false; } - $(self).attr('href', '/uninterested'); - $(self).find('span').text(gettext('Stop Work')); - $(self).parent().attr('title', '
' + gettext('Notify the funder that you will not be working on this project') + '
'); + add_interest(document.result['pk'], { issue_message: msg + }).then(success => { + if (success) { + $(self).attr('href', '/uninterested'); + $(self).find('span').text(gettext('Stop Work')); + $(self).parent().attr('title', '
' + gettext('Notify the funder that you will not be working on this project') + '
'); + $.modal.close(); + } + }).catch((error) => { + if (error.responseJSON.error === 'You may only work on max of 3 issues at once.') + return; + throw error; }); - $.modal.close(); }); }); }); diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index dfd9281b19e..e347af91511 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -267,7 +267,7 @@ var add_interest = function(bounty_pk, data) { if (document.interested) { return; } - mutate_interest(bounty_pk, 'new', data); + return mutate_interest(bounty_pk, 'new', data); }; /** Remove the current profile from the interested profiles list. */ @@ -284,7 +284,7 @@ var mutate_interest = function(bounty_pk, direction, data) { var request_url = '/actions/bounty/' + bounty_pk + '/interest/' + direction + '/'; showBusyOverlay(); - $.post(request_url, data).then(function(result) { + return $.post(request_url, data).then(function(result) { hideBusyOverlay(); result = sanitizeAPIResults(result); @@ -293,6 +293,7 @@ var mutate_interest = function(bounty_pk, direction, data) { if (direction === 'new') { _alert({ message: result.msg }, 'success'); $('#interest a').attr('id', 'btn-white'); + return true; } else if (direction === 'remove') { _alert({ message: result.msg }, 'success'); $('#interest a').attr('id', ''); @@ -312,7 +313,6 @@ var mutate_interest = function(bounty_pk, direction, data) { } _alert({ message: alertMsg }, 'error'); - }); };