@bigbinary/neeto-commons-frontend 3.6.0 → 4.0.1
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/cjs/configs/constants.js +4 -4
- package/cjs/react-utils/useFetchNeetoApps/useFetchNeetoApps.js +1 -1
- package/cjs/react-utils/useFetchNeetoApps/useFetchNeetoApps.js.map +1 -1
- package/cjs/react-utils/useMutationWithInvalidation/useMutationWithInvalidation.js +16 -4
- package/cjs/react-utils/useMutationWithInvalidation/useMutationWithInvalidation.js.map +1 -1
- package/cjs/react-utils/usePersistedQuery/usePersistedQuery.js +5 -2
- package/cjs/react-utils/usePersistedQuery/usePersistedQuery.js.map +1 -1
- package/configs/constants.js +4 -4
- package/package.json +2 -2
- package/react-utils/useFetchNeetoApps/useFetchNeetoApps.js +1 -1
- package/react-utils/useFetchNeetoApps/useFetchNeetoApps.js.map +1 -1
- package/react-utils/useMutationWithInvalidation/useMutationWithInvalidation.js +16 -4
- package/react-utils/useMutationWithInvalidation/useMutationWithInvalidation.js.map +1 -1
- package/react-utils/usePersistedQuery/usePersistedQuery.js +5 -2
- package/react-utils/usePersistedQuery/usePersistedQuery.js.map +1 -1
- package/react-utils.d.ts +17 -7
package/cjs/configs/constants.js
CHANGED
|
@@ -97,12 +97,12 @@ const TRANSFORM_RULES = [
|
|
|
97
97
|
transform: "neetoicons/app-icons/${member}",
|
|
98
98
|
preventFullImport: false,
|
|
99
99
|
},
|
|
100
|
-
"@bigbinary/neeto-icons/
|
|
101
|
-
transform: "@bigbinary/neeto-icons/
|
|
100
|
+
"@bigbinary/neeto-icons/logos": {
|
|
101
|
+
transform: "@bigbinary/neeto-icons/logos/${member}",
|
|
102
102
|
preventFullImport: false,
|
|
103
103
|
},
|
|
104
|
-
"neetoicons/
|
|
105
|
-
transform: "neetoicons/
|
|
104
|
+
"neetoicons/logos": {
|
|
105
|
+
transform: "neetoicons/logos/${member}",
|
|
106
106
|
preventFullImport: false,
|
|
107
107
|
},
|
|
108
108
|
"@bigbinary/neeto-icons/misc": {
|
|
@@ -15,7 +15,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
15
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
16
|
var useFetchNeetoApps = function useFetchNeetoApps(options) {
|
|
17
17
|
var _globalProps$user;
|
|
18
|
-
var scopedQueryKey = "".concat(_query.QUERY_KEYS.NEETO_APPS_LIST, "-").concat((_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id);
|
|
18
|
+
var scopedQueryKey = ["".concat(_query.QUERY_KEYS.NEETO_APPS_LIST, "-").concat((_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id)];
|
|
19
19
|
var neetoApps = _usePersistedQuery["default"].getCache(scopedQueryKey);
|
|
20
20
|
return (0, _usePersistedQuery["default"])(scopedQueryKey, _neeto_apps["default"].fetch, _objectSpread({
|
|
21
21
|
staleTime: _constants.NEETO_APPS_LIST_STALE_TIME,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchNeetoApps.js","names":["_neetoCist","require","_usePersistedQuery","_interopRequireDefault","_neeto_apps","_constants","_query","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useFetchNeetoApps","options","_globalProps$user","scopedQueryKey","concat","QUERY_KEYS","NEETO_APPS_LIST","globalProps","user","id","neetoApps","usePersistedQuery","getCache","neetoAppsApi","fetch","staleTime","NEETO_APPS_LIST_STALE_TIME","enabled","isNotPresent","data","_default","exports"],"sources":["../../../../src/react-utils/useFetchNeetoApps/useFetchNeetoApps.js"],"sourcesContent":["import { isNotPresent } from \"neetocist\";\nimport usePersistedQuery from \"react-utils/usePersistedQuery\";\n\nimport neetoAppsApi from \"./apis/neeto_apps\";\n\nimport { NEETO_APPS_LIST_STALE_TIME } from \"../constants\";\nimport { QUERY_KEYS } from \"../constants/query\";\n\nconst useFetchNeetoApps = options => {\n const scopedQueryKey = `${QUERY_KEYS.NEETO_APPS_LIST}-${globalProps.user?.id}
|
|
1
|
+
{"version":3,"file":"useFetchNeetoApps.js","names":["_neetoCist","require","_usePersistedQuery","_interopRequireDefault","_neeto_apps","_constants","_query","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useFetchNeetoApps","options","_globalProps$user","scopedQueryKey","concat","QUERY_KEYS","NEETO_APPS_LIST","globalProps","user","id","neetoApps","usePersistedQuery","getCache","neetoAppsApi","fetch","staleTime","NEETO_APPS_LIST_STALE_TIME","enabled","isNotPresent","data","_default","exports"],"sources":["../../../../src/react-utils/useFetchNeetoApps/useFetchNeetoApps.js"],"sourcesContent":["import { isNotPresent } from \"neetocist\";\nimport usePersistedQuery from \"react-utils/usePersistedQuery\";\n\nimport neetoAppsApi from \"./apis/neeto_apps\";\n\nimport { NEETO_APPS_LIST_STALE_TIME } from \"../constants\";\nimport { QUERY_KEYS } from \"../constants/query\";\n\nconst useFetchNeetoApps = options => {\n const scopedQueryKey = [\n `${QUERY_KEYS.NEETO_APPS_LIST}-${globalProps.user?.id}`,\n ];\n\n const neetoApps = usePersistedQuery.getCache(scopedQueryKey);\n\n return usePersistedQuery(scopedQueryKey, neetoAppsApi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,MAAA,EAAAM,GAAA,EAAAhB,MAAA,CAAAK,wBAAA,CAAAS,MAAA,EAAAE,GAAA,iBAAAN,MAAA;AAEhD,IAAMW,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAGC,OAAO,EAAI;EAAA,IAAAC,iBAAA;EACnC,IAAMC,cAAc,GAAG,IAAAC,MAAA,CAClBC,iBAAU,CAACC,eAAe,OAAAF,MAAA,EAAAF,iBAAA,GAAIK,WAAW,CAACC,IAAI,cAAAN,iBAAA,uBAAhBA,iBAAA,CAAkBO,EAAE,EACtD;EAED,IAAMC,SAAS,GAAGC,6BAAiB,CAACC,QAAQ,CAACT,cAAc,CAAC;EAE5D,OAAO,IAAAQ,6BAAiB,EAACR,cAAc,EAAEU,sBAAY,CAACC,KAAK,EAAA1B,aAAA;IACzD2B,SAAS,EAAEC,qCAA0B;IACrCC,OAAO,EAAE,IAAAC,uBAAY,EAACR,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAES,IAAI;EAAC,GACnClB,OAAO,EACV;AACJ,CAAC;AAAC,IAAAmB,QAAA,GAEapB,iBAAiB;AAAAqB,OAAA,cAAAD,QAAA"}
|
|
@@ -7,7 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
-
var _reactQuery = require("react-query");
|
|
10
|
+
var _reactQuery = require("@tanstack/react-query");
|
|
11
|
+
var _ramda = require("ramda");
|
|
11
12
|
var _excluded = ["keysToInvalidate"],
|
|
12
13
|
_excluded2 = ["onSuccess"];
|
|
13
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -18,11 +19,22 @@ var useMutationWithInvalidation = function useMutationWithInvalidation(mutationF
|
|
|
18
19
|
var queryClient = (0, _reactQuery.useQueryClient)();
|
|
19
20
|
var _onSuccess = options.onSuccess,
|
|
20
21
|
otherOptions = (0, _objectWithoutProperties2["default"])(options, _excluded2);
|
|
21
|
-
return (0, _reactQuery.useMutation)(
|
|
22
|
+
return (0, _reactQuery.useMutation)(_objectSpread({
|
|
23
|
+
mutationFn: mutationFn,
|
|
22
24
|
onSuccess: function onSuccess(data, variables, context) {
|
|
23
25
|
keysToInvalidate.forEach(function (key) {
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
+
var result = (0, _ramda.type)(key) === "Function" ? key(data, variables, context) : key;
|
|
27
|
+
if ((0, _ramda.type)(result) === "Object") {
|
|
28
|
+
queryClient.invalidateQueries(result);
|
|
29
|
+
} else if ((0, _ramda.type)(result) === "String") {
|
|
30
|
+
queryClient.invalidateQueries({
|
|
31
|
+
queryKey: [result]
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
queryClient.invalidateQueries({
|
|
35
|
+
queryKey: result
|
|
36
|
+
});
|
|
37
|
+
}
|
|
26
38
|
});
|
|
27
39
|
_onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(data, variables, context);
|
|
28
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationWithInvalidation.js","names":["_reactQuery","require","_excluded","_excluded2","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useMutationWithInvalidation","mutationFn","_ref","keysToInvalidate","options","_objectWithoutProperties2","queryClient","useQueryClient","onSuccess","otherOptions","useMutation","data","variables","context","
|
|
1
|
+
{"version":3,"file":"useMutationWithInvalidation.js","names":["_reactQuery","require","_ramda","_excluded","_excluded2","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","useMutationWithInvalidation","mutationFn","_ref","keysToInvalidate","options","_objectWithoutProperties2","queryClient","useQueryClient","onSuccess","otherOptions","useMutation","data","variables","context","result","type","invalidateQueries","queryKey","_default","exports"],"sources":["../../../../src/react-utils/useMutationWithInvalidation/useMutationWithInvalidation.js"],"sourcesContent":["import { useQueryClient, useMutation } from \"@tanstack/react-query\";\nimport { type } from \"ramda\";\n\nconst useMutationWithInvalidation = (\n mutationFn,\n { keysToInvalidate, ...options }\n) => {\n const queryClient = useQueryClient();\n const { onSuccess, ...otherOptions } = options;\n\n return useMutation({\n mutationFn,\n onSuccess: (data, variables, context) => {\n keysToInvalidate.forEach(key => {\n const result =\n type(key) === \"Function\" ? key(data, variables, context) : key;\n\n if (type(result) === \"Object\") {\n queryClient.invalidateQueries(result);\n } else if (type(result) === \"String\") {\n queryClient.invalidateQueries({ queryKey: [result] });\n } else {\n queryClient.invalidateQueries({ queryKey: result });\n }\n });\n\n onSuccess?.(data, variables, context);\n },\n\n ...otherOptions,\n });\n};\n\nexport default useMutationWithInvalidation;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAA6B,IAAAE,SAAA;EAAAC,UAAA;AAAA,SAAAC,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CA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T,OAAO,CAAC,UAAAC,GAAG,EAAI;QAC9B,IAAMmB,MAAM,GACV,IAAAC,WAAI,EAACpB,GAAG,CAAC,KAAK,UAAU,GAAGA,GAAG,CAACgB,IAAI,EAAEC,SAAS,EAAEC,OAAO,CAAC,GAAGlB,GAAG;QAEhE,IAAI,IAAAoB,WAAI,EAACD,MAAM,CAAC,KAAK,QAAQ,EAAE;UAC7BR,WAAW,CAACU,iBAAiB,CAACF,MAAM,CAAC;QACvC,CAAC,MAAM,IAAI,IAAAC,WAAI,EAACD,MAAM,CAAC,KAAK,QAAQ,EAAE;UACpCR,WAAW,CAACU,iBAAiB,CAAC;YAAEC,QAAQ,EAAE,CAACH,MAAM;UAAE,CAAC,CAAC;QACvD,CAAC,MAAM;UACLR,WAAW,CAACU,iBAAiB,CAAC;YAAEC,QAAQ,EAAEH;UAAO,CAAC,CAAC;QACrD;MACF,CAAC,CAAC;MAEFN,UAAS,aAATA,UAAS,uBAATA,UAAS,CAAGG,IAAI,EAAEC,SAAS,EAAEC,OAAO,CAAC;IACvC;EAAC,GAEEJ,YAAY,EACf;AACJ,CAAC;AAAC,IAAAS,QAAA,GAEalB,2BAA2B;AAAAmB,OAAA,cAAAD,QAAA"}
|
|
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = require("react");
|
|
10
|
+
var _reactQuery = require("@tanstack/react-query");
|
|
10
11
|
var _ramda = require("ramda");
|
|
11
|
-
var _reactQuery = require("react-query");
|
|
12
12
|
var _constants = require("../constants");
|
|
13
13
|
var _general = require("../../utils/general");
|
|
14
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -37,7 +37,10 @@ var isOutdated = function isOutdated(localCache, staleTime) {
|
|
|
37
37
|
return localCache.modifiedAt <= Date.now() - staleTime;
|
|
38
38
|
};
|
|
39
39
|
var usePersistedQuery = function usePersistedQuery(queryKey, fetch, options) {
|
|
40
|
-
var queryResult = (0, _reactQuery.useQuery)(
|
|
40
|
+
var queryResult = (0, _reactQuery.useQuery)(_objectSpread({
|
|
41
|
+
queryKey: queryKey,
|
|
42
|
+
queryFn: fetch
|
|
43
|
+
}, options));
|
|
41
44
|
var localCache = localStorageQueryCache.get(queryKey);
|
|
42
45
|
(0, _react.useEffect)(function () {
|
|
43
46
|
if (!queryResult.isSuccess) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersistedQuery.js","names":["_react","require","
|
|
1
|
+
{"version":3,"file":"usePersistedQuery.js","names":["_react","require","_reactQuery","_ramda","_constants","_general","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","localStorageQueryCache","set","data","cache","getAll","newCache","modifiedAt","Date","now","setToLocalStorage","QUERY_CACHE_NAME_SPACE","getFromLocalStorage","get","isOutdated","localCache","staleTime","isNil","usePersistedQuery","queryKey","fetch","options","queryResult","useQuery","queryFn","useEffect","isSuccess","isFreshLoading","isLoading","getCache","_default","exports"],"sources":["../../../../src/react-utils/usePersistedQuery/usePersistedQuery.js"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { isNil } from \"ramda\";\nimport { QUERY_CACHE_NAME_SPACE } from \"react-utils/constants\";\nimport { getFromLocalStorage, setToLocalStorage } from \"utils/general\";\n\nconst localStorageQueryCache = {\n set: (key, data) => {\n const cache = localStorageQueryCache.getAll();\n const newCache = { ...cache, [key]: { data, modifiedAt: Date.now() } };\n setToLocalStorage(QUERY_CACHE_NAME_SPACE, newCache);\n },\n getAll: () => {\n const cache = getFromLocalStorage(QUERY_CACHE_NAME_SPACE);\n if (!cache) return {};\n\n return cache;\n },\n get: key => localStorageQueryCache.getAll()[key],\n};\n\nconst isOutdated = (localCache, staleTime) => {\n if (isNil(localCache)) return true;\n\n if (isNil(staleTime)) return false;\n\n return localCache.modifiedAt <= Date.now() - staleTime;\n};\n\nconst usePersistedQuery = (queryKey, fetch, options) => {\n const queryResult = useQuery({\n queryKey,\n queryFn: fetch,\n ...options,\n });\n const localCache = localStorageQueryCache.get(queryKey);\n\n useEffect(() => {\n if (!queryResult.isSuccess) return;\n localStorageQueryCache.set(queryKey, queryResult.data);\n }, [queryKey, queryResult.data, queryResult.isSuccess]);\n\n if (isOutdated(localCache, options?.staleTime)) {\n return { ...queryResult, isFreshLoading: queryResult.isLoading };\n }\n\n return {\n ...queryResult,\n data: queryResult.data || localCache.data,\n isFreshLoading: false,\n };\n};\n\nusePersistedQuery.getCache = localStorageQueryCache.get;\n\nexport default usePersistedQuery;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAAuE,SAAAK,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA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AEzB,CAAC;AAEDT,iBAAiB,CAACW,QAAQ,GAAG5B,sBAAsB,CAACY,GAAG;AAAC,IAAAiB,QAAA,GAEzCZ,iBAAiB;AAAAa,OAAA,cAAAD,QAAA"}
|
package/configs/constants.js
CHANGED
|
@@ -97,12 +97,12 @@ const TRANSFORM_RULES = [
|
|
|
97
97
|
transform: "neetoicons/app-icons/${member}",
|
|
98
98
|
preventFullImport: false,
|
|
99
99
|
},
|
|
100
|
-
"@bigbinary/neeto-icons/
|
|
101
|
-
transform: "@bigbinary/neeto-icons/
|
|
100
|
+
"@bigbinary/neeto-icons/logos": {
|
|
101
|
+
transform: "@bigbinary/neeto-icons/logos/${member}",
|
|
102
102
|
preventFullImport: false,
|
|
103
103
|
},
|
|
104
|
-
"neetoicons/
|
|
105
|
-
transform: "neetoicons/
|
|
104
|
+
"neetoicons/logos": {
|
|
105
|
+
transform: "neetoicons/logos/${member}",
|
|
106
106
|
preventFullImport: false,
|
|
107
107
|
},
|
|
108
108
|
"@bigbinary/neeto-icons/misc": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
|
|
6
6
|
"author": "Amaljith K <amaljith.k@bigbinary.com>",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"@faker-js/faker": "^8.2.0",
|
|
82
82
|
"@honeybadger-io/js": "^6.4.1",
|
|
83
83
|
"@honeybadger-io/react": "^6.1.3",
|
|
84
|
+
"@tanstack/react-query": "5.40.0",
|
|
84
85
|
"antd": "4.18.7",
|
|
85
86
|
"autoprefixer": "^10.4.13",
|
|
86
87
|
"axios": "1.6.2",
|
|
@@ -95,7 +96,6 @@
|
|
|
95
96
|
"react": "18.2.0",
|
|
96
97
|
"react-helmet": "^6.1.0",
|
|
97
98
|
"react-i18next": "^12.3.1",
|
|
98
|
-
"react-query": "^3.39.2",
|
|
99
99
|
"react-router-dom": "5.3.3",
|
|
100
100
|
"react-toastify": "8.0.2",
|
|
101
101
|
"shakapacker": "^6.5.5",
|
|
@@ -8,7 +8,7 @@ import { NEETO_APPS_LIST_STALE_TIME } from "../constants";
|
|
|
8
8
|
import { QUERY_KEYS } from "../constants/query";
|
|
9
9
|
var useFetchNeetoApps = function useFetchNeetoApps(options) {
|
|
10
10
|
var _globalProps$user;
|
|
11
|
-
var scopedQueryKey = "".concat(QUERY_KEYS.NEETO_APPS_LIST, "-").concat((_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id);
|
|
11
|
+
var scopedQueryKey = ["".concat(QUERY_KEYS.NEETO_APPS_LIST, "-").concat((_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id)];
|
|
12
12
|
var neetoApps = usePersistedQuery.getCache(scopedQueryKey);
|
|
13
13
|
return usePersistedQuery(scopedQueryKey, neetoAppsApi.fetch, _objectSpread({
|
|
14
14
|
staleTime: NEETO_APPS_LIST_STALE_TIME,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchNeetoApps.js","names":["isNotPresent","usePersistedQuery","neetoAppsApi","NEETO_APPS_LIST_STALE_TIME","QUERY_KEYS","useFetchNeetoApps","options","_globalProps$user","scopedQueryKey","concat","NEETO_APPS_LIST","globalProps","user","id","neetoApps","getCache","fetch","_objectSpread","staleTime","enabled","data"],"sources":["../../../src/react-utils/useFetchNeetoApps/useFetchNeetoApps.js"],"sourcesContent":["import { isNotPresent } from \"neetocist\";\nimport usePersistedQuery from \"react-utils/usePersistedQuery\";\n\nimport neetoAppsApi from \"./apis/neeto_apps\";\n\nimport { NEETO_APPS_LIST_STALE_TIME } from \"../constants\";\nimport { QUERY_KEYS } from \"../constants/query\";\n\nconst useFetchNeetoApps = options => {\n const scopedQueryKey = `${QUERY_KEYS.NEETO_APPS_LIST}-${globalProps.user?.id}
|
|
1
|
+
{"version":3,"file":"useFetchNeetoApps.js","names":["isNotPresent","usePersistedQuery","neetoAppsApi","NEETO_APPS_LIST_STALE_TIME","QUERY_KEYS","useFetchNeetoApps","options","_globalProps$user","scopedQueryKey","concat","NEETO_APPS_LIST","globalProps","user","id","neetoApps","getCache","fetch","_objectSpread","staleTime","enabled","data"],"sources":["../../../src/react-utils/useFetchNeetoApps/useFetchNeetoApps.js"],"sourcesContent":["import { isNotPresent } from \"neetocist\";\nimport usePersistedQuery from \"react-utils/usePersistedQuery\";\n\nimport neetoAppsApi from \"./apis/neeto_apps\";\n\nimport { NEETO_APPS_LIST_STALE_TIME } from \"../constants\";\nimport { QUERY_KEYS } from \"../constants/query\";\n\nconst useFetchNeetoApps = options => {\n const scopedQueryKey = [\n `${QUERY_KEYS.NEETO_APPS_LIST}-${globalProps.user?.id}`,\n ];\n\n const neetoApps = usePersistedQuery.getCache(scopedQueryKey);\n\n return usePersistedQuery(scopedQueryKey, neetoAppsApi.fetch, {\n staleTime: NEETO_APPS_LIST_STALE_TIME,\n enabled: isNotPresent(neetoApps?.data),\n ...options,\n });\n};\n\nexport default useFetchNeetoApps;\n"],"mappings":";;;AAAA,SAASA,YAAY;AACrB,OAAOC,iBAAiB;AAExB,OAAOC,YAAY;AAEnB,SAASC,0BAA0B;AACnC,SAASC,UAAU;AAEnB,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAGC,OAAO,EAAI;EAAA,IAAAC,iBAAA;EACnC,IAAMC,cAAc,GAAG,IAAAC,MAAA,CAClBL,UAAU,CAACM,eAAe,OAAAD,MAAA,EAAAF,iBAAA,GAAII,WAAW,CAACC,IAAI,cAAAL,iBAAA,uBAAhBA,iBAAA,CAAkBM,EAAE,EACtD;EAED,IAAMC,SAAS,GAAGb,iBAAiB,CAACc,QAAQ,CAACP,cAAc,CAAC;EAE5D,OAAOP,iBAAiB,CAACO,cAAc,EAAEN,YAAY,CAACc,KAAK,EAAAC,aAAA;IACzDC,SAAS,EAAEf,0BAA0B;IACrCgB,OAAO,EAAEnB,YAAY,CAACc,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAEM,IAAI;EAAC,GACnCd,OAAO,EACV;AACJ,CAAC;AAED,eAAeD,iBAAiB"}
|
|
@@ -4,18 +4,30 @@ var _excluded = ["keysToInvalidate"],
|
|
|
4
4
|
_excluded2 = ["onSuccess"];
|
|
5
5
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
6
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
-
import { useQueryClient, useMutation } from "react-query";
|
|
7
|
+
import { useQueryClient, useMutation } from "@tanstack/react-query";
|
|
8
|
+
import { type } from "ramda";
|
|
8
9
|
var useMutationWithInvalidation = function useMutationWithInvalidation(mutationFn, _ref) {
|
|
9
10
|
var keysToInvalidate = _ref.keysToInvalidate,
|
|
10
11
|
options = _objectWithoutProperties(_ref, _excluded);
|
|
11
12
|
var queryClient = useQueryClient();
|
|
12
13
|
var _onSuccess = options.onSuccess,
|
|
13
14
|
otherOptions = _objectWithoutProperties(options, _excluded2);
|
|
14
|
-
return useMutation(
|
|
15
|
+
return useMutation(_objectSpread({
|
|
16
|
+
mutationFn: mutationFn,
|
|
15
17
|
onSuccess: function onSuccess(data, variables, context) {
|
|
16
18
|
keysToInvalidate.forEach(function (key) {
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
+
var result = type(key) === "Function" ? key(data, variables, context) : key;
|
|
20
|
+
if (type(result) === "Object") {
|
|
21
|
+
queryClient.invalidateQueries(result);
|
|
22
|
+
} else if (type(result) === "String") {
|
|
23
|
+
queryClient.invalidateQueries({
|
|
24
|
+
queryKey: [result]
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
queryClient.invalidateQueries({
|
|
28
|
+
queryKey: result
|
|
29
|
+
});
|
|
30
|
+
}
|
|
19
31
|
});
|
|
20
32
|
_onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(data, variables, context);
|
|
21
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationWithInvalidation.js","names":["useQueryClient","useMutation","useMutationWithInvalidation","mutationFn","_ref","keysToInvalidate","options","_objectWithoutProperties","_excluded","queryClient","onSuccess","otherOptions","_excluded2","_objectSpread","data","variables","context","forEach","key","
|
|
1
|
+
{"version":3,"file":"useMutationWithInvalidation.js","names":["useQueryClient","useMutation","type","useMutationWithInvalidation","mutationFn","_ref","keysToInvalidate","options","_objectWithoutProperties","_excluded","queryClient","onSuccess","otherOptions","_excluded2","_objectSpread","data","variables","context","forEach","key","result","invalidateQueries","queryKey"],"sources":["../../../src/react-utils/useMutationWithInvalidation/useMutationWithInvalidation.js"],"sourcesContent":["import { useQueryClient, useMutation } from \"@tanstack/react-query\";\nimport { type } from \"ramda\";\n\nconst useMutationWithInvalidation = (\n mutationFn,\n { keysToInvalidate, ...options }\n) => {\n const queryClient = useQueryClient();\n const { onSuccess, ...otherOptions } = options;\n\n return useMutation({\n mutationFn,\n onSuccess: (data, variables, context) => {\n keysToInvalidate.forEach(key => {\n const result =\n type(key) === \"Function\" ? key(data, variables, context) : key;\n\n if (type(result) === \"Object\") {\n queryClient.invalidateQueries(result);\n } else if (type(result) === \"String\") {\n queryClient.invalidateQueries({ queryKey: [result] });\n } else {\n queryClient.invalidateQueries({ queryKey: result });\n }\n });\n\n onSuccess?.(data, variables, context);\n },\n\n ...otherOptions,\n });\n};\n\nexport default useMutationWithInvalidation;\n"],"mappings":";;;;;;AAAA,SAASA,cAAc,EAAEC,WAAW,QAAQ,uBAAuB;AACnE,SAASC,IAAI,QAAQ,OAAO;AAE5B,IAAMC,2BAA2B,GAAG,SAA9BA,2BAA2BA,CAC/BC,UAAU,EAAAC,IAAA,EAEP;EAAA,IADDC,gBAAgB,GAAAD,IAAA,CAAhBC,gBAAgB;IAAKC,OAAO,GAAAC,wBAAA,CAAAH,IAAA,EAAAI,SAAA;EAE9B,IAAMC,WAAW,GAAGV,cAAc,EAAE;EACpC,IAAQW,UAAS,GAAsBJ,OAAO,CAAtCI,SAAS;IAAKC,YAAY,GAAAJ,wBAAA,CAAKD,OAAO,EAAAM,UAAA;EAE9C,OAAOZ,WAAW,CAAAa,aAAA;IAChBV,UAAU,EAAVA,UAAU;IACVO,SAAS,EAAE,SAAAA,UAACI,IAAI,EAAEC,SAAS,EAAEC,OAAO,EAAK;MACvCX,gBAAgB,CAACY,OAAO,CAAC,UAAAC,GAAG,EAAI;QAC9B,IAAMC,MAAM,GACVlB,IAAI,CAACiB,GAAG,CAAC,KAAK,UAAU,GAAGA,GAAG,CAACJ,IAAI,EAAEC,SAAS,EAAEC,OAAO,CAAC,GAAGE,GAAG;QAEhE,IAAIjB,IAAI,CAACkB,MAAM,CAAC,KAAK,QAAQ,EAAE;UAC7BV,WAAW,CAACW,iBAAiB,CAACD,MAAM,CAAC;QACvC,CAAC,MAAM,IAAIlB,IAAI,CAACkB,MAAM,CAAC,KAAK,QAAQ,EAAE;UACpCV,WAAW,CAACW,iBAAiB,CAAC;YAAEC,QAAQ,EAAE,CAACF,MAAM;UAAE,CAAC,CAAC;QACvD,CAAC,MAAM;UACLV,WAAW,CAACW,iBAAiB,CAAC;YAAEC,QAAQ,EAAEF;UAAO,CAAC,CAAC;QACrD;MACF,CAAC,CAAC;MAEFT,UAAS,aAATA,UAAS,uBAATA,UAAS,CAAGI,IAAI,EAAEC,SAAS,EAAEC,OAAO,CAAC;IACvC;EAAC,GAEEL,YAAY,EACf;AACJ,CAAC;AAED,eAAeT,2BAA2B"}
|
|
@@ -2,8 +2,8 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
import { useEffect } from "react";
|
|
5
|
+
import { useQuery } from "@tanstack/react-query";
|
|
5
6
|
import { isNil } from "ramda";
|
|
6
|
-
import { useQuery } from "react-query";
|
|
7
7
|
import { QUERY_CACHE_NAME_SPACE } from "../constants";
|
|
8
8
|
import { getFromLocalStorage, setToLocalStorage } from "../../utils/general";
|
|
9
9
|
var localStorageQueryCache = {
|
|
@@ -30,7 +30,10 @@ var isOutdated = function isOutdated(localCache, staleTime) {
|
|
|
30
30
|
return localCache.modifiedAt <= Date.now() - staleTime;
|
|
31
31
|
};
|
|
32
32
|
var usePersistedQuery = function usePersistedQuery(queryKey, fetch, options) {
|
|
33
|
-
var queryResult = useQuery(
|
|
33
|
+
var queryResult = useQuery(_objectSpread({
|
|
34
|
+
queryKey: queryKey,
|
|
35
|
+
queryFn: fetch
|
|
36
|
+
}, options));
|
|
34
37
|
var localCache = localStorageQueryCache.get(queryKey);
|
|
35
38
|
useEffect(function () {
|
|
36
39
|
if (!queryResult.isSuccess) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersistedQuery.js","names":["useEffect","
|
|
1
|
+
{"version":3,"file":"usePersistedQuery.js","names":["useEffect","useQuery","isNil","QUERY_CACHE_NAME_SPACE","getFromLocalStorage","setToLocalStorage","localStorageQueryCache","set","key","data","cache","getAll","newCache","_objectSpread","_defineProperty","modifiedAt","Date","now","get","isOutdated","localCache","staleTime","usePersistedQuery","queryKey","fetch","options","queryResult","queryFn","isSuccess","isFreshLoading","isLoading","getCache"],"sources":["../../../src/react-utils/usePersistedQuery/usePersistedQuery.js"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { isNil } from \"ramda\";\nimport { QUERY_CACHE_NAME_SPACE } from \"react-utils/constants\";\nimport { getFromLocalStorage, setToLocalStorage } from \"utils/general\";\n\nconst localStorageQueryCache = {\n set: (key, data) => {\n const cache = localStorageQueryCache.getAll();\n const newCache = { ...cache, [key]: { data, modifiedAt: Date.now() } };\n setToLocalStorage(QUERY_CACHE_NAME_SPACE, newCache);\n },\n getAll: () => {\n const cache = getFromLocalStorage(QUERY_CACHE_NAME_SPACE);\n if (!cache) return {};\n\n return cache;\n },\n get: key => localStorageQueryCache.getAll()[key],\n};\n\nconst isOutdated = (localCache, staleTime) => {\n if (isNil(localCache)) return true;\n\n if (isNil(staleTime)) return false;\n\n return localCache.modifiedAt <= Date.now() - staleTime;\n};\n\nconst usePersistedQuery = (queryKey, fetch, options) => {\n const queryResult = useQuery({\n queryKey,\n queryFn: fetch,\n ...options,\n });\n const localCache = localStorageQueryCache.get(queryKey);\n\n useEffect(() => {\n if (!queryResult.isSuccess) return;\n localStorageQueryCache.set(queryKey, queryResult.data);\n }, [queryKey, queryResult.data, queryResult.isSuccess]);\n\n if (isOutdated(localCache, options?.staleTime)) {\n return { ...queryResult, isFreshLoading: queryResult.isLoading };\n }\n\n return {\n ...queryResult,\n data: queryResult.data || localCache.data,\n isFreshLoading: false,\n };\n};\n\nusePersistedQuery.getCache = localStorageQueryCache.get;\n\nexport default usePersistedQuery;\n"],"mappings":";;;AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,KAAK,QAAQ,OAAO;AAC7B,SAASC,sBAAsB;AAC/B,SAASC,mBAAmB,EAAEC,iBAAiB;AAE/C,IAAMC,sBAAsB,GAAG;EAC7BC,GAAG,EAAE,SAAAA,IAACC,GAAG,EAAEC,IAAI,EAAK;IAClB,IAAMC,KAAK,GAAGJ,sBAAsB,CAACK,MAAM,EAAE;IAC7C,IAAMC,QAAQ,GAAAC,aAAA,CAAAA,aAAA,KAAQH,KAAK,OAAAI,eAAA,KAAGN,GAAG,EAAG;MAAEC,IAAI,EAAJA,IAAI;MAAEM,UAAU,EAAEC,IAAI,CAACC,GAAG;IAAG,CAAC,EAAE;IACtEZ,iBAAiB,CAACF,sBAAsB,EAAES,QAAQ,CAAC;EACrD,CAAC;EACDD,MAAM,EAAE,SAAAA,OAAA,EAAM;IACZ,IAAMD,KAAK,GAAGN,mBAAmB,CAACD,sBAAsB,CAAC;IACzD,IAAI,CAACO,KAAK,EAAE,OAAO,CAAC,CAAC;IAErB,OAAOA,KAAK;EACd,CAAC;EACDQ,GAAG,EAAE,SAAAA,IAAAV,GAAG;IAAA,OAAIF,sBAAsB,CAACK,MAAM,EAAE,CAACH,GAAG,CAAC;EAAA;AAClD,CAAC;AAED,IAAMW,UAAU,GAAG,SAAbA,UAAUA,CAAIC,UAAU,EAAEC,SAAS,EAAK;EAC5C,IAAInB,KAAK,CAACkB,UAAU,CAAC,EAAE,OAAO,IAAI;EAElC,IAAIlB,KAAK,CAACmB,SAAS,CAAC,EAAE,OAAO,KAAK;EAElC,OAAOD,UAAU,CAACL,UAAU,IAAIC,IAAI,CAACC,GAAG,EAAE,GAAGI,SAAS;AACxD,CAAC;AAED,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAIC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAK;EACtD,IAAMC,WAAW,GAAGzB,QAAQ,CAAAY,aAAA;IAC1BU,QAAQ,EAARA,QAAQ;IACRI,OAAO,EAAEH;EAAK,GACXC,OAAO,EACV;EACF,IAAML,UAAU,GAAGd,sBAAsB,CAACY,GAAG,CAACK,QAAQ,CAAC;EAEvDvB,SAAS,CAAC,YAAM;IACd,IAAI,CAAC0B,WAAW,CAACE,SAAS,EAAE;IAC5BtB,sBAAsB,CAACC,GAAG,CAACgB,QAAQ,EAAEG,WAAW,CAACjB,IAAI,CAAC;EACxD,CAAC,EAAE,CAACc,QAAQ,EAAEG,WAAW,CAACjB,IAAI,EAAEiB,WAAW,CAACE,SAAS,CAAC,CAAC;EAEvD,IAAIT,UAAU,CAACC,UAAU,EAAEK,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEJ,SAAS,CAAC,EAAE;IAC9C,OAAAR,aAAA,CAAAA,aAAA,KAAYa,WAAW;MAAEG,cAAc,EAAEH,WAAW,CAACI;IAAS;EAChE;EAEA,OAAAjB,aAAA,CAAAA,aAAA,KACKa,WAAW;IACdjB,IAAI,EAAEiB,WAAW,CAACjB,IAAI,IAAIW,UAAU,CAACX,IAAI;IACzCoB,cAAc,EAAE;EAAK;AAEzB,CAAC;AAEDP,iBAAiB,CAACS,QAAQ,GAAGzB,sBAAsB,CAACY,GAAG;AAEvD,eAAeI,iBAAiB"}
|
package/react-utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { RouteProps } from "react-router-dom";
|
|
|
3
3
|
import { Notice } from "@honeybadger-io/js/dist/server/types/core/types";
|
|
4
4
|
import { History } from "history";
|
|
5
5
|
import { StoreApi, UseBoundStore } from "zustand";
|
|
6
|
-
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult, QueryKey, MutationFunction } from "react-query";
|
|
6
|
+
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult, QueryKey, MutationFunction } from "@tanstack/react-query";
|
|
7
7
|
import { KeyPrefix, Namespace } from "i18next";
|
|
8
8
|
import { DefaultNamespace } from "react-i18next/TransWithoutContext";
|
|
9
9
|
import { qsOptionsType, QueryParamsType } from "./utils";
|
|
@@ -1471,7 +1471,9 @@ type QueryKeyOrFilters = QueryKey | QueryFilters;
|
|
|
1471
1471
|
* useMutation(questionsApi.update, {
|
|
1472
1472
|
* ...options,
|
|
1473
1473
|
* onSuccess: (data, ...args) => {
|
|
1474
|
-
* queryClient.invalidateQueries(
|
|
1474
|
+
* queryClient.invalidateQueries({
|
|
1475
|
+
* queryKey: ["QUESTIONS"]
|
|
1476
|
+
* });
|
|
1475
1477
|
* queryClient.setQueryData(["RESPONSES"], data);
|
|
1476
1478
|
* options?.onSuccess(data, ...args);
|
|
1477
1479
|
* },
|
|
@@ -1491,7 +1493,9 @@ type QueryKeyOrFilters = QueryKey | QueryFilters;
|
|
|
1491
1493
|
* useMutation(questionsApi.update, {
|
|
1492
1494
|
* ...options,
|
|
1493
1495
|
* onSuccess: (...args) => {
|
|
1494
|
-
* queryClient.invalidateQueries(
|
|
1496
|
+
* queryClient.invalidateQueries({
|
|
1497
|
+
* queryKey: ["FORM", "QUESTIONS"],
|
|
1498
|
+
* });
|
|
1495
1499
|
* options?.onSuccess(...args);
|
|
1496
1500
|
* },
|
|
1497
1501
|
* });
|
|
@@ -1510,8 +1514,12 @@ type QueryKeyOrFilters = QueryKey | QueryFilters;
|
|
|
1510
1514
|
* useMutation(questionsApi.update, {
|
|
1511
1515
|
* ...options,
|
|
1512
1516
|
* onSuccess: () => {
|
|
1513
|
-
* queryClient.invalidateQueries(
|
|
1514
|
-
*
|
|
1517
|
+
* queryClient.invalidateQueries({
|
|
1518
|
+
* queryKey: ["FORM"],
|
|
1519
|
+
* });
|
|
1520
|
+
* queryClient.invalidateQueries({
|
|
1521
|
+
* queryKey: ["QUESTIONS"],
|
|
1522
|
+
* });
|
|
1515
1523
|
* options?.onSuccess(...args);
|
|
1516
1524
|
* },
|
|
1517
1525
|
* });
|
|
@@ -1531,13 +1539,15 @@ type QueryKeyOrFilters = QueryKey | QueryFilters;
|
|
|
1531
1539
|
* ...options,
|
|
1532
1540
|
* onSuccess: (...args) => {
|
|
1533
1541
|
* const [_, { id }] = args;
|
|
1534
|
-
* queryClient.invalidateQueries(
|
|
1542
|
+
* queryClient.invalidateQueries({
|
|
1543
|
+
* queryKey: ["QUESTION", id],
|
|
1544
|
+
* });
|
|
1535
1545
|
* options?.onSuccess(...args);
|
|
1536
1546
|
* },
|
|
1537
1547
|
* });
|
|
1538
1548
|
*
|
|
1539
1549
|
* // Update question component
|
|
1540
|
-
* const { mutate: updateQuestions,
|
|
1550
|
+
* const { mutate: updateQuestions, isPending } = useUpdateQuestions({
|
|
1541
1551
|
* onError: e => logger.error(e),
|
|
1542
1552
|
* });
|
|
1543
1553
|
* @endexample
|