Skip to content

Commit cb007f7

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

3 files changed

Lines changed: 45 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: 40 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,10 @@ 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+
console.log({ canUseMediaOffloading, settings, isMediaOffloadingLegacyFreeUser });
98+
return ! canUseMediaOffloading && isMediaOffloadingLegacyFreeUser && 'enabled' === settings?.['offload_media'];
99+
}, [ settings, canUseMediaOffloading, isMediaOffloadingLegacyFreeUser ]);
87100

88101
useEffect( () => {
89102
if ( isOffloadingInProgress ) {
@@ -181,14 +194,24 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
181194
[MODAL_STATE_OFFLOAD]: {
182195
icon: offload,
183196
onConfirm: () => {
184-
onOffloadMedia();
197+
if ( canUseMediaOffloading ) {
198+
onOffloadMedia();
199+
} else {
200+
window.open( optimoleDashboardApp.optimoleHome + 'pricing', '_blank' );
201+
}
185202
setModal( null );
186203
},
187204
labels: {
188205
title: options_strings.offloading_start_title,
189206
description: options_strings.offloading_start_description,
190-
action: options_strings.offloading_start_action
191-
}
207+
action: canUseMediaOffloading ? options_strings.offloading_start_action : optimoleDashboardApp.strings.upgrade.title_long
208+
},
209+
afterContentChildren: ! canUseMediaOffloading && (
210+
<Notice
211+
type="warning"
212+
text={options_strings.upgrade_to_use_offloading_notice_desc}
213+
/>
214+
)
192215
},
193216
[MODAL_STATE_ROLLBACK]: {
194217
icon: rollbackIcon,
@@ -297,6 +320,16 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
297320
<h1 className="text-xl font-bold">{options_strings.enable_offload_media_title}</h1>
298321
<p dangerouslySetInnerHTML={{ __html: options_strings.enable_offload_media_desc }}/>
299322

323+
{
324+
showDisabledOffloadingNotice && (
325+
<Notice
326+
type="warning"
327+
title={options_strings.plan_update_notice_title}
328+
text={options_strings.plan_update_notice_desc}
329+
/>
330+
)
331+
}
332+
300333
{offloadFinishNotice && (
301334
<Notice
302335
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)