@antscorp/antsomi-ui 1.3.5-beta.69 → 1.3.5-beta.70
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.
|
@@ -14,6 +14,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
14
14
|
// Libraries
|
|
15
15
|
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';
|
|
16
16
|
import { omit, isEmpty, flatMapDeep, set, get, isNaN } from 'lodash';
|
|
17
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
17
18
|
// Hooks
|
|
18
19
|
import { useDeepCompareEffect, useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
19
20
|
// Components
|
|
@@ -27,7 +28,6 @@ import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
|
|
|
27
28
|
import { useGetDynamicContentAttr, useGetListPromotionPool, useGetListEventAttr, useGetListPromotionCodeAttr, useGetListBO, useGetListAllEvents, useGetListSourceByEvent, useGetListAttributeBO, useGetCustomFunction, useAddSavedCSFunction, useUpdateCSFunction, } from '@antscorp/antsomi-ui/es/queries';
|
|
28
29
|
import { useGetEventTrackingAttributes } from '@antscorp/antsomi-ui/es/queries/ThirdParty';
|
|
29
30
|
// Queries config
|
|
30
|
-
import { queryClientAntsomiUI } from '@antscorp/antsomi-ui/es/queries/configs';
|
|
31
31
|
import { QUERY_KEYS } from '@antscorp/antsomi-ui/es/constants/queries';
|
|
32
32
|
import { dateExample } from './components/FormatDatetime';
|
|
33
33
|
import DisplayFormat from './components/DisplayFormat';
|
|
@@ -126,6 +126,7 @@ export const AddDynamicContent = props => {
|
|
|
126
126
|
const [attrDFOptions, setAttrDFOptions] = useState([]);
|
|
127
127
|
// Template Custom
|
|
128
128
|
const [templateId, settemplateId] = useState();
|
|
129
|
+
const queryClient = useQueryClient();
|
|
129
130
|
const { data: listBoAttributes = [], isFetching: isFetchingListBoAttr, isError: isErrorBoAttr, } = useGetListAttributeBO({
|
|
130
131
|
url,
|
|
131
132
|
itemTypeIds: itemTypeId ? [itemTypeId] : [],
|
|
@@ -911,7 +912,7 @@ export const AddDynamicContent = props => {
|
|
|
911
912
|
break;
|
|
912
913
|
setItemTypeId(Number(selectedItemTypeId));
|
|
913
914
|
const key = [QUERY_KEYS.GET_EVENT_ATTRIBUTE_BO, [selectedItemTypeId]];
|
|
914
|
-
const listAttBOByItemTypeId = serilizeBOAttr(
|
|
915
|
+
const listAttBOByItemTypeId = serilizeBOAttr(queryClient.getQueryData(key));
|
|
915
916
|
if (listAttBOByItemTypeId.length) {
|
|
916
917
|
form.setFieldsValue({
|
|
917
918
|
[DYNAMIC_CONTENT_SETTING_KEY.ATTRIBUTE]: listAttBOByItemTypeId[0],
|
|
@@ -8,46 +8,46 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
// Libraries
|
|
11
|
-
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
11
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
12
12
|
// Services
|
|
13
13
|
import { getListingTemplateCustomFunction, createSavedCustomFunction, updateSavedCustomFunction, } from '../../services/MediaTemplateDesign/CustomFunction';
|
|
14
14
|
// Constants
|
|
15
15
|
import { QUERY_KEYS } from '../../constants/queries';
|
|
16
|
-
// Query client
|
|
17
|
-
import { queryClientAntsomiUI } from '../configs';
|
|
18
16
|
export const useGetCustomFunction = (apiConfig, infos, queryOptions) => useQuery(Object.assign({ queryKey: [QUERY_KEYS.GET_LIST_CUSTOM], queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
17
|
const data = yield getListingTemplateCustomFunction({ url: apiConfig.url }, infos);
|
|
20
18
|
return data;
|
|
21
19
|
}) }, queryOptions));
|
|
22
|
-
export const useAddSavedCSFunction = () =>
|
|
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
|
-
}
|
|
20
|
+
export const useAddSavedCSFunction = () => {
|
|
21
|
+
const queryClient = useQueryClient();
|
|
22
|
+
return useMutation(createSavedCustomFunction, {
|
|
23
|
+
onMutate: (_payload) => {
|
|
24
|
+
const previousSavedBlock = queryClient.getQueryData([QUERY_KEYS.GET_SAVE_CUSTOM_FUNCTION]);
|
|
25
|
+
return { previousSavedBlock };
|
|
26
|
+
},
|
|
27
|
+
onError: (_error, _payload, context) => {
|
|
28
|
+
queryClient.setQueryData([QUERY_KEYS.GET_SAVE_CUSTOM_FUNCTION], context === null || context === void 0 ? void 0 : context.previousSavedBlock);
|
|
29
|
+
},
|
|
30
|
+
onSettled: () => {
|
|
31
|
+
queryClient.invalidateQueries([QUERY_KEYS.GET_SAVE_CUSTOM_FUNCTION], {
|
|
32
|
+
exact: true,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export const useUpdateCSFunction = () => {
|
|
38
|
+
const queryClient = useQueryClient();
|
|
39
|
+
return useMutation(updateSavedCustomFunction, {
|
|
40
|
+
onMutate: (_payload) => {
|
|
41
|
+
const previousSavedBlock = queryClient.getQueryData([QUERY_KEYS.GET_SAVE_CUSTOM_FUNCTION]);
|
|
42
|
+
return { previousSavedBlock };
|
|
43
|
+
},
|
|
44
|
+
onError: (_error, _payload, context) => {
|
|
45
|
+
queryClient.setQueryData([QUERY_KEYS.GET_SAVE_CUSTOM_FUNCTION], context === null || context === void 0 ? void 0 : context.previousSavedBlock);
|
|
46
|
+
},
|
|
47
|
+
onSettled: () => {
|
|
48
|
+
queryClient.invalidateQueries([QUERY_KEYS.GET_SAVE_CUSTOM_FUNCTION], {
|
|
49
|
+
exact: true,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
};
|