Skip to content

Commit

Permalink
Merge pull request #13 from mamatharao05/PRESS0-1415
Browse files Browse the repository at this point in the history
Added Drop down for temporary deactivation options in deactivation popup
  • Loading branch information
mamatharao05 authored Jun 3, 2024
2 parents 9c45ae7 + 8856256 commit 6888522
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions includes/DeactivationSurvey.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public function __construct() {
__( 'Need Help? Check the <a href="%s">help center</a> for support.', 'wp-module-deactivation' ),
'/wp-admin/admin.php?page=' . container()->plugin()->id . '#/help'
),
'durationOption1' => __( '1 Hour','wp-module-deactivation' ),
'durationOption1Value' => __( '1_hour','wp-module-deactivation' ),
'durationOption2' => __( '24 Hours','wp-module-deactivation' ),
'durationOption2Value' => __( '24_hours','wp-module-deactivation' ),
'durationOption3' => __( 'Until I turn it back on','wp-module-deactivation' ),
'durationOption3Value' => __( 'until_manual','wp-module-deactivation' ),
);

// Merge defaults with container values from plugin
Expand Down
23 changes: 17 additions & 6 deletions static/js/deactivation-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
</div>
<div class="nfd-deactivation-survey__content-actions">
<button type="button" class="nfd-deactivation-survey-action" nfd-deactivation-survey-skip aria-label="${ runtimeData.strings.skipAriaLabel }">${ runtimeData.strings.skip }</button>
<select id="deactivation-duration" name="deactivation_duration" class="nfd-deactivation-duration">
<option value=${ runtimeData.strings.durationOption1Value }>${ runtimeData.strings.durationOption1 }</option>
<option value=${ runtimeData.strings.durationOption2Value }>${ runtimeData.strings.durationOption2 }</option>
<option value=${ runtimeData.strings.durationOption3Value } selected>${ runtimeData.strings.durationOption3 }</option>
</select>
<input type="submit" value="${ runtimeData.strings.submit }" nfd-deactivation-survey-submit class="button button-primary" aria-label="${ runtimeData.strings.submitAriaLabel }"/>
</div>
</div></div>
Expand Down Expand Up @@ -185,42 +190,48 @@
isSubmitting();

let surveyInput = 'No input';
let deactivationDuration = '';
if ( ! skipped ) {
const inputValue = document.getElementById(
'nfd-deactivation-survey__input'
).value;
if ( inputValue.length > 0 ) {
surveyInput = inputValue;
}
deactivationDuration = document.getElementById(
'deactivation-duration'
).value;
}

// Send event
const send = await sendEvent( surveyInput );
const sendSurveyInput = await sendEvent( surveyInput,'');
const sendDeactivationDuration = await sendEvent( '', deactivationDuration);
deactivatePlugin();
};

const sendEvent = async ( surveyInput ) => {
const sendEvent = async ( surveyInput = '', deactivationDuration = '' ) => {
const eventData = {
label_key: 'survey_input',
survey_input: surveyInput,
label_key: surveyInput ? 'survey_input' : 'deactivation_duration',
category: 'user_action',
brand: runtimeData.brand,
page: window.location.href,
...surveyInput && { survey_input: surveyInput },
...deactivationDuration && { deactivation_duration: deactivationDuration },
};

// Attach abTestPluginHome flag value if exists
if ( typeof getABTestPluginHome() === 'boolean' ) {
eventData.abTestPluginHome = getABTestPluginHome();
}

const actionName = surveyInput ? 'deactivation_survey_freeform' : 'deactivation_duration';
await fetch( runtimeData.eventsEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': runtimeData.restApiNonce,
},
body: JSON.stringify( {
action: 'deactivation_survey_freeform',
action: actionName,
data: eventData,
} ),
} );
Expand Down

0 comments on commit 6888522

Please sign in to comment.