| 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302 |
2x
2x
2x
2x
2x
2x
2x
98x
82x
67x
2x
108x
19x
89x
33x
56x
2x
98x
19x
2x
108x
2x
108x
2x
106x
106x
3x
103x
3x
100x
2x
98x
2x
108x
2x
2x
| import React from 'react';
import PropTypes from 'prop-types';
import {
Button,
Text,
ClockIcon,
WarningIcon,
} from '@bufferapp/components';
import {
borderWidth,
} from '@bufferapp/components/style/border';
import {
mystic,
} from '@bufferapp/components/style/color';
import PostFooterDelete from '../PostFooterDelete';
import PostFooterApproval from '../PostFooterApproval';
import HoverableText from '../../../HoverableText';
const postDetailsStyle = {
display: 'flex',
padding: '0.5rem 1rem',
backgroundColor: '#fcfcfc',
borderTop: `${borderWidth} solid ${mystic}`,
};
const postActionDetailsStyle = {
flexGrow: 1,
display: 'flex',
alignItems: 'center',
};
const postActionDetailsIconStyle = {
marginRight: '0.5rem',
display: 'flex',
alignItems: 'center',
};
const postControlsStyle = {
display: 'flex',
};
const postButtonEdit = {
marginLeft: '0.7rem',
};
const verticalLineStyle = {
marginRight: '0.7rem',
marginLeft: '0.7rem',
borderLeft: `${borderWidth} solid ${mystic}`,
};
/* eslint-disable react/prop-types */
const renderEdit = ({
hasPermission,
manager,
onEditClick,
view,
}) => {
if (!hasPermission) return;
if (!manager && view === 'approval') return;
return (
<span style={postButtonEdit}>
<Button onClick={onEditClick} noStyle>
<HoverableText
size={'small'}
>
Edit
</HoverableText>
</Button>
</span>
);
};
const renderIcon = ({ isPastDue, scheduledAt }) => {
if (isPastDue) {
return (
<div style={postActionDetailsIconStyle}>
<WarningIcon color={'torchRed'} />
</div>
);
} else if (scheduledAt) {
return (
<div style={postActionDetailsIconStyle}>
<ClockIcon />
</div>
);
}
return null;
};
const renderMoveToDrafts = ({
hasPermission,
onMoveToDraftsClick,
view,
}) => {
if (view !== 'approval' || !hasPermission) return;
return (<span>
<span style={verticalLineStyle} />
<Button onClick={onMoveToDraftsClick} noStyle>
<HoverableText
size={'small'}
color={'curiousBlue'}
hoverColor={'toryBlue'}
>
Move to Drafts
</HoverableText>
</Button>
</span>);
};
const renderText = ({
draftDetails,
isPastDue,
view,
hasPermission,
manager,
}) =>
<span>
<Text
size={'small'}
color={isPastDue ? 'torchRed' : undefined}
>
{draftDetails.postAction}
</Text>
{
(hasPermission || manager) && isPastDue && view === 'drafts' ?
<Text size={'small'}> Please reschedule.</Text>
: null
}
</span>;
const renderControls = ({
hasPermission,
isDeleting,
isConfirmingDelete,
isMoving,
isPastDue,
isWorking,
manager,
onApproveClick,
onCancelConfirmClick,
onDeleteClick,
onEditClick,
onDeleteConfirmClick,
onMoveToDraftsClick,
onRescheduleClick,
onRequestApprovalClick,
view,
}) => {
if (isDeleting) {
return (
<Text size={'small'}> Deleting... </Text>
);
}
const approvalView = view === 'approval';
if (approvalView && isMoving) {
return (
<Text size={'small'}> Moving... </Text>
);
}
if (manager && isWorking) {
return (
<Text size={'small'}>{ approvalView ? 'Approving...' : 'Adding...' }</Text>
);
}
if (!approvalView && isWorking) {
return (
<Text size={'small'}> Requesting... </Text>
);
}
return (
<div>
{ hasPermission &&
<PostFooterDelete
isConfirmingDelete={isConfirmingDelete}
onCancelConfirmClick={onCancelConfirmClick}
onDeleteConfirmClick={onDeleteConfirmClick}
onDeleteClick={onDeleteClick}
/>
}
{renderEdit({
hasPermission,
manager,
onEditClick,
view,
})}
{renderMoveToDrafts({
hasPermission,
manager,
onMoveToDraftsClick,
view,
})}
<PostFooterApproval
hasPermission={hasPermission}
isPastDue={isPastDue}
onApproveClick={onApproveClick}
onRequestApprovalClick={onRequestApprovalClick}
onRescheduleClick={onRescheduleClick}
manager={manager}
view={view}
/>
</div>
);
};
/* eslint-enable react/prop-types */
const PostFooter = ({
hasPermission,
isDeleting,
isConfirmingDelete,
isMoving,
isPastDue,
isWorking,
manager,
onApproveClick,
onCancelConfirmClick,
onDeleteClick,
onDeleteConfirmClick,
onEditClick,
onMoveToDraftsClick,
onRequestApprovalClick,
onRescheduleClick,
scheduledAt,
draftDetails,
view,
}) =>
<div style={postDetailsStyle}>
<div style={postActionDetailsStyle}>
{renderIcon({ isPastDue, scheduledAt })}
{renderText({ draftDetails, scheduledAt, isPastDue, view, hasPermission, manager })}
</div>
<div style={postControlsStyle}>
{renderControls({
hasPermission,
isDeleting,
isConfirmingDelete,
isMoving,
isPastDue,
isWorking,
manager,
onApproveClick,
onCancelConfirmClick,
onDeleteClick,
onEditClick,
onMoveToDraftsClick,
onRequestApprovalClick,
onRescheduleClick,
onDeleteConfirmClick,
view,
})}
</div>
</div>;
PostFooter.propTypes = {
hasPermission: PropTypes.bool.isRequired,
isDeleting: PropTypes.bool,
isConfirmingDelete: PropTypes.bool,
isMoving: PropTypes.bool,
isPastDue: PropTypes.bool,
isWorking: PropTypes.bool,
manager: PropTypes.bool,
onApproveClick: PropTypes.func,
onCancelConfirmClick: PropTypes.func.isRequired,
onDeleteClick: PropTypes.func.isRequired,
onDeleteConfirmClick: PropTypes.func.isRequired,
onEditClick: PropTypes.func.isRequired,
onMoveToDraftsClick: PropTypes.func,
onRequestApprovalClick: PropTypes.func,
onRescheduleClick: PropTypes.func,
draftDetails: PropTypes.shape({
userName: PropTypes.string,
avatarUrl: PropTypes.string,
email: PropTypes.string,
createdAt: PropTypes.string,
via: PropTypes.string,
postAction: PropTypes.string,
}).isRequired,
scheduledAt: PropTypes.number,
view: PropTypes.string.isRequired,
};
PostFooter.defaultProps = {
isDeleting: false,
isConfirmingDelete: false,
isMoving: false,
isPastDue: false,
isWorking: false,
};
export default PostFooter;
|