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.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../src/componen...
File: triggerBulkExportAction.js
import apiFetch from '@wordpress/api-fetch';
[0] Fix | Delete
import PropTypes from 'prop-types';
[1] Fix | Delete
[2] Fix | Delete
export const triggerBulkExportAction = async ( props ) => {
[3] Fix | Delete
props.setProcessing( true );
[4] Fix | Delete
///Set Nonce in API requests headers
[5] Fix | Delete
apiFetch.use( apiFetch.createNonceMiddleware( props.globalParams.token ) );
[6] Fix | Delete
[7] Fix | Delete
const forms = props.forms ? props.forms.join( ',' ) : '',
[8] Fix | Delete
start = props.startDateTimestamp
[9] Fix | Delete
? JSON.stringify( props.startDateTimestamp )
[10] Fix | Delete
: '',
[11] Fix | Delete
end = props.endDateTimeStamp
[12] Fix | Delete
? JSON.stringify( props.endDateTimeStamp )
[13] Fix | Delete
: '';
[14] Fix | Delete
[15] Fix | Delete
//TODO apiFetch returns a parsed response we need to check if it already checks and throws errors for http errors
[16] Fix | Delete
//Still need to determine how it ends here
[17] Fix | Delete
await apiFetch({
[18] Fix | Delete
url: props.globalParams.restUrl + 'ninja-forms-submissions/export',
[19] Fix | Delete
method: 'POST',
[20] Fix | Delete
data: {
[21] Fix | Delete
form_ids: forms,
[22] Fix | Delete
start_date: start,
[23] Fix | Delete
end_date: end,
[24] Fix | Delete
},
[25] Fix | Delete
signal: props.signal
[26] Fix | Delete
})
[27] Fix | Delete
.then( ( res ) => {
[28] Fix | Delete
for ( const [ key, value ] of Object.entries( res ) ) {
[29] Fix | Delete
downloadCsv( key, value );
[30] Fix | Delete
}
[31] Fix | Delete
props.setExportSuccess();
[32] Fix | Delete
props.setProcessing( false );
[33] Fix | Delete
} )
[34] Fix | Delete
.catch( (e) => {
[35] Fix | Delete
console.log( 'Export cancelled: ' + e.message );
[36] Fix | Delete
});
[37] Fix | Delete
};
[38] Fix | Delete
[39] Fix | Delete
const downloadCsv = ( formID, data ) => {
[40] Fix | Delete
const blob = new Blob( [ data ] );
[41] Fix | Delete
let a = window.document.createElement( 'a' );
[42] Fix | Delete
a.href = window.URL.createObjectURL( blob, {
[43] Fix | Delete
encoding: 'UTF-8',
[44] Fix | Delete
type: 'text/csv;charset=UTF-8',
[45] Fix | Delete
} );
[46] Fix | Delete
a.download = 'nf-subs-' + formID + '.csv';
[47] Fix | Delete
document.body.appendChild( a );
[48] Fix | Delete
a.click();
[49] Fix | Delete
document.body.removeChild( a );
[50] Fix | Delete
};
[51] Fix | Delete
[52] Fix | Delete
triggerBulkExportAction.propTypes = {
[53] Fix | Delete
globalParams: PropTypes.object.isRequired,
[54] Fix | Delete
forms: PropTypes.array.isRequired,
[55] Fix | Delete
startDateTimestamp: PropTypes.object.isRequired,
[56] Fix | Delete
endDateTimeStamp: PropTypes.object.isRequired,
[57] Fix | Delete
setProcessing: PropTypes.func.isRequired,
[58] Fix | Delete
setExportSuccess: PropTypes.func.isRequired,
[59] Fix | Delete
setExportError: PropTypes.func.isRequired,
[60] Fix | Delete
signal: PropTypes.object.isRequired
[61] Fix | Delete
}
[62] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function