2023-09-21 14:00:04 +00:00
/ * *
* External dependencies
* /
2023-11-08 10:26:44 +00:00
import { Button } from '@wordpress/components' ;
import { __ } from '@wordpress/i18n' ;
import { createInterpolateElement , useContext } from '@wordpress/element' ;
import { Icon , external } from '@wordpress/icons' ;
2023-09-21 14:00:04 +00:00
/ * *
* Internal dependencies
* /
2023-09-26 12:12:14 +00:00
import { getAdminSetting } from '../../../utils/admin-settings' ;
2023-10-23 05:55:23 +00:00
import { SubscriptionsContext } from '../../contexts/subscriptions-context' ;
2023-09-21 14:00:04 +00:00
import './my-subscriptions.scss' ;
2023-10-18 09:14:14 +00:00
import {
AvailableSubscriptionsTable ,
2023-10-23 05:55:23 +00:00
InstalledSubscriptionsTable ,
2023-10-18 09:14:14 +00:00
} from './table/table' ;
import {
availableSubscriptionRow ,
2023-10-23 05:55:23 +00:00
installedSubscriptionRow ,
2023-10-18 09:14:14 +00:00
} from './table/table-rows' ;
2023-10-23 05:55:23 +00:00
import { Subscription } from './types' ;
2023-11-16 10:51:30 +00:00
import { RefreshButton } from './table/actions/refresh-button' ;
import Notices from './notices' ;
2023-12-14 11:45:40 +00:00
import InstallModal from './table/actions/install-modal' ;
2024-01-10 06:20:15 +00:00
import { connectUrl } from '../../utils/functions' ;
2023-09-21 14:00:04 +00:00
export default function MySubscriptions ( ) : JSX . Element {
2023-10-18 09:14:14 +00:00
const { subscriptions , isLoading } = useContext ( SubscriptionsContext ) ;
2023-10-23 05:55:23 +00:00
const wccomSettings = getAdminSetting ( 'wccomHelper' , { } ) ;
2023-09-26 12:12:14 +00:00
2023-11-08 10:26:44 +00:00
const installedTableDescription = createInterpolateElement (
2023-09-21 14:11:19 +00:00
__ (
2024-04-09 08:50:15 +00:00
'WooCommerce.com extensions and themes installed on this store. To see all your subscriptions go to <a>your account<custom_icon /></a> on WooCommerce.com.' ,
2023-09-21 14:11:19 +00:00
'woocommerce'
) ,
2023-11-08 10:26:44 +00:00
{
a : (
< a
2024-04-09 08:50:15 +00:00
href = "https://woocommerce.com/my-account/my-subscriptions"
2023-11-08 10:26:44 +00:00
target = "_blank"
rel = "nofollow noopener noreferrer"
>
your account
< / a >
) ,
custom_icon : < Icon icon = { external } size = { 12 } / > ,
}
2023-09-21 14:11:19 +00:00
) ;
2023-09-21 14:00:04 +00:00
2023-09-26 12:12:14 +00:00
const subscriptionsInstalled : Array < Subscription > = subscriptions . filter (
2023-11-10 05:11:40 +00:00
( subscription : Subscription ) = > subscription . subscription_installed
2023-09-26 12:12:14 +00:00
) ;
2023-09-21 14:00:04 +00:00
2023-09-26 12:12:14 +00:00
const subscriptionsAvailable : Array < Subscription > = subscriptions . filter (
2024-03-20 14:02:23 +00:00
( subscription : Subscription ) = >
! subscription . subscription_installed &&
wccomSettings ? . wooUpdateManagerPluginSlug !==
subscription . product_slug
2023-09-26 12:12:14 +00:00
) ;
2023-09-21 14:00:04 +00:00
2023-10-23 05:55:23 +00:00
if ( ! wccomSettings ? . isConnected ) {
2024-04-23 15:38:11 +00:00
const connectMessage = __ (
"Connect your store to WooCommerce.com using the WooCommerce.com Update Manager. Once connected, you'll be able to manage your subscriptions, receive product updates, and access streamlined support from this screen." ,
'woocommerce'
) ;
2023-10-23 05:55:23 +00:00
return (
< div className = "woocommerce-marketplace__my-subscriptions--connect" >
2023-12-14 11:45:40 +00:00
< InstallModal / >
2023-10-23 05:55:23 +00:00
< div className = "woocommerce-marketplace__my-subscriptions__icon" / >
< h2 className = "woocommerce-marketplace__my-subscriptions__header" >
{ __ ( 'Manage your subscriptions' , 'woocommerce' ) }
< / h2 >
< p className = "woocommerce-marketplace__my-subscriptions__description" >
2024-04-23 15:38:11 +00:00
{ connectMessage }
2023-10-23 05:55:23 +00:00
< / p >
2024-01-10 06:20:15 +00:00
< Button href = { connectUrl ( ) } variant = "primary" >
2024-03-20 14:02:23 +00:00
{ __ ( 'Connect your store' , 'woocommerce' ) }
2023-10-23 05:55:23 +00:00
< / Button >
< / div >
) ;
}
2023-09-21 14:00:04 +00:00
return (
< div className = "woocommerce-marketplace__my-subscriptions" >
2023-12-14 11:45:40 +00:00
< InstallModal / >
2023-11-16 10:51:30 +00:00
< section className = "woocommerce-marketplace__my-subscriptions__notices" >
< Notices / >
< / section >
2023-11-21 07:08:26 +00:00
< section className = "woocommerce-marketplace__my-subscriptions-section woocommerce-marketplace__my-subscriptions__installed" >
2023-11-08 10:26:44 +00:00
< header className = "woocommerce-marketplace__my-subscriptions__header" >
2023-11-21 11:43:06 +00:00
< div className = "woocommerce-marketplace__my-subscriptions__header-content" >
2023-11-08 10:26:44 +00:00
< h2 className = "woocommerce-marketplace__my-subscriptions__heading" >
{ __ ( 'Installed on this store' , 'woocommerce' ) }
< / h2 >
2023-11-21 07:08:26 +00:00
< p className = "woocommerce-marketplace__my-subscriptions__table-description" >
2023-11-08 10:26:44 +00:00
{ installedTableDescription }
2023-11-21 07:08:26 +00:00
< / p >
2023-11-08 10:26:44 +00:00
< / div >
2023-11-21 07:08:26 +00:00
< div className = "woocommerce-marketplace__my-subscriptions__header-refresh" >
2023-11-16 10:51:30 +00:00
< RefreshButton / >
2023-11-08 10:26:44 +00:00
< / div >
< / header >
2023-11-21 11:43:06 +00:00
< div className = "woocommerce-marketplace__my-subscriptions__table-wrapper" >
< InstalledSubscriptionsTable
isLoading = { isLoading }
rows = { subscriptionsInstalled . map ( ( item ) = > {
return installedSubscriptionRow ( item ) ;
} ) }
/ >
< / div >
2023-09-21 14:00:04 +00:00
< / section >
2023-11-21 07:33:06 +00:00
{ subscriptionsAvailable . length > 0 && (
< section className = "woocommerce-marketplace__my-subscriptions-section woocommerce-marketplace__my-subscriptions__available" >
< h2 className = "woocommerce-marketplace__my-subscriptions__heading" >
{ __ ( 'Available to use' , 'woocommerce' ) }
< / h2 >
< p className = "woocommerce-marketplace__my-subscriptions__table-description" >
{ __ (
2024-04-09 08:50:15 +00:00
"WooCommerce.com subscriptions you haven't used yet." ,
2023-11-21 07:33:06 +00:00
'woocommerce'
) }
< / p >
2023-11-21 11:43:06 +00:00
< div className = "woocommerce-marketplace__my-subscriptions__table-wrapper" >
< AvailableSubscriptionsTable
isLoading = { isLoading }
rows = { subscriptionsAvailable . map ( ( item ) = > {
return availableSubscriptionRow ( item ) ;
} ) }
/ >
< / div >
2023-11-21 07:33:06 +00:00
< / section >
) }
2023-09-21 14:00:04 +00:00
< / div >
) ;
}