2023-09-21 14:00:04 +00:00
/ * *
* External dependencies
* /
import { getNewPath } from '@woocommerce/navigation' ;
2023-10-23 05:55:23 +00:00
import { Button , Tooltip } from '@wordpress/components' ;
2023-10-18 09:14:14 +00:00
import { useContext } from '@wordpress/element' ;
2023-10-23 05:55:23 +00:00
import { __ , sprintf } from '@wordpress/i18n' ;
import { help } 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-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-09-21 14:11:19 +00:00
const updateConnectionUrl = getNewPath (
{
page : 'wc-addons' ,
section : 'helper' ,
filter : 'all' ,
'wc-helper-refresh' : 1 ,
'wc-helper-nonce' : getAdminSetting ( 'wc_helper_nonces' ) . refresh ,
2023-10-18 10:07:18 +00:00
'redirect-to-wc-admin' : 1 ,
2023-09-21 14:11:19 +00:00
} ,
''
) ;
const updateConnectionHTML = sprintf (
2023-09-26 12:12:14 +00:00
// translators: %s is a link to the update connection page.
2023-09-21 14:11:19 +00:00
__ (
'If you don\'t see your subscription, try <a href="%s">updating</a> your connection.' ,
'woocommerce'
) ,
updateConnectionUrl
) ;
2023-09-21 14:00:04 +00:00
2023-09-26 12:12:14 +00:00
const subscriptionsInstalled : Array < Subscription > = subscriptions . filter (
2023-09-28 18:58:07 +00:00
( subscription : Subscription ) = > subscription . local . 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 (
2023-09-27 10:21:50 +00:00
( subscription : Subscription ) = >
! subscriptionsInstalled . includes ( subscription )
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 ) {
return (
< div className = "woocommerce-marketplace__my-subscriptions--connect" >
< 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" >
{ __ (
'Connect your account to get updates, manage your subscriptions, and get seamless support. Once connected, your WooCommerce.com subscriptions will appear here.' ,
'woocommerce'
) }
< / p >
< Button href = { wccomSettings ? . connectURL } variant = "primary" >
{ __ ( 'Connect Account' , 'woocommerce' ) }
< / Button >
< / div >
) ;
}
2023-09-21 14:00:04 +00:00
return (
< div className = "woocommerce-marketplace__my-subscriptions" >
< section >
2023-10-18 09:14:14 +00:00
< h2 className = "woocommerce-marketplace__my-subscriptions__header" >
{ __ ( 'Installed on this store' , 'woocommerce' ) }
< / h2 >
< p className = "woocommerce-marketplace__my-subscriptions__table-description" >
2023-09-21 14:11:19 +00:00
< span
dangerouslySetInnerHTML = { {
__html : updateConnectionHTML ,
} }
/ >
2023-09-21 14:00:04 +00:00
< Tooltip
text = {
< >
2023-09-22 10:05:42 +00:00
< h3 >
{ __ (
"Still don't see your subscription?" ,
'woocommerce'
) }
< / h3 >
< p
dangerouslySetInnerHTML = { {
__html : __ (
'To see all your subscriptions go to <a href="https://woocommerce.com/my-account/" target="_blank" class="woocommerce-marketplace__my-subscriptions__tooltip-external-link">your account</a> on WooCommerce.com.' ,
'woocommerce'
) ,
} }
/ >
2023-09-21 14:00:04 +00:00
< / >
}
>
2023-09-21 14:11:19 +00:00
< Button
icon = { help }
iconSize = { 20 }
isSmall = { true }
label = { __ ( 'Help' , 'woocommerce' ) }
/ >
2023-09-21 14:00:04 +00:00
< / Tooltip >
< / p >
2023-10-18 09:14:14 +00:00
< InstalledSubscriptionsTable
isLoading = { isLoading }
2023-09-21 14:00:04 +00:00
rows = { subscriptionsInstalled . map ( ( item ) = > {
2023-10-18 09:14:14 +00:00
return installedSubscriptionRow ( item ) ;
2023-09-21 14:00:04 +00:00
} ) }
/ >
< / section >
< section >
2023-10-18 09:14:14 +00:00
< h2 className = "woocommerce-marketplace__my-subscriptions__header" >
{ __ ( 'Not in use' , 'woocommerce' ) }
< / h2 >
< p className = "woocommerce-marketplace__my-subscriptions__table-description" >
2023-09-21 14:11:19 +00:00
{ __ (
2023-10-18 09:14:14 +00:00
'Your unused WooCommerce.com subscriptions.' ,
2023-09-21 14:11:19 +00:00
'woocommerce'
) }
2023-09-21 14:00:04 +00:00
< / p >
2023-10-18 09:14:14 +00:00
< AvailableSubscriptionsTable
isLoading = { isLoading }
2023-09-21 14:00:04 +00:00
rows = { subscriptionsAvailable . map ( ( item ) = > {
2023-10-18 09:14:14 +00:00
return availableSubscriptionRow ( item ) ;
2023-09-21 14:00:04 +00:00
} ) }
/ >
< / section >
2023-10-18 09:14:14 +00:00
< section >
< h2 className = "woocommerce-marketplace__my-subscriptions__header" >
{ __ ( 'Free to install' , 'woocommerce' ) }
< / h2 >
< p className = "woocommerce-marketplace__my-subscriptions__table-description" >
{ __ (
'Easily install your existing free to install WooCommerce.com subscriptions across sites.' ,
'woocommerce'
) }
< / p >
< AvailableSubscriptionsTable
isLoading = { isLoading }
// TODO: fetch free and uninstalled subscriptions.
rows = { [ ] }
/ >
< / section >
2023-09-21 14:00:04 +00:00
< / div >
) ;
}