@micromag/data 0.3.676 → 0.3.698
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.
- package/es/index.js +17 -5
- package/package.json +3 -3
package/es/index.js
CHANGED
|
@@ -9,10 +9,10 @@ import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
|
|
|
9
9
|
import { generatePath } from '@folklore/routes';
|
|
10
10
|
import queryString from 'query-string';
|
|
11
11
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
12
|
+
import { useVisitor, useStory } from '@micromag/core/contexts';
|
|
12
13
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
13
14
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
14
15
|
import isString from 'lodash/isString';
|
|
15
|
-
import { useVisitor, useStory } from '@micromag/core/contexts';
|
|
16
16
|
|
|
17
17
|
var Base = /*#__PURE__*/function () {
|
|
18
18
|
function Base() {
|
|
@@ -292,6 +292,10 @@ ApiProvider.defaultProps = defaultProps$1;
|
|
|
292
292
|
var useContributionCreate = function useContributionCreate() {
|
|
293
293
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
294
294
|
screenId = _ref.screenId,
|
|
295
|
+
_ref$visitorId = _ref.visitorId,
|
|
296
|
+
providedVisitorId = _ref$visitorId === void 0 ? null : _ref$visitorId,
|
|
297
|
+
_ref$storyId = _ref.storyId,
|
|
298
|
+
providedStoryId = _ref$storyId === void 0 ? null : _ref$storyId,
|
|
295
299
|
_ref$onSuccess = _ref.onSuccess,
|
|
296
300
|
onSuccess = _ref$onSuccess === void 0 ? null : _ref$onSuccess;
|
|
297
301
|
var api = useApi();
|
|
@@ -299,13 +303,20 @@ var useContributionCreate = function useContributionCreate() {
|
|
|
299
303
|
_useState2 = _slicedToArray(_useState, 2),
|
|
300
304
|
creating = _useState2[0],
|
|
301
305
|
setCreating = _useState2[1];
|
|
306
|
+
var _ref2 = useVisitor() || {},
|
|
307
|
+
visitorId = _ref2.id;
|
|
308
|
+
var _ref3 = useStory() || {},
|
|
309
|
+
storyId = _ref3.id,
|
|
310
|
+
documentId = _ref3.document_id;
|
|
302
311
|
var create = useCallback(function (data) {
|
|
303
312
|
if (api === null) {
|
|
304
313
|
return null;
|
|
305
314
|
}
|
|
306
315
|
setCreating(true);
|
|
307
316
|
return api.contributions.create(_objectSpread({
|
|
308
|
-
screen_id: screenId
|
|
317
|
+
screen_id: screenId,
|
|
318
|
+
visitor_id: providedVisitorId || visitorId,
|
|
319
|
+
story_id: documentId || providedStoryId || storyId
|
|
309
320
|
}, data)).then(function (response) {
|
|
310
321
|
setCreating(false);
|
|
311
322
|
if (onSuccess !== null) {
|
|
@@ -313,7 +324,7 @@ var useContributionCreate = function useContributionCreate() {
|
|
|
313
324
|
}
|
|
314
325
|
return response;
|
|
315
326
|
});
|
|
316
|
-
}, [api, setCreating, onSuccess, screenId]);
|
|
327
|
+
}, [api, setCreating, onSuccess, screenId, visitorId, storyId, providedVisitorId, providedStoryId]);
|
|
317
328
|
return {
|
|
318
329
|
create: create,
|
|
319
330
|
creating: creating
|
|
@@ -1012,7 +1023,8 @@ var useQuizCreate = function useQuizCreate() {
|
|
|
1012
1023
|
var _ref2 = useVisitor() || {},
|
|
1013
1024
|
visitorId = _ref2.id;
|
|
1014
1025
|
var _ref3 = useStory() || {},
|
|
1015
|
-
storyId = _ref3.id
|
|
1026
|
+
storyId = _ref3.id,
|
|
1027
|
+
documentId = _ref3.document_id;
|
|
1016
1028
|
var create = useCallback(function (data) {
|
|
1017
1029
|
if (api === null) {
|
|
1018
1030
|
return null;
|
|
@@ -1021,7 +1033,7 @@ var useQuizCreate = function useQuizCreate() {
|
|
|
1021
1033
|
return api.quiz.create(_objectSpread({
|
|
1022
1034
|
screen_id: screenId,
|
|
1023
1035
|
visitor_id: providedVisitorId || visitorId,
|
|
1024
|
-
story_id: providedStoryId || storyId
|
|
1036
|
+
story_id: documentId || providedStoryId || storyId
|
|
1025
1037
|
}, data)).then(function (response) {
|
|
1026
1038
|
setCreating(false);
|
|
1027
1039
|
if (onSuccess !== null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/data",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.698",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@babel/runtime": "^7.13.10",
|
|
60
60
|
"@folklore/fetch": "^0.1.17",
|
|
61
61
|
"@folklore/routes": "^0.2.36",
|
|
62
|
-
"@micromag/core": "^0.3.
|
|
62
|
+
"@micromag/core": "^0.3.679",
|
|
63
63
|
"lodash": "^4.17.21",
|
|
64
64
|
"prop-types": "^15.7.2",
|
|
65
65
|
"query-string": "^9.0.0"
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"access": "public",
|
|
69
69
|
"registry": "https://registry.npmjs.org/"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "902961f5ef5773bee063b6e6405ea37eac10fa7d"
|
|
72
72
|
}
|