Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../clone/wp-conte.../plugins/ninja-fo.../src/componen...
File: triggerEmailAction.js
import apiFetch from '@wordpress/api-fetch';
[0] Fix | Delete
import PropTypes from 'prop-types';
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* There is a straitforward way of sending all requests at once and have the Jobs in the loop done quicker
[4] Fix | Delete
* BUT I fear it could result in memory exhaustion in some browsers, this way we run request by request
[5] Fix | Delete
* TODO organize batches depending on the total amount of emails to be sent in order to make the process faster
[6] Fix | Delete
*
[7] Fix | Delete
*/
[8] Fix | Delete
export const sendEmail = async ( props, submissionID ) => {
[9] Fix | Delete
await apiFetch( {
[10] Fix | Delete
url:
[11] Fix | Delete
props.restUrl +
[12] Fix | Delete
'ninja-forms-submissions/email-action',
[13] Fix | Delete
method: 'POST',
[14] Fix | Delete
data: {
[15] Fix | Delete
submission: submissionID,
[16] Fix | Delete
action_settings: props.action,
[17] Fix | Delete
formID: props.formID,
[18] Fix | Delete
},
[19] Fix | Delete
parse: false, //Use false to manage errors, by default apiFetch is set to true on Parse and directly sends back the json response
[20] Fix | Delete
signal: props.signal
[21] Fix | Delete
} )
[22] Fix | Delete
.then( ( response ) => {
[23] Fix | Delete
//Count Processed emails (sent or not )
[24] Fix | Delete
props.setEmailProcessed();
[25] Fix | Delete
//Catch not OK fetch task or process response via json
[26] Fix | Delete
if ( ! response.ok ) {
[27] Fix | Delete
//Push Submission ID in an array to store failures
[28] Fix | Delete
console.log(response.json());
[29] Fix | Delete
props.setNotSent( response.json() );
[30] Fix | Delete
} else {
[31] Fix | Delete
return response.json();
[32] Fix | Delete
}
[33] Fix | Delete
} )
[34] Fix | Delete
.then( ( res ) => {
[35] Fix | Delete
//Count Sent emails if sent or push Submission ID to an array if email was not sent
[36] Fix | Delete
if ( res === true ) {
[37] Fix | Delete
props.setSent();
[38] Fix | Delete
} else {
[39] Fix | Delete
props.setNotSent( res );
[40] Fix | Delete
}
[41] Fix | Delete
} );
[42] Fix | Delete
};
[43] Fix | Delete
[44] Fix | Delete
sendEmail.propTypes = {
[45] Fix | Delete
restUrl: PropTypes.string.isRequired,
[46] Fix | Delete
action: PropTypes.object.isRequired,
[47] Fix | Delete
formID: PropTypes.number.isRequired,
[48] Fix | Delete
setSent: PropTypes.func.isRequired,
[49] Fix | Delete
setNotSent: PropTypes.func.isRequired,
[50] Fix | Delete
setEmailProcessed: PropTypes.func.isRequired,
[51] Fix | Delete
signal: PropTypes.object.isRequired
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function