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

A4A: Add upgrade link to WordPress.com/Pressable licenses #99175

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Button } from '@automattic/components';
import { Icon, external } from '@wordpress/icons';
import { useTranslate } from 'i18n-calypso';
import { useCallback, useState, useEffect } from 'react';
import { isPressableHostingProduct } from 'calypso/a8c-for-agencies/sections/marketplace/lib/hosting';
import {
isPressableHostingProduct,
isWPCOMHostingProduct,
} from 'calypso/a8c-for-agencies/sections/marketplace/lib/hosting';
import {
LicenseRole,
LicenseState,
Expand All @@ -25,6 +28,7 @@ interface Props {
licenseType: LicenseType;
hasDownloads: boolean;
isChildLicense?: boolean;
isClientLicense?: boolean;
}

export default function LicenseDetailsActions( {
Expand All @@ -35,6 +39,7 @@ export default function LicenseDetailsActions( {
licenseType,
hasDownloads,
isChildLicense,
isClientLicense,
}: Props ) {
const dispatch = useDispatch();
const translate = useTranslate();
Expand All @@ -45,6 +50,7 @@ export default function LicenseDetailsActions( {

const [ revokeDialog, setRevokeDialog ] = useState( false );
const isPressableLicense = isPressableHostingProduct( licenseKey );
const isWPCOMHostingLicense = isWPCOMHostingProduct( licenseKey );
const pressableManageUrl = 'https://my.pressable.com/agency/auth';

const debugUrl = siteUrl ? `https://jptools.wordpress.com/debug/?url=${ siteUrl }` : null;
Expand Down Expand Up @@ -113,6 +119,19 @@ export default function LicenseDetailsActions( {
</Button>
) }

{ ( isPressableLicense || isWPCOMHostingLicense ) &&
licenseState !== LicenseState.Revoked &&
! isClientLicense && (
<Button
compact
href={
isPressableLicense ? '/marketplace/hosting/pressable' : '/marketplace/hosting/wpcom'
}
>
{ translate( 'Upgrade' ) }
</Button>
) }

{ canRevoke &&
( isChildLicense
? licenseState === LicenseState.Attached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export default function LicenseDetails( {
licenseType={ licenseType }
hasDownloads={ hasDownloads }
isChildLicense={ isChildLicense }
isClientLicense={ !! ( isAutomatedReferralsEnabled && referral ) }
/>
</Card>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export default function LicensePreview( {
revokedAt={ revokedAt }
licenseType={ licenseType }
isChildLicense={ isChildLicense }
isClientLicense={ !! isClientLicense }
/>
) : (
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Props {
revokedAt: string | null;
licenseType: LicenseType;
isChildLicense?: boolean;
isClientLicense?: boolean;
}

export default function LicenseActions( {
Expand All @@ -21,6 +22,7 @@ export default function LicenseActions( {
revokedAt,
licenseType,
isChildLicense,
isClientLicense,
}: Props ) {
const buttonActionRef = useRef< HTMLButtonElement | null >( null );

Expand All @@ -32,7 +34,8 @@ export default function LicenseActions( {
attachedAt,
revokedAt,
licenseType,
isChildLicense
isChildLicense,
isClientLicense
);

const handleActionClick = ( action: LicenseAction ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default function useLicenseActions(
attachedAt: string | null,
revokedAt: string | null,
licenseType: LicenseType,
isChildLicense?: boolean
isChildLicense?: boolean,
isClientLicense?: boolean
): LicenseAction[] {
const translate = useTranslate();
const dispatch = useDispatch();
Expand Down Expand Up @@ -82,6 +83,13 @@ export default function useLicenseActions(
isExternalLink: true,
isEnabled: licenseState === LicenseState.Attached,
},
{
name: translate( 'Upgrade' ),
href: `/marketplace/hosting/wpcom`,
onClick: () => handleClickMenuItem( 'calypso_a4a_licenses_upgrade_click' ),
isExternalLink: false,
isEnabled: ! isClientLicense,
},
{
name: translate( 'Revoke' ),
href: `https://wordpress.com/purchases/subscriptions/${ siteSlug }`,
Expand All @@ -102,6 +110,7 @@ export default function useLicenseActions(
canRevoke,
dispatch,
isChildLicense,
isClientLicense,
isDevSite,
licenseType,
revokedAt,
Expand Down