Skip to content

Commit bc58c04

Browse files
feat: add notices for offload restriction and upgrade
1 parent f2794c7 commit bc58c04

3 files changed

Lines changed: 44 additions & 8 deletions

File tree

assets/src/dashboard/parts/components/Modal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { close } from '@wordpress/icons';
44
import { useViewportMatch } from '@wordpress/compose';
55
import { Button, Icon, Modal as CoreModal } from '@wordpress/components';
66

7-
export default function Modal({ icon, labels = {}, onRequestClose = () => {}, onConfirm = () => {}, variant = 'default', onSecondaryAction = () => {} }) {
7+
export default function Modal({ icon, labels = {}, onRequestClose = () => {}, onConfirm = () => {}, variant = 'default', onSecondaryAction = () => {}, afterContentChildren = null }) {
88

99
const isMobileViewport = useViewportMatch( 'small', '<' );
1010

@@ -53,6 +53,7 @@ export default function Modal({ icon, labels = {}, onRequestClose = () => {}, on
5353
className="text-center mx-0 my-4 text-gray-700"
5454
dangerouslySetInnerHTML={ { __html: labels.description } }
5555
/>
56+
{ afterContentChildren }
5657
<div class="flex gap-4">
5758
<Button variant="primary" className={ actionButtonClasses } onClick={ onConfirm }>
5859
{ labels.action }

assets/src/dashboard/parts/connected/settings/OffloadMedia.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import classnames from 'classnames';
44
import { useEffect, useState } from '@wordpress/element';
5-
import { useDispatch, useSelect } from '@wordpress/data';
5+
import { useDispatch, useSelect, useMemo } from '@wordpress/data';
66
import { Icon } from '@wordpress/icons';
77

88
import { warning, rollback as rollbackIcon, offload, warningAlt, sync } from '../../../utils/icons';
@@ -37,7 +37,9 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
3737
processedImages,
3838
offloadFinishNotice,
3939
offloadLimitReached,
40-
offloadLimit
40+
offloadLimit,
41+
canUseMediaOffloading,
42+
isMediaOffloadingLegacyFreeUser
4143
} = useSelect( select => {
4244
const {
4345
getOffloadConflicts,
@@ -51,9 +53,14 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
5153
getQueryArgs,
5254
isLoading,
5355
getSiteSettings,
54-
getOffloadLimit
56+
getOffloadLimit,
57+
getUserData
5558
} = select( 'optimole' );
5659

60+
const userData = getUserData();
61+
const canUseMediaOffloading = Boolean( userData?.can_use_offloading );
62+
const isMediaOffloadingLegacyFreeUser = Boolean( userData?.is_legacy_offloading_free_user );
63+
5764
return {
5865
offloadConflicts: getOffloadConflicts(),
5966
errorMedia: getErrorMedia(),
@@ -67,7 +74,9 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
6774
processedImages: getProcessedImages(),
6875
offloadFinishNotice: getSiteSettings( 'show_offload_finish_notice' ),
6976
offloadLimitReached: 'enabled' === getSiteSettings( 'offload_limit_reached' ),
70-
offloadLimit: getOffloadLimit()
77+
offloadLimit: getOffloadLimit(),
78+
canUseMediaOffloading,
79+
isMediaOffloadingLegacyFreeUser
7180
};
7281
}, []);
7382

@@ -84,6 +93,9 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
8493
const isOffloadingInProgress = 'disabled' !== settings['offloading_status'];
8594
const isRollbackInProgress = 'disabled' !== settings['rollback_status'];
8695

96+
const showDisabledOffloadingNotice = useMemo( () => {
97+
return ! canUseMediaOffloading && isMediaOffloadingLegacyFreeUser && 'enabled' === settings?.['offload_media'];
98+
}, [ settings, canUseMediaOffloading, isMediaOffloadingLegacyFreeUser ]);
8799

88100
useEffect( () => {
89101
if ( isOffloadingInProgress ) {
@@ -181,14 +193,24 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
181193
[MODAL_STATE_OFFLOAD]: {
182194
icon: offload,
183195
onConfirm: () => {
184-
onOffloadMedia();
196+
if ( canUseMediaOffloading ) {
197+
onOffloadMedia();
198+
} else {
199+
window.open( optimoleDashboardApp.optimoleHome + 'pricing', '_blank' );
200+
}
185201
setModal( null );
186202
},
187203
labels: {
188204
title: options_strings.offloading_start_title,
189205
description: options_strings.offloading_start_description,
190-
action: options_strings.offloading_start_action
191-
}
206+
action: canUseMediaOffloading ? options_strings.offloading_start_action : optimoleDashboardApp.strings.upgrade.title_long
207+
},
208+
afterContentChildren: ! canUseMediaOffloading && (
209+
<Notice
210+
type="warning"
211+
text={options_strings.upgrade_to_use_offloading_notice_desc}
212+
/>
213+
)
192214
},
193215
[MODAL_STATE_ROLLBACK]: {
194216
icon: rollbackIcon,
@@ -297,6 +319,16 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
297319
<h1 className="text-xl font-bold">{options_strings.enable_offload_media_title}</h1>
298320
<p dangerouslySetInnerHTML={{ __html: options_strings.enable_offload_media_desc }}/>
299321

322+
{
323+
showDisabledOffloadingNotice && (
324+
<Notice
325+
type="warning"
326+
title={options_strings.plan_update_notice_title}
327+
text={options_strings.plan_update_notice_desc}
328+
/>
329+
)
330+
}
331+
300332
{offloadFinishNotice && (
301333
<Notice
302334
title={'offload' === offloadFinishNotice ? options_strings.offloading_success : options_strings.rollback_success }

inc/admin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,9 @@ private function get_dashboard_strings() {
20382038
'exceed_plan_quota_notice_description' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Based on this trend, you are likely to exceed your free quota before the month ends. To avoid any disruption in service, we strongly recommend %1$supgrading%2$s your plan or waiting until your traffic stabilizes before offloading your images. Do you still wish to proceed?', 'optimole-wp' ), '<a style="white-space: nowrap;" target=”_blank” href="https://dashboard.optimole.com/settings/billing/">', '</a>' ),
20392039
'exceed_plan_quota_notice_start_action' => __( 'Yes, Transfer to Optimole Cloud', 'optimole-wp' ),
20402040
'exceed_plan_quota_notice_secondary_action' => __( 'No, keep images on my website', 'optimole-wp' ),
2041+
'plan_update_notice_title' => __( 'Plan Update', 'optimole-wp' ),
2042+
'plan_update_notice_desc' => __( 'We\'ve changed how plans work. Users on Optimole Free plan can not offload new image. Existing images that are already offloaded will remain offloaded.', 'optimole-wp' ),
2043+
'upgrade_to_use_offloading_notice_desc' => __( 'Offloading images is a PRO feature. Please upgrade your plan to enable image transfer to Optimole Cloud.', 'optimole-wp' ),
20412044
],
20422045
'help' => [
20432046
'section_one_title' => __( 'Help and Support', 'optimole-wp' ),

0 commit comments

Comments
 (0)