/
deactivate-modal.tsx
155 lines (148 loc) · 4.42 KB
/
deactivate-modal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { useState } from 'react';
import { Button, Modal } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { dispatch, useSelect } from '@wordpress/data';
import { storeName } from '../../store';
import { AutomationStatus } from '../../../listing/automation';
type DeactivateImmediatelyModalProps = {
onClose: () => void;
};
export function DeactivateImmediatelyModal({
onClose,
}: DeactivateImmediatelyModalProps): JSX.Element {
const [isBusy, setIsBusy] = useState<boolean>(false);
return (
<Modal
className="mailpoet-automation-deactivate-modal"
title={__('Stop automation for all subscribers?', 'mailpoet')}
onRequestClose={onClose}
>
<p>
{__(
'Are you sure you want to deactivate now? This would stop this automation for all subscribers immediately.',
'mailpoet',
)}
</p>
<Button
isBusy={isBusy}
variant="primary"
onClick={() => {
setIsBusy(true);
void dispatch(storeName).deactivate(true);
}}
>
{__('Deactivate now', 'mailpoet')}
</Button>
<Button disabled={isBusy} variant="tertiary" onClick={onClose}>
{__('Cancel', 'mailpoet')}
</Button>
</Modal>
);
}
type DeactivateModalProps = {
onClose: () => void;
};
export function DeactivateModal({
onClose,
}: DeactivateModalProps): JSX.Element {
const { automationName } = useSelect(
(select) => ({
automationName: select(storeName).getAutomationData().name,
}),
[],
);
const [selected, setSelected] = useState<
AutomationStatus.DRAFT | AutomationStatus.DEACTIVATING
>(AutomationStatus.DEACTIVATING);
const [isBusy, setIsBusy] = useState<boolean>(false);
// translators: %s is the name of the automation.
const title = sprintf(
__('Deactivate the "%s" automation?', 'mailpoet'),
automationName,
);
return (
<Modal
className="mailpoet-automation-deactivate-modal"
title={title}
onRequestClose={onClose}
>
{__(
"Some subscribers entered but have not finished the flow. Let's decide what to do in this case.",
'mailpoet',
)}
<ul className="mailpoet-automation-options">
<li>
<label
className={
selected === AutomationStatus.DEACTIVATING
? 'mailpoet-automation-option active'
: 'mailpoet-automation-option'
}
>
<span>
<input
type="radio"
disabled={isBusy}
name="deactivation-method"
checked={selected === AutomationStatus.DEACTIVATING}
onChange={() => setSelected(AutomationStatus.DEACTIVATING)}
/>
</span>
<span>
<strong>
{__('Let entered subscribers finish the flow', 'mailpoet')}
</strong>
{__(
"New subscribers won't enter, but recently entered could proceed.",
'mailpoet',
)}
</span>
</label>
</li>
<li>
<label
className={
selected === AutomationStatus.DRAFT
? 'mailpoet-automation-option active'
: 'mailpoet-automation-option'
}
>
<span>
<input
type="radio"
disabled={isBusy}
name="deactivation-method"
checked={selected === AutomationStatus.DRAFT}
onChange={() => setSelected(AutomationStatus.DRAFT)}
/>
</span>
<span>
<strong>
{__('Stop automation for all subscribers', 'mailpoet')}
</strong>
{__(
'Automation will be deactivated for all the subscribers immediately.',
'mailpoet',
)}
</span>
</label>
</li>
</ul>
<Button
isBusy={isBusy}
variant="primary"
onClick={() => {
setIsBusy(true);
void dispatch(storeName).deactivate(
selected !== AutomationStatus.DEACTIVATING,
);
}}
>
{__('Deactivate automation', 'mailpoet')}
</Button>
<Button disabled={isBusy} variant="tertiary" onClick={onClose}>
{__('Cancel', 'mailpoet')}
</Button>
</Modal>
);
}