Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking "Maybe later" will dismiss feature announcement for 3 days #2762

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion classes/class-wc-connect-service-settings-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,17 @@ public function get_package_lookup() {
}

public function is_eligible_for_migration() {
$migration_dismissed = false;
if ( isset( $_COOKIE[ WC_Connect_Loader::MIGRATION_DISMISSAL_COOKIE_KEY ] ) && (int) $_COOKIE[ WC_Connect_Loader::MIGRATION_DISMISSAL_COOKIE_KEY ] === 1 ) {
$migration_dismissed = true;
}

$migration_state = WC_Connect_Options::get_option( 'wcshipping_migration_state' );

$migration_pending = WC_Connect_WCST_To_WCShipping_Migration_State_Enum::COMPLETED !== $migration_state;
$migration_enabled = $this->service_schemas_store->is_wcship_wctax_migration_enabled();

return $migration_pending && $migration_enabled;
return $migration_pending && $migration_enabled && ! $migration_dismissed;
}

private function translate_unit( $value ) {
Expand Down
1 change: 1 addition & 0 deletions client/components/migration/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TIME_TO_REMMEMBER_DISMISSAL_SECONDS = 3 * 24 * 60 * 60; // 3 Days - number of seconds
13 changes: 11 additions & 2 deletions client/components/migration/feature-announcement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import React from 'react';
import { Flex, FlexItem, Modal, Icon, Button } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { localize } from 'i18n-calypso';
Expand All @@ -18,17 +18,26 @@ import {
wcshippingMigrationState,
} from 'woocommerce/woocommerce-services/state/shipping-label/selectors';
import { installAndActivatePlugins } from './migration-runner';
import { TIME_TO_REMMEMBER_DISMISSAL_SECONDS } from './constants';

const FeatureAnnouncement = ( { translate, isEligable, previousMigrationState } ) => {
const [isOpen, setIsOpen] = useState(isEligable);
const [isUpdating, setIsUpdating] = useState(false);

useEffect( () => {
const isMigrationDismissed = window.wpCookies.get( 'wcst-wcshipping-migration-dismissed' ) && parseInt( window.wpCookies.get( 'wcst-wcshipping-migration-dismissed' ) );
if ( isMigrationDismissed ) {
setIsOpen( false );
}
}, [] );

const closeModal = () => {
setIsOpen(false);
};

const snooze = () => {
// Todo: implement maybe later
window.wpCookies.set( 'wcst-wcshipping-migration-dismissed', 1, TIME_TO_REMMEMBER_DISMISSAL_SECONDS );
setIsOpen( false );
};

const update = async () => {
Expand Down
2 changes: 1 addition & 1 deletion client/wcshipping-migration-admin-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import '../assets/stylesheets/migration_to_wcshipping_admin_notice.scss';
import FeatureAnnouncement from 'components/migration/feature-announcement';
import ShippingLabel from 'wcs-client/apps/shipping-label';
import { setNonce, setBaseURL } from 'wcs-client/api/request';
import { TIME_TO_REMMEMBER_DISMISSAL_SECONDS } from 'components/migration/constants';

const container = document.getElementById('wcst_wcshipping_migration_admin_notice_feature_announcement');
const args = container.dataset.args && JSON.parse( container.dataset.args ) || {};
Expand All @@ -23,7 +24,6 @@ const store = createStore(ShippingLabelStore.getReducer(), ShippingLabelStore.ge

const wcstWCShippingMigrationNoticeButton = document.getElementById('wcst-wcshipping-migration-notice__click');
const wcstMigrationNoticeDimissButton = document.querySelector('.wcst-wcshipping-migration-notice button.notice-dismiss');
const TIME_TO_REMMEMBER_DISMISSAL_SECONDS = 3 * 24 * 60 * 60; // 3 Days - number of seconds

// Add all button events
["click", "keydown"].forEach(eventName => {
Expand Down
4 changes: 2 additions & 2 deletions woocommerce-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class WC_Connect_Loader {

protected static $wcs_version;

const MIGRATION_DISMISSAL_COOKIE_KEY = 'wcst-wcshipping-migration-dismissed';
public const MIGRATION_DISMISSAL_COOKIE_KEY = 'wcst-wcshipping-migration-dismissed';

public static function plugin_deactivation() {
wp_clear_scheduled_hook( 'wc_connect_fetch_service_schemas' );
Expand Down Expand Up @@ -1523,7 +1523,7 @@ public function edit_orders_page_actions() {
return;
}

// Add the WCS&T to WCShipping migratio notice, creating a button to update.
// Add the WCS&T to WCShipping migration notice, creating a button to update.
$settings_store = $this->get_service_settings_store();
if ( $settings_store->is_eligible_for_migration() ) {
add_action( 'admin_notices', array( $this, 'display_wcst_to_wcshipping_migration_notice' ) );
Expand Down
Loading