Skip to content

Commit f09d200

Browse files
Display warning popup before offloading
1 parent a123b70 commit f09d200

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed

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

+12-6
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' }) {
7+
export default function Modal({ icon, labels = {}, onRequestClose = () => {}, onConfirm = () => {}, variant = 'default', onAction2 = () => {} }) {
88

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

@@ -19,7 +19,7 @@ export default function Modal({ icon, labels = {}, onRequestClose = () => {}, on
1919
{
2020
'bg-mango-yellow': 'warning' === variant
2121
},
22-
'optml__button flex justify-center px-5 py-3 rounded font-bold min-h-40 basis-1/5'
22+
'inline-flex optml__button flex justify-center px-5 py-3 rounded font-bold min-h-40 basis-1/5'
2323
);
2424

2525
return (
@@ -53,10 +53,16 @@ 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-
57-
<Button variant="primary" className={ actionButtonClasses } onClick={ onConfirm }>
58-
{ labels.action }
59-
</Button>
56+
<div class="flex gap-4">
57+
<Button variant="primary" className={ actionButtonClasses } onClick={ onConfirm }>
58+
{ labels.action }
59+
</Button>
60+
{ labels.action2 && (
61+
<Button variant="link" className={ actionButtonClasses } onClick={ onAction2 }>
62+
{ labels.action2 }
63+
</Button>
64+
) }
65+
</div>
6066
</div>
6167
</CoreModal>
6268
);

assets/src/dashboard/parts/connected/dashboard/index.js

-12
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,6 @@ const ActivatedNotice = () => (
8080
</div>
8181
);
8282

83-
const ExceedPlanQuotaWarning = () => (
84-
<div className="flex gap-2 bg-warning text-danger border border-solid border-danger rounded relative px-6 py-5 mb-5">
85-
<Icon icon="warning" />
86-
87-
<p
88-
className="m-0"
89-
dangerouslySetInnerHTML={ { __html: optimoleDashboardApp.strings.exceed_plan_quota_notice } }
90-
/>
91-
</div>
92-
);
93-
9483
const Dashboard = () => {
9584
const {
9685
userData,
@@ -142,7 +131,6 @@ const Dashboard = () => {
142131
return (
143132
<div className="bg-white p-8 border-0 rounded-lg shadow-md">
144133
{ ( 0 < optimoleDashboardApp.strings.notice_just_activated.length && 'active' === userStatus ) && <ActivatedNotice/> }
145-
{ ( 0 < optimoleDashboardApp.strings.exceed_plan_quota_notice.length && 'active' === userStatus ) && <ExceedPlanQuotaWarning/> }
146134

147135
{ 'inactive' === userStatus && <InactiveWarning/> }
148136

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

+30-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import Modal from '../../components/Modal';
1414
import Logs from './Logs';
1515

1616
const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
17-
const { strings, cron_disabled } = optimoleDashboardApp;
17+
const { strings, cron_disabled, show_exceed_plan_quota_notice } = optimoleDashboardApp;
18+
1819
const { conflicts, options_strings } = strings;
1920

2021
const MODAL_STATE_OFFLOAD = 'offload';
2122
const MODAL_STATE_ROLLBACK = 'rollback';
2223
const MODAL_STATE_STOP_OFFLOAD = 'stopOffload';
2324
const MODAL_STATE_STOP_ROLLBACK = 'stopRollback';
25+
const MODAL_STATE_EXCEED_PLAN_QUOTA_NOTICE = 'planQuotaNotice';
2426

2527
const {
2628
offloadConflicts,
@@ -181,12 +183,12 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
181183
setCanSave( true );
182184

183185
if ( offloadEnabled ) {
184-
setModal( MODAL_STATE_OFFLOAD );
186+
setModal( show_exceed_plan_quota_notice ? MODAL_STATE_EXCEED_PLAN_QUOTA_NOTICE : MODAL_STATE_OFFLOAD );
185187

186188
return;
187189
}
188190

189-
setModal( MODAL_STATE_ROLLBACK );
191+
setModal( show_exceed_plan_quota_notice ? MODAL_STATE_EXCEED_PLAN_QUOTA_NOTICE : MODAL_STATE_ROLLBACK );
190192
};
191193

192194
const getModalProps = ( type ) => {
@@ -245,6 +247,29 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
245247
description: options_strings.rollback_stop_description,
246248
action: options_strings.rollback_stop_action
247249
}
250+
},
251+
[MODAL_STATE_EXCEED_PLAN_QUOTA_NOTICE]: {
252+
variant: 'warning',
253+
icon: warningAlt,
254+
onConfirm: () => {
255+
onOffloadMedia();
256+
setModal( null );
257+
},
258+
onAction2: () => {
259+
setModal( null );
260+
const options = settings;
261+
options.offload_media = 'disabled';
262+
saveSettings( options );
263+
264+
// Remove "unsaved changes" warning
265+
window.onbeforeunload = null;
266+
},
267+
labels: {
268+
title: options_strings.exceed_plan_quota_notice_title,
269+
description: options_strings.exceed_plan_quota_notice_description,
270+
action: options_strings.exceed_plan_quota_notice_start_action,
271+
action2: options_strings.exceed_plan_quota_notice_start_action2
272+
}
248273
}
249274
};
250275

@@ -270,11 +295,11 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
270295
e.preventDefault();
271296

272297
if ( 'offload' === radioBoxValue ) {
273-
setModal( MODAL_STATE_OFFLOAD );
298+
setModal( show_exceed_plan_quota_notice ? MODAL_STATE_EXCEED_PLAN_QUOTA_NOTICE : MODAL_STATE_OFFLOAD );
274299
}
275300

276301
if ( 'rollback' === radioBoxValue ) {
277-
setModal( MODAL_STATE_ROLLBACK );
302+
setModal( show_exceed_plan_quota_notice ? MODAL_STATE_EXCEED_PLAN_QUOTA_NOTICE : MODAL_STATE_ROLLBACK );
278303
}
279304
};
280305

inc/admin.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ private function localize_dashboard_app() {
13401340
],
13411341
],
13421342
'bf_notices' => $this->get_bf_notices(),
1343+
'show_exceed_plan_quota_notice' => $this->should_show_exceed_quota_warning(),
13431344
];
13441345
}
13451346

@@ -1537,14 +1538,6 @@ private function get_dashboard_strings() {
15371538
'</b>',
15381539
'<br>'
15391540
),
1540-
'exceed_plan_quota_notice' => $this->should_show_exceed_quota_warning() ?
1541-
sprintf(
1542-
/* translators: 1 starting bold tag, 2 is the ending bold tag */
1543-
__( '%1$sYour site has already reached over 50%% of your monthly visits limit within just two weeks.%2$s <br/> 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 upgrading your plan or waiting until your traffic stabilizes before offloading your images. Do you still wish to proceed?', 'optimole-wp' ),
1544-
'<strong>',
1545-
'</strong>'
1546-
)
1547-
: '',
15481541
'signup_terms' => sprintf(
15491542
/* translators: 1 is starting anchor tag to terms, 2 is starting anchor tag to privacy link and 3 is ending anchor tag. */
15501543
__( 'By signing up, you agree to our %1$sTerms of Service %3$s and %2$sPrivacy Policy %3$s.', 'optimole-wp' ),
@@ -1892,6 +1885,10 @@ private function get_dashboard_strings() {
18921885
'rollback_stop_title' => __( 'Are you sure?', 'optimole-wp' ),
18931886
'rollback_stop_description' => __( 'Canceling will halt the ongoing process, and any remaining images will stay in the Optimole Cloud. To transfer images to the Optimole Cloud, use the Offloading option.', 'optimole-wp' ),
18941887
'rollback_stop_action' => __( 'Cancel the transfer from Optimole', 'optimole-wp' ),
1888+
'exceed_plan_quota_notice_title' => __( 'Your site has already reached over 50% of your monthly visits limit within just two weeks.', 'optimole-wp' ),
1889+
'exceed_plan_quota_notice_description' => __( '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 upgrading your plan or waiting until your traffic stabilizes before offloading your images. Do you still wish to proceed?', 'optimole-wp' ),
1890+
'exceed_plan_quota_notice_start_action' => __( 'Yes, Transfer to Optimole Cloud', 'optimole-wp' ),
1891+
'exceed_plan_quota_notice_start_action2' => __( 'No', 'optimole-wp' ),
18951892
],
18961893
'help' => [
18971894
'section_one_title' => __( 'Help and Support', 'optimole-wp' ),

0 commit comments

Comments
 (0)