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: add Search interstitial view #22687

Merged
merged 9 commits into from
Feb 7, 2022
6 changes: 5 additions & 1 deletion projects/packages/my-jetpack/_inc/admin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Container, Col, JetpackFooter } from '@automattic/jetpack-components';
import MyJetpackScreen from './components/my-jetpack-screen';
import ConnectionScreen from './components/connection-screen';
import { initStore } from './state/store';
import { BoostInterstitial } from './components/product-interstitial';
import { BoostInterstitial, SearchInterstitial } from './components/product-interstitial';
import GoBackLink from './components/go-back-link';
import styles from './style.module.scss';

Expand Down Expand Up @@ -75,6 +75,10 @@ function render() {
path="/add-boost"
element={ <Layout nav={ true } children={ <BoostInterstitial /> } /> }
/>
<Route
path="/add-search"
element={ <Layout nav={ true } children={ <SearchInterstitial /> } /> }
/>
</Routes>
</HashRouter>,
container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export const PRODUCT_STATUSES = {
INACTIVE: 'inactive',
ERROR: 'error',
ABSENT: 'plugin_absent',
NEEDS_PURCHASE: 'needs_purchase',
};

const PRODUCT_STATUSES_LABELS = {
[ PRODUCT_STATUSES.ACTIVE ]: __( 'Active', 'jetpack-my-jetpack' ),
[ PRODUCT_STATUSES.INACTIVE ]: __( 'Inactive', 'jetpack-my-jetpack' ),
[ PRODUCT_STATUSES.NEEDS_PURCHASE ]: __( 'Inactive', 'jetpack-my-jetpack' ),
[ PRODUCT_STATUSES.ERROR ]: __( 'Error', 'jetpack-my-jetpack' ),
};

Expand Down Expand Up @@ -65,6 +67,7 @@ const renderActionButton = ( {
};

switch ( status ) {
case PRODUCT_STATUSES.NEEDS_PURCHASE:
case PRODUCT_STATUSES.ABSENT:
return (
<Button variant="link" onClick={ onAdd }>
Expand Down Expand Up @@ -110,12 +113,14 @@ const ProductCard = props => {
const isActive = status === PRODUCT_STATUSES.ACTIVE;
const isError = status === PRODUCT_STATUSES.ERROR;
const isInactive = status === PRODUCT_STATUSES.INACTIVE;
const isAbsent = status === PRODUCT_STATUSES.ABSENT;
const isAbsent = status === PRODUCT_STATUSES.ABSENT || status === PRODUCT_STATUSES.NEEDS_PURCHASE;
const isPurchaseRequired = status === PRODUCT_STATUSES.NEEDS_PURCHASE;
const flagLabel = PRODUCT_STATUSES_LABELS[ status ];
const canDeactivate = ( isActive || isError ) && admin;

const containerClassName = classNames( styles.container, {
[ styles.plugin_absent ]: isAbsent,
[ styles[ 'is-purchase-required' ] ]: isPurchaseRequired,
retrofox marked this conversation as resolved.
Show resolved Hide resolved
} );

const statusClassName = classNames( styles.status, {
Expand Down Expand Up @@ -211,6 +216,7 @@ ProductCard.propTypes = {
PRODUCT_STATUSES.INACTIVE,
PRODUCT_STATUSES.ERROR,
PRODUCT_STATUSES.ABSENT,
PRODUCT_STATUSES.NEEDS_PURCHASE,
] ).isRequired,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
flex-direction: column;
justify-content: space-between;

&.is-purchase-required,
&.plugin_absent {
background: none;
box-shadow: none;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* External dependencies
*/
import React from 'react';
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import { useNavigate } from 'react-router-dom';

/**
* Internal dependencies
Expand All @@ -21,6 +22,9 @@ const SearchCard = ( { admin } ) => {
const { status, activate, deactivate, detail, isFetching } = useProduct( 'search' );
const { name, description } = detail;

const navigate = useNavigate();
const onAddHandler = useCallback( () => navigate( '/add-search' ), [ navigate ] );

return (
<ProductCard
name={ name }
Expand All @@ -31,6 +35,7 @@ const SearchCard = ( { admin } ) => {
isFetching={ isFetching }
onDeactivate={ deactivate }
onActivate={ activate }
onAdd={ onAddHandler }
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { Container, Col } from '@automattic/jetpack-components';
*/
import { ProductDetail } from '../product-detail-card';
import styles from './style.module.scss';
import boostImage from './boost.png';
import useAnalytics from '../../hooks/use-analytics';
import boostImage from './boost.png';
import searchImage from './search.png';

/**
* Product Interstitial component.
Expand Down Expand Up @@ -61,7 +62,7 @@ export function BackupInterstitial() {
}

/**
* BoostInterstitial component
* SearchInterstitial component
*
* @returns {object} BoostInterstitial react component.
*/
Expand All @@ -72,3 +73,16 @@ export function BoostInterstitial() {
</ProductInterstitial>
);
}

/**
* SearchInterstitial component
*
* @returns {object} SearchInterstitial react component.
*/
export function SearchInterstitial() {
return (
<ProductInterstitial slug="search">
<img src={ searchImage } alt="Search" />
</ProductInterstitial>
);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import withMock from 'storybook-addon-mock';
/**
* Internal dependencies
*/
import ProductInterstitial, { BackupInterstitial, BoostInterstitial } from '../index.jsx';
import ProductInterstitial, {
BackupInterstitial,
BoostInterstitial,
SearchInterstitial,
} from '../index.jsx';

export default {
title: 'Packages/My Jetpack/Product Interstitial',
Expand All @@ -31,3 +35,7 @@ JetpackBackup.parameters = {};
const BoostTemplate = args => <BoostInterstitial { ...args } />;
export const JetpackBoost = BoostTemplate.bind( {} );
JetpackBoost.parameters = {};

const SearchTemplate = args => <SearchInterstitial { ...args } />;
export const JetpackSearch = SearchTemplate.bind( {} );
JetpackSearch.parameters = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Implement Search product interstitial
7 changes: 3 additions & 4 deletions projects/packages/my-jetpack/src/products/class-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ public static function has_required_plan() {
* @return string
*/
public static function get_status() {
if ( static::is_active() ) {
if ( ! static::has_required_plan() ) {
$status = 'needs_purchase';
} elseif ( static::is_active() ) {
$status = 'active';
if ( ! static::has_required_plan() ) {
$status = 'needs_purchase';
}
} elseif ( ! self::is_plugin_installed() ) {
$status = 'plugin_absent';
} else {
Expand Down