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

My Jetpack: replace Creator card with Newsletter #38418

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import AiCard from './ai-card';
import AntiSpamCard from './anti-spam-card';
import BackupCard from './backup-card';
import BoostCard from './boost-card';
import CreatorCard from './creator-card';
import CrmCard from './crm-card';
import NewsletterCard from './newsletter-card';
import ProtectCard from './protect-card';
import SearchCard from './search-card';
import SocialCard from './social-card';
Expand All @@ -21,15 +21,19 @@ type DisplayItemsProps = {
slugs: JetpackModule[];
};

type ExcludedModules = 'extras' | 'scan' | 'security' | 'creator';

type DisplayItemType = Record<
// We don't have a card for Security or Extras, and scan is displayed as protect.
Exclude< JetpackModule, 'extras' | 'scan' | 'security' >,
Exclude< JetpackModule, ExcludedModules >,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvements with the excludes, thanks!

FC< { admin: boolean } >
>;

const excludedModules: ExcludedModules[] = [ 'extras', 'scan', 'security', 'creator' ];

const DisplayItems: FC< DisplayItemsProps > = ( { slugs } ) => {
const { showFullJetpackStatsCard = false } = getMyJetpackWindowInitialState( 'myJetpackFlags' );
const { isAtomic = false, userIsAdmin = false } = getMyJetpackWindowInitialState();
const { userIsAdmin = false } = getMyJetpackWindowInitialState();

const items: DisplayItemType = {
backup: BackupCard,
Expand All @@ -40,7 +44,7 @@ const DisplayItems: FC< DisplayItemsProps > = ( { slugs } ) => {
videopress: VideopressCard,
stats: StatsCard,
crm: CrmCard,
creator: ! isAtomic ? CreatorCard : null,
newsletter: NewsletterCard,
social: SocialCard,
'jetpack-ai': AiCard,
};
Expand Down Expand Up @@ -101,10 +105,7 @@ const ProductCardsSection: FC< ProductCardsSectionProps > = ( { noticeMessage }

const filterProducts = ( products: JetpackModule[] ) => {
return products.filter( product => {
if ( product === 'scan' || product === 'security' || product === 'extras' ) {
return false;
}
return true;
return ! excludedModules.includes( product );
} );
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { __ } from '@wordpress/i18n';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a brand new file, what do you think about converting it to TypeScript since we are heading that direction in My Jetpack?

import PropTypes from 'prop-types';
import React from 'react';
import { PRODUCT_STATUSES } from '../../constants';
import ProductCard from '../connected-product-card';

const NEWSLETTER_SETTINGS_PAGE_URL = 'admin.php?page=jetpack#/newsletter';

const NewsletterCard = ( { admin } ) => {
const actionOverride = {
[ PRODUCT_STATUSES.NEEDS_PURCHASE_OR_FREE ]: {
href: NEWSLETTER_SETTINGS_PAGE_URL,
},
[ PRODUCT_STATUSES.NEEDS_FIRST_SITE_CONNECTION ]: {
href: NEWSLETTER_SETTINGS_PAGE_URL,
},
[ PRODUCT_STATUSES.INACTIVE ]: {
href: NEWSLETTER_SETTINGS_PAGE_URL,
label: __( 'View', 'jetpack-my-jetpack' ),
onClick: () => {},
},
[ PRODUCT_STATUSES.MODULE_DISABLED ]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR we've gone towards allowing the user to "Activate" the module/plugin from My Jetpack if at all possible. Could we possibly continue that trend here? Would the activate function work here or is there a reason we need to have the user do it from the settings page?

href: NEWSLETTER_SETTINGS_PAGE_URL,
label: __( 'View', 'jetpack-my-jetpack' ),
onClick: () => {},
},
};

return <ProductCard admin={ admin } slug="newsletter" primaryActionOverride={ actionOverride } />;
};

NewsletterCard.propTypes = {
admin: PropTypes.bool.isRequired,
};

export default NewsletterCard;
4 changes: 4 additions & 0 deletions projects/packages/my-jetpack/changelog/add-newsletter-card
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

My Jetpack: add a new product card for Newsletter and replace Creator with it.
11 changes: 6 additions & 5 deletions projects/packages/my-jetpack/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ type JetpackModule =
| 'anti-spam'
| 'backup'
| 'boost'
| 'crm'
| 'creator'
| 'crm'
| 'extras'
| 'jetpack-ai'
| 'newsletter'
| 'protect'
| 'scan'
| 'search'
| 'social'
| 'security'
| 'protect'
| 'videopress'
| 'stats';
| 'social'
| 'stats'
| 'videopress';

type ThreatItem = {
// Protect API properties (free plan)
Expand Down
13 changes: 7 additions & 6 deletions projects/packages/my-jetpack/src/class-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,22 @@ class Products {
*/
public static function get_products_classes() {
$classes = array(
'ai' => Products\Jetpack_Ai::class,
'anti-spam' => Products\Anti_Spam::class,
'backup' => Products\Backup::class,
'boost' => Products\Boost::class,
'crm' => Products\Crm::class,
'creator' => Products\Creator::class,
'crm' => Products\Crm::class,
'extras' => Products\Extras::class,
'jetpack-ai' => Products\Jetpack_Ai::class,
'newsletter' => Products\Newsletter::class,
'protect' => Products\Protect::class,
'scan' => Products\Scan::class,
'search' => Products\Search::class,
'social' => Products\Social::class,
'security' => Products\Security::class,
'protect' => Products\Protect::class,
'videopress' => Products\Videopress::class,
'social' => Products\Social::class,
'stats' => Products\Stats::class,
'ai' => Products\Jetpack_Ai::class,
'videopress' => Products\Videopress::class,
);

/**
Expand Down Expand Up @@ -219,7 +220,7 @@ public static function get_products_by_ownership( $type ) {
)
)
),
'unowned' => array_unique( $unowned_products ),
'unowned' => array_values( array_unique( $unowned_products ) ),
);

return $data[ $type ];
Expand Down
194 changes: 194 additions & 0 deletions projects/packages/my-jetpack/src/products/class-newsletter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<?php
/**
* Jetpack Newsletter
*
* @package my-jetpack
*/

namespace Automattic\Jetpack\My_Jetpack\Products;

use Automattic\Jetpack\My_Jetpack\Initializer;
use Automattic\Jetpack\My_Jetpack\Module_Product;
use Automattic\Jetpack\My_jetpack\Products;
use Automattic\Jetpack\My_Jetpack\Wpcom_Products;

/**
* Class responsible for handling the Jetpack Newsletter (subscriptions) module
*/
class Newsletter extends Module_Product {
/**
* The product slug
*
* @var string
*/
public static $slug = 'newsletter';

/**
* The Jetpack module name associated with this product
*
* @var string|null
*/
public static $module_name = 'subscriptions';

/**
* The Plugin slug associated with Newsletter
*
* @var string|null
*/
public static $plugin_slug = self::JETPACK_PLUGIN_SLUG;

/**
* The Plugin file associated with Newsletter
*
* @var string|null
*/
public static $plugin_filename = self::JETPACK_PLUGIN_FILENAME;

/**
* Newsletter requires user connection
*
* @var bool
*/
public static $requires_user_connection = true;

/**
* Newsletter does not have a standalone plugin yet
*
* @var bool
*/
public static $has_standalone_plugin = false;

/**
* Whether this product has a free offering
*
* @var bool
*/
public static $has_free_offering = true;

/**
* Get the product name
*
* @return string
*/
public static function get_name() {
return 'Newsletter';
}

/**
* Get the product title
*
* @return string
*/
public static function get_title() {
return 'Jetpack Newsletter';
}

/**
* Get the internationalized product description
*
* @return string
*/
public static function get_description() {
return __( 'Deliver your content with ease.', 'jetpack-my-jetpack' );
}

/**
* Get the internationalized product long description
*
* @return string
*/
public static function get_long_description() {
return __( 'Write and share your content, get more subscribers, and monetize your writing.', 'jetpack-my-jetpack' );
}

/**
* Get the internationalized features list
*
* @return array Newsletter features list
*/
public static function get_features() {
return array(
__( 'Instant blog‑to‑newsletter delivery', 'jetpack-my-jetpack' ),
__( 'Effortlessly reach your subscribers with fresh content', 'jetpack-my-jetpack' ),
__( 'Earn money through your Newsletter', 'jetpack-my-jetpack' ),
);
}

/**
* Get the product pricing details
* Only showing the pricing details for the commercial product
*
* @return array Pricing details
*/
public static function get_pricing_for_ui() {
return array(
'available' => true,
'is_free' => true,
);
}

/**
* Gets the 'status' of the Newsletter module
*
* @return string
*/
public static function get_status() {
$status = parent::get_status();
if ( Products::STATUS_MODULE_DISABLED === $status && ! Initializer::is_registered() ) {
// If the site has never been connected before, show the "Learn more" CTA.
// It should point to the settings page where the user can manage Newsletter
$status = Products::STATUS_NEEDS_PURCHASE_OR_FREE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This status has been replaced with STATUS_NEEDS_ACTIVATION in the PR I linked to in a previous comment FYI, you might want to rebase and update that so there are no issues with an undefined constant 😄

}
return $status;
}

/**
* Checks whether the product can be upgraded to a different product.
* Newsletter is not upgradable.
*
* @return boolean
*/
public static function is_upgradable() {
return false;
}

/**
* Checks if the site has a paid plan that supports this product
*
* @return boolean
*/
public static function has_paid_plan_for_product() {
$purchases_data = Wpcom_Products::get_site_current_purchases();
if ( is_wp_error( $purchases_data ) ) {
return false;
}
if ( is_array( $purchases_data ) && ! empty( $purchases_data ) ) {
foreach ( $purchases_data as $purchase ) {
// Newsletter is also part of Creator and Complete plans.
if ( strpos( $purchase->product_slug, 'jetpack_complete' ) !== false || str_starts_with( $purchase->product_slug, 'jetpack_creator' ) ) {
return true;
}
}
}
return false;
}

/**
* Checks whether the product supports trial or not.
* Since Jetpack Newsletter has a free product, it "supports" a trial.
*
* @return boolean
*/
public static function has_trial_support() {
return true;
}

/**
* Get the URL where the user manages the product
*
* @return ?string
*/
public static function get_manage_url() {
return admin_url( 'admin.php?page=jetpack#/settings?term=newsletter' );
}
}
Loading