powr-sdk-web 6.14.0 → 6.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,12 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = PowrPost;
7
7
  var _react = _interopRequireDefault(require("react"));
8
- var _reactMarkdown = _interopRequireDefault(require("react-markdown"));
9
- var _remarkGfm = _interopRequireDefault(require("remark-gfm"));
10
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
9
  function PowrPost(_ref) {
12
10
  var post = _ref.post,
13
- cta = _ref.cta;
11
+ cta = _ref.cta,
12
+ body = _ref.body;
14
13
  if (!post) return null;
15
14
  var when = post.publishedAt ? new Date(post.publishedAt).toLocaleDateString() : "";
16
15
  return /*#__PURE__*/_react["default"].createElement("article", {
@@ -42,7 +41,5 @@ function PowrPost(_ref) {
42
41
  }
43
42
  }, post.description) : null, /*#__PURE__*/_react["default"].createElement("div", {
44
43
  className: "powr-post-body"
45
- }, /*#__PURE__*/_react["default"].createElement(_reactMarkdown["default"], {
46
- remarkPlugins: [_remarkGfm["default"]]
47
- }, post.bodyMd || "")), cta || null);
44
+ }, body || null), cta || null);
48
45
  }
@@ -103,6 +103,7 @@ function PowrPostWriter(_ref) {
103
103
  description: "",
104
104
  tags: "",
105
105
  coverUrl: "",
106
+ sourcePdfUrl: "",
106
107
  bodyMd: "",
107
108
  status: "draft"
108
109
  });
@@ -115,6 +116,7 @@ function PowrPostWriter(_ref) {
115
116
  description: row.description || "",
116
117
  tags: (row.tags || []).join(", "),
117
118
  coverUrl: row.coverUrl || "",
119
+ sourcePdfUrl: row.sourcePdfUrl || "",
118
120
  bodyMd: row.bodyMd || "",
119
121
  status: row.status,
120
122
  slug: row.slug,
@@ -149,6 +151,7 @@ function PowrPostWriter(_ref) {
149
151
  description: current.description,
150
152
  bodyMd: current.bodyMd,
151
153
  coverUrl: current.coverUrl,
154
+ sourcePdfUrl: current.sourcePdfUrl,
152
155
  tags: current.tags
153
156
  };
154
157
  path = current._id ? "/posts/".concat(current._id) : "/posts";
@@ -180,46 +183,145 @@ function PowrPostWriter(_ref) {
180
183
  }));
181
184
  return _save.apply(this, arguments);
182
185
  }
186
+ function submitPdf() {
187
+ return _submitPdf.apply(this, arguments);
188
+ }
189
+ function _submitPdf() {
190
+ _submitPdf = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
191
+ var _saved$data, _sent$data;
192
+ var sourcePdfUrl, title, body, path, saved, _saved$data2, row, sent, _sent$data2;
193
+ return _regenerator().w(function (_context3) {
194
+ while (1) switch (_context3.n) {
195
+ case 0:
196
+ if (current) {
197
+ _context3.n = 1;
198
+ break;
199
+ }
200
+ return _context3.a(2);
201
+ case 1:
202
+ sourcePdfUrl = String(current.sourcePdfUrl || "").trim();
203
+ if (sourcePdfUrl) {
204
+ _context3.n = 2;
205
+ break;
206
+ }
207
+ setError("Add the PDF first.");
208
+ return _context3.a(2);
209
+ case 2:
210
+ title = String(current.title || "").trim();
211
+ if (title) {
212
+ _context3.n = 3;
213
+ break;
214
+ }
215
+ setError("Add a title.");
216
+ return _context3.a(2);
217
+ case 3:
218
+ setError("");
219
+ setNotice("");
220
+ body = {
221
+ title: title,
222
+ description: current.description,
223
+ bodyMd: current.bodyMd,
224
+ coverUrl: current.coverUrl,
225
+ sourcePdfUrl: sourcePdfUrl,
226
+ tags: current.tags
227
+ };
228
+ path = current._id ? "/posts/".concat(current._id) : "/posts";
229
+ _context3.n = 4;
230
+ return (0, _auth.apiCall)(apiUrl, path, projectId, {
231
+ method: current._id ? "PATCH" : "POST",
232
+ headers: headers,
233
+ body: body
234
+ });
235
+ case 4:
236
+ saved = _context3.v;
237
+ if (!(!saved.ok || !((_saved$data = saved.data) !== null && _saved$data !== void 0 && _saved$data.success))) {
238
+ _context3.n = 5;
239
+ break;
240
+ }
241
+ setError(((_saved$data2 = saved.data) === null || _saved$data2 === void 0 ? void 0 : _saved$data2.message) || "Could not save.");
242
+ return _context3.a(2);
243
+ case 5:
244
+ row = saved.data.data;
245
+ if (!(row.status !== "draft")) {
246
+ _context3.n = 7;
247
+ break;
248
+ }
249
+ setNotice("Saved.");
250
+ open(row);
251
+ _context3.n = 6;
252
+ return load();
253
+ case 6:
254
+ return _context3.a(2);
255
+ case 7:
256
+ _context3.n = 8;
257
+ return (0, _auth.apiCall)(apiUrl, "/posts/".concat(row._id, "/submit"), projectId, {
258
+ method: "POST",
259
+ headers: headers
260
+ });
261
+ case 8:
262
+ sent = _context3.v;
263
+ if (!(!sent.ok || !((_sent$data = sent.data) !== null && _sent$data !== void 0 && _sent$data.success))) {
264
+ _context3.n = 10;
265
+ break;
266
+ }
267
+ setError(((_sent$data2 = sent.data) === null || _sent$data2 === void 0 ? void 0 : _sent$data2.message) || "Could not send it.");
268
+ open(row);
269
+ _context3.n = 9;
270
+ return load();
271
+ case 9:
272
+ return _context3.a(2);
273
+ case 10:
274
+ setNotice("Sent for review.");
275
+ open(sent.data.data);
276
+ _context3.n = 11;
277
+ return load();
278
+ case 11:
279
+ return _context3.a(2);
280
+ }
281
+ }, _callee3);
282
+ }));
283
+ return _submitPdf.apply(this, arguments);
284
+ }
183
285
  function submit() {
184
286
  return _submit.apply(this, arguments);
185
287
  }
186
288
  function _submit() {
187
- _submit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
289
+ _submit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
188
290
  var _yield$apiCall3, data, ok;
189
- return _regenerator().w(function (_context3) {
190
- while (1) switch (_context3.n) {
291
+ return _regenerator().w(function (_context4) {
292
+ while (1) switch (_context4.n) {
191
293
  case 0:
192
294
  if (current !== null && current !== void 0 && current._id) {
193
- _context3.n = 1;
295
+ _context4.n = 1;
194
296
  break;
195
297
  }
196
298
  setError("Save the draft first.");
197
- return _context3.a(2);
299
+ return _context4.a(2);
198
300
  case 1:
199
- _context3.n = 2;
301
+ _context4.n = 2;
200
302
  return (0, _auth.apiCall)(apiUrl, "/posts/".concat(current._id, "/submit"), projectId, {
201
303
  method: "POST",
202
304
  headers: headers
203
305
  });
204
306
  case 2:
205
- _yield$apiCall3 = _context3.v;
307
+ _yield$apiCall3 = _context4.v;
206
308
  data = _yield$apiCall3.data;
207
309
  ok = _yield$apiCall3.ok;
208
310
  if (!(!ok || !(data !== null && data !== void 0 && data.success))) {
209
- _context3.n = 3;
311
+ _context4.n = 3;
210
312
  break;
211
313
  }
212
314
  setError((data === null || data === void 0 ? void 0 : data.message) || "Could not send it.");
213
- return _context3.a(2);
315
+ return _context4.a(2);
214
316
  case 3:
215
317
  setNotice("Sent for review.");
216
318
  open(data.data);
217
- _context3.n = 4;
319
+ _context4.n = 4;
218
320
  return load();
219
321
  case 4:
220
- return _context3.a(2);
322
+ return _context4.a(2);
221
323
  }
222
- }, _callee3);
324
+ }, _callee4);
223
325
  }));
224
326
  return _submit.apply(this, arguments);
225
327
  }
@@ -270,7 +372,44 @@ function PowrPostWriter(_ref) {
270
372
  onChange: function onChange(event) {
271
373
  return setField("title", event.target.value);
272
374
  }
273
- })), /*#__PURE__*/_react["default"].createElement("label", null, "Short description", /*#__PURE__*/_react["default"].createElement("input", {
375
+ })), /*#__PURE__*/_react["default"].createElement("p", {
376
+ style: {
377
+ margin: "0 0 8px",
378
+ fontSize: 14
379
+ }
380
+ }, "PDF"), /*#__PURE__*/_react["default"].createElement(_uploader["default"], {
381
+ key: "pdf-".concat(current._id || "new"),
382
+ apiUrl: apiUrl,
383
+ projectId: projectId,
384
+ maxFiles: 1,
385
+ acceptedFileTypes: "application/pdf,.pdf",
386
+ initialFiles: current.sourcePdfUrl ? [{
387
+ url: current.sourcePdfUrl,
388
+ name: "article.pdf",
389
+ type: "application/pdf"
390
+ }] : [],
391
+ onUploadComplete: function onUploadComplete(files) {
392
+ var last = files && files[files.length - 1];
393
+ if (!last || !last.url) return;
394
+ var name = String(last.name || "");
395
+ if (last.type !== "application/pdf" && !/\.pdf$/i.test(name)) {
396
+ setError("That file needs to be a PDF.");
397
+ return;
398
+ }
399
+ setCurrent(function (prev) {
400
+ return _objectSpread(_objectSpread({}, prev || {}), {}, {
401
+ sourcePdfUrl: last.url,
402
+ title: prev && prev.title || name.replace(/\.pdf$/i, "").replace(/[-_]+/g, " ").trim()
403
+ });
404
+ });
405
+ }
406
+ }), !current.status || current.status === "draft" ? /*#__PURE__*/_react["default"].createElement("button", {
407
+ type: "button",
408
+ onClick: submitPdf,
409
+ style: {
410
+ margin: "8px 0 16px"
411
+ }
412
+ }, "Submit PDF") : null, /*#__PURE__*/_react["default"].createElement("label", null, "Short description", /*#__PURE__*/_react["default"].createElement("input", {
274
413
  style: field,
275
414
  value: current.description,
276
415
  onChange: function onChange(event) {
@@ -290,6 +429,7 @@ function PowrPostWriter(_ref) {
290
429
  return setField("coverUrl", event.target.value);
291
430
  }
292
431
  })), /*#__PURE__*/_react["default"].createElement(_uploader["default"], {
432
+ key: "img-".concat(current._id || "new"),
293
433
  apiUrl: apiUrl,
294
434
  projectId: projectId,
295
435
  maxFiles: 1,
@@ -298,7 +298,9 @@ function PowrPostsAdmin(_ref) {
298
298
  style: {
299
299
  color: "#6b7280"
300
300
  }
301
- }, row.status, " \xB7 ", ((_row$author = row.author) === null || _row$author === void 0 ? void 0 : _row$author.displayName) || "No name")), /*#__PURE__*/_react["default"].createElement("td", {
301
+ }, row.status, " \xB7 ", ((_row$author = row.author) === null || _row$author === void 0 ? void 0 : _row$author.displayName) || "No name", row.sourcePdfUrl ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, " · ", /*#__PURE__*/_react["default"].createElement("a", {
302
+ href: row.sourcePdfUrl
303
+ }, "PDF")) : null)), /*#__PURE__*/_react["default"].createElement("td", {
302
304
  style: {
303
305
  padding: 8,
304
306
  borderBottom: "1px solid #e5e7eb",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-web",
3
- "version": "6.14.0",
3
+ "version": "6.14.2",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"