/* global wphb */ /** * Internal dependencies */ import Fetcher from '../utils/fetcher'; const MixPanel = require( 'mixpanel-browser' ); ( function ( $ ) { 'use strict'; const WPHB_Admin = { modules: [], // Common functionality to all screens init() { /** * Clear log button clicked. * * @since 1.9.2 */ $( '.wphb-logging-buttons' ).on( 'click', '.wphb-logs-clear', function ( e ) { e.preventDefault(); Fetcher.common .clearLogs( e.target.dataset.module ) .then( ( response ) => { if ( 'undefined' === typeof response.success ) { return; } if ( response.success ) { WPHB_Admin.notices.show( response.message ); } else { WPHB_Admin.notices.show( response.message, 'error' ); } } ); } ); /** * Add recipient button clicked. * * On Performance and Uptime recipient modals. * * @since 1.9.3 Unified two handle both modules. */ $( '#add-recipient' ).on( 'click', function () { const self = $( this ); self.attr( 'disabled', 'disabled' ); let module = ''; let setting = 'reports'; // Get the module name from URL. if ( window.location.search.includes( 'wphb-performance' ) ) { module = 'performance'; } else if ( window.location.search.includes( 'wphb-uptime' ) ) { module = 'uptime'; if ( window.location.search.includes( 'notifications' ) ) { setting = 'notifications'; } } const reportingEmail = $( '#reporting-email' ); const emailField = reportingEmail.closest( '.sui-form-field' ); const email = reportingEmail.val(); const name = $( '#reporting-first-name' ).val(); // Remove errors. emailField.removeClass( 'sui-form-field-error' ); emailField.find( '.sui-error-message' ).remove(); Fetcher.common .addRecipient( module, setting, email, name ) .then( ( response ) => { const userRow = $( '
' ); if ( 'notifications' === setting ) { userRow.append( '' ); } userRow.append( '' ); userRow .find( '.sui-recipient-name' ) .append( response.name ); userRow.append( $( '' ).html( email ) ); if ( 'notifications' === setting ) { userRow.append( $( '