step-footer.jsx
3.65 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* External dependencies
*/
import React from 'react';
/**
* WordPress dependencies
*/
const { __ } = wp.i18n;
export default ({
currentStep,
setCurrentStep,
serverType,
rulesMethod,
setRulesError,
makeRequest,
}) => {
const genericRequestError = __(
'Something went wrong with the request.',
'wp-smushit'
);
const checkStatus = () => {
setRulesError(false);
makeRequest('smush_webp_get_status')
.then((res) => {
if (res.success) {
setCurrentStep(currentStep + 1);
} else {
setRulesError(res.data);
}
})
.catch(() => setRulesError(genericRequestError));
};
const applyRules = () => {
setRulesError(false);
makeRequest('smush_webp_apply_htaccess_rules')
.then((res) => {
if (res.success) {
return checkStatus();
}
setRulesError(res.data);
})
.catch(() => setRulesError(genericRequestError));
};
const hideWizard = (e) => {
e.currentTarget.classList.add(
'sui-button-onload',
'sui-button-onload-text'
);
makeRequest('smush_toggle_webp_wizard').then(() => location.reload());
};
// Markup stuff.
let buttonsLeft;
const quitButton = (
<button
type="button"
className="sui-button sui-button-ghost"
onClick={hideWizard}
>
<span className="sui-loading-text">
<span className="sui-icon-logout" aria-hidden="true"></span>
<span className="sui-hidden-xs">
{__('Quit setup', 'wp-smushit')}
</span>
<span className="sui-hidden-sm sui-hidden-md sui-hidden-lg">
{__('Quit', 'wp-smushit')}
</span>
</span>
<span
className="sui-icon-loader sui-loading"
aria-hidden="true"
></span>
</button>
);
if (1 !== currentStep) {
buttonsLeft = (
<button
type="button"
className="sui-button sui-button-compound sui-button-ghost"
onClick={() => setCurrentStep(currentStep - 1)}
>
<span className="sui-compound-desktop" aria-hidden="true">
<span className="sui-icon-arrow-left"></span>
{__('Previous', 'wp-smushit')}
</span>
<span className="sui-compound-mobile" aria-hidden="true">
<span className="sui-icon-arrow-left"></span>
</span>
<span className="sui-screen-reader-text">
{__('Previous', 'wp-smushit')}
</span>
</button>
);
}
const getButtonsRight = () => {
if (1 === currentStep) {
return (
<button
type="button"
className="sui-button sui-button-blue sui-button-icon-right"
onClick={() => setCurrentStep(currentStep + 1)}
>
{__('Next', 'wp-smushit')}
<span
className="sui-icon-arrow-right"
aria-hidden="true"
></span>
</button>
);
}
if (2 === currentStep) {
if ('apache' === serverType && 'automatic' === rulesMethod) {
return (
<button
type="button"
className="sui-button sui-button-blue"
onClick={applyRules}
>
{__('Apply rules', 'wp-smushit')}
</button>
);
}
return (
<button
type="button"
className="sui-button sui-button-blue"
onClick={checkStatus}
>
{__('Check status', 'wp-smushit')}
</button>
);
}
return (
<button
type="button"
className="sui-button sui-button-blue"
onClick={hideWizard}
>
<span className="sui-button-text-default">
{__('Finish', 'wp-smushit')}
</span>
<span className="sui-button-text-onload">
<span
className="sui-icon-loader sui-loading"
aria-hidden="true"
></span>
{__('Finishing setup…', 'wp-smushit')}
</span>
</button>
);
};
return (
<div className="sui-box-footer">
<div className="sui-actions-left">
{quitButton}
{buttonsLeft}
</div>
<div className="sui-actions-right">{getButtonsRight()}</div>
</div>
);
};