Fix hold button to properly show Resume state when call is on hold
- Enhanced Call SID detection using multiple fallback methods - Fixed button state logic to properly toggle between Hold/Resume - Added immediate UI feedback during hold operations - Enhanced error handling with proper button state reversion - Added distinctive orange styling for active hold button state - Improved user messaging to clarify when call is on hold - Added comprehensive console logging for debugging hold operations - Fixed logic error in button state updates The button will now properly show: - "Hold" when call is active (normal state) - "Resume" when call is on hold (orange/active state) - Loading states during operations ("Holding..." / "Resuming...") 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1254,3 +1254,16 @@
|
|||||||
color: #6c757d;
|
color: #6c757d;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hold button active state */
|
||||||
|
.twp-btn.btn-active {
|
||||||
|
background-color: #ff6b35 !important;
|
||||||
|
color: white !important;
|
||||||
|
border-color: #e55100 !important;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.twp-btn.btn-active:hover {
|
||||||
|
background-color: #e55100 !important;
|
||||||
|
border-color: #bf360c !important;
|
||||||
|
}
|
@@ -1545,32 +1545,72 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get Call SID using multiple detection methods
|
||||||
|
const callSid = currentCall.parameters.CallSid ||
|
||||||
|
currentCall.customParameters.CallSid ||
|
||||||
|
currentCall.outgoingConnectionId ||
|
||||||
|
currentCall.sid;
|
||||||
|
|
||||||
|
if (!callSid) {
|
||||||
|
showMessage('Unable to identify call for hold operation', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const $holdBtn = $('#twp-hold-btn');
|
const $holdBtn = $('#twp-hold-btn');
|
||||||
|
const currentHoldState = isOnHold;
|
||||||
|
|
||||||
|
// Update button immediately for better UX
|
||||||
|
if (currentHoldState) {
|
||||||
|
$holdBtn.text('Resuming...').prop('disabled', true);
|
||||||
|
} else {
|
||||||
|
$holdBtn.text('Holding...').prop('disabled', true);
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: twp_frontend_ajax.ajax_url,
|
url: twp_frontend_ajax.ajax_url,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
action: 'twp_toggle_hold',
|
action: 'twp_toggle_hold',
|
||||||
call_sid: currentCall.parameters.CallSid,
|
call_sid: callSid,
|
||||||
hold: !isOnHold,
|
hold: !currentHoldState,
|
||||||
nonce: twp_frontend_ajax.nonce
|
nonce: twp_frontend_ajax.nonce
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
console.log('Hold toggle response:', response);
|
||||||
|
console.log('Current hold state before:', currentHoldState);
|
||||||
|
console.log('New hold state will be:', !currentHoldState);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
isOnHold = !isOnHold;
|
isOnHold = !currentHoldState;
|
||||||
|
console.log('Hold state updated to:', isOnHold);
|
||||||
|
|
||||||
if (isOnHold) {
|
if (isOnHold) {
|
||||||
$holdBtn.text('Unhold').addClass('btn-active');
|
$holdBtn.text('Resume').addClass('btn-active').prop('disabled', false);
|
||||||
showMessage('Call placed on hold', 'info');
|
showMessage('Call placed on hold - Click Resume to continue', 'info');
|
||||||
|
console.log('Button updated to Resume state');
|
||||||
} else {
|
} else {
|
||||||
$holdBtn.text('Hold').removeClass('btn-active');
|
$holdBtn.text('Hold').removeClass('btn-active').prop('disabled', false);
|
||||||
showMessage('Call resumed', 'info');
|
showMessage('Call resumed', 'info');
|
||||||
|
console.log('Button updated to Hold state');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.error('Hold toggle failed:', response);
|
||||||
|
// Revert button state on error
|
||||||
|
if (currentHoldState) {
|
||||||
|
$holdBtn.text('Resume').addClass('btn-active').prop('disabled', false);
|
||||||
|
} else {
|
||||||
|
$holdBtn.text('Hold').removeClass('btn-active').prop('disabled', false);
|
||||||
|
}
|
||||||
showMessage('Failed to toggle hold: ' + (response.data || 'Unknown error'), 'error');
|
showMessage('Failed to toggle hold: ' + (response.data || 'Unknown error'), 'error');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
|
// Revert button state on error
|
||||||
|
if (currentHoldState) {
|
||||||
|
$holdBtn.text('Resume').addClass('btn-active').prop('disabled', false);
|
||||||
|
} else {
|
||||||
|
$holdBtn.text('Hold').removeClass('btn-active').prop('disabled', false);
|
||||||
|
}
|
||||||
showMessage('Failed to toggle hold', 'error');
|
showMessage('Failed to toggle hold', 'error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user