@griddo/ax 12.6.1 → 12.6.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.
- package/config/griddo-config/index.js +0 -1
- package/package.json +4 -3
- package/src/GlobalStore.tsx +35 -91
- package/src/__tests__/hooks/heartbeat.test.tsx +88 -0
- package/src/components/MainWrapper/index.tsx +2 -14
- package/src/containers/ActivityLog/{thunks.ts → actions.tsx} +89 -104
- package/src/containers/ActivityLog/constants.tsx +6 -0
- package/src/containers/ActivityLog/index.tsx +3 -16
- package/src/containers/ActivityLog/interfaces.tsx +12 -0
- package/src/containers/ActivityLog/reducer.tsx +24 -0
- package/src/containers/Analytics/actions.tsx +109 -0
- package/src/containers/Analytics/constants.tsx +5 -0
- package/src/containers/Analytics/index.tsx +3 -14
- package/src/containers/Analytics/interfaces.tsx +9 -0
- package/src/containers/Analytics/reducer.tsx +28 -0
- package/src/containers/Domains/actions.tsx +58 -0
- package/src/containers/Domains/constants.tsx +5 -0
- package/src/containers/Domains/index.tsx +3 -12
- package/src/containers/Domains/interfaces.tsx +9 -0
- package/src/containers/Domains/reducer.tsx +22 -0
- package/src/containers/Redirects/actions.tsx +190 -0
- package/src/containers/Redirects/constants.tsx +17 -1
- package/src/containers/Redirects/index.tsx +3 -14
- package/src/containers/Redirects/interfaces.tsx +23 -0
- package/src/containers/Redirects/reducer.tsx +35 -0
- package/src/containers/Settings/Languages/actions.tsx +88 -0
- package/src/containers/Settings/Languages/constants.tsx +6 -0
- package/src/containers/Settings/Languages/index.tsx +3 -15
- package/src/containers/Settings/Languages/reducer.tsx +31 -0
- package/src/containers/Settings/Social/actions.tsx +63 -0
- package/src/containers/Settings/Social/constants.tsx +3 -0
- package/src/containers/Settings/Social/index.tsx +3 -11
- package/src/containers/Settings/Social/interfaces.tsx +9 -0
- package/src/containers/Settings/Social/reducer.tsx +18 -0
- package/src/containers/Sites/actions.tsx +2 -6
- package/src/hooks/heartbeat.ts +32 -0
- package/src/hooks/index.tsx +2 -0
- package/src/index.tsx +6 -7
- package/src/modules/ActivityLog/ItemLog/EventItem/index.tsx +27 -13
- package/src/modules/ActivityLog/ItemLogUser/UserItem/EventItem/index.tsx +27 -13
- package/src/modules/ActivityLog/index.tsx +51 -22
- package/src/modules/Analytics/index.tsx +42 -33
- package/src/modules/App/Routing/index.tsx +4 -5
- package/src/modules/FileDrive/index.tsx +1 -1
- package/src/modules/GlobalEditor/index.tsx +6 -8
- package/src/modules/GlobalSettings/Robots/index.tsx +47 -24
- package/src/modules/MediaGallery/index.tsx +1 -1
- package/src/modules/PageEditor/index.tsx +5 -9
- package/src/modules/Redirects/RedirectItem/index.tsx +22 -9
- package/src/modules/Redirects/RedirectPanel/index.tsx +14 -13
- package/src/modules/Redirects/index.tsx +69 -26
- package/src/modules/Settings/ContentTypes/DataPacks/index.tsx +3 -4
- package/src/modules/Settings/Languages/LanguagePanel/Form/ConnectedField/index.tsx +18 -11
- package/src/modules/Settings/Languages/LanguagePanel/Form/index.tsx +9 -7
- package/src/modules/Settings/Languages/LanguagePanel/index.tsx +44 -38
- package/src/modules/Settings/Languages/Table/Header/index.tsx +19 -12
- package/src/modules/Settings/Languages/Table/Item/index.tsx +36 -21
- package/src/modules/Settings/Languages/Table/index.tsx +14 -6
- package/src/modules/Settings/Languages/index.tsx +30 -18
- package/src/modules/Settings/SeoAnalyticsSettings/Analytics/index.tsx +52 -42
- package/src/modules/Settings/Social/index.tsx +12 -17
- package/src/modules/StructuredData/StructuredDataList/index.tsx +2 -3
- package/src/types/index.tsx +6 -5
- package/tsconfig.paths.json +0 -1
- package/src/__tests__/modules/ActivityLog/ActivityLog.uc.test.tsx +0 -132
- package/src/__tests__/modules/Analytics/Analytics.uc.test.tsx +0 -168
- package/src/__tests__/modules/GlobalSettings/Robots/Robots.test.tsx +0 -110
- package/src/__tests__/modules/GlobalSettings/Robots/Robots.uc.test.tsx +0 -125
- package/src/__tests__/modules/Redirects/Redirects.uc.test.tsx +0 -164
- package/src/__tests__/modules/Settings/Languages/Languages.uc.test.tsx +0 -213
- package/src/__tests__/modules/Settings/Social/Social.uc.test.tsx +0 -171
- package/src/__tests__/store/activityLog.test.ts +0 -301
- package/src/__tests__/store/analytics.test.ts +0 -134
- package/src/__tests__/store/domains.test.ts +0 -107
- package/src/__tests__/store/languages.test.ts +0 -129
- package/src/__tests__/store/persist.test.ts +0 -47
- package/src/__tests__/store/redirects.test.ts +0 -313
- package/src/__tests__/store/social.test.ts +0 -165
- package/src/containers/ActivityLog/slice.ts +0 -45
- package/src/containers/Analytics/slice.ts +0 -48
- package/src/containers/Analytics/thunks.ts +0 -103
- package/src/containers/Domains/slice.ts +0 -37
- package/src/containers/Domains/thunks.ts +0 -60
- package/src/containers/Redirects/slice.ts +0 -60
- package/src/containers/Redirects/thunks.ts +0 -196
- package/src/containers/Settings/Languages/slice.ts +0 -48
- package/src/containers/Settings/Languages/thunks.ts +0 -83
- package/src/containers/Settings/Social/slice.ts +0 -40
- package/src/containers/Settings/Social/thunks.ts +0 -68
- package/src/store/hooks.ts +0 -37
- package/src/store/index.ts +0 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { analytics } from "@ax/api";
|
|
2
|
+
import { appActions } from "@ax/containers/App";
|
|
3
|
+
import { handleRequest } from "@ax/helpers";
|
|
4
|
+
import type { IAnalytics } from "@ax/types";
|
|
5
|
+
import type { Dispatch } from "redux";
|
|
6
|
+
import { SET_ANALYTICS } from "./constants";
|
|
7
|
+
import type { ISetAnalytics } from "./interfaces";
|
|
8
|
+
|
|
9
|
+
function setAnalytics(analytics: IAnalytics): ISetAnalytics {
|
|
10
|
+
return { type: SET_ANALYTICS, payload: analytics };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getAnalytics(siteId?: number | null): (dispatch: Dispatch) => Promise<void> {
|
|
14
|
+
return async (dispatch) => {
|
|
15
|
+
try {
|
|
16
|
+
const callback = async () => analytics.getAnalytics(siteId || "global");
|
|
17
|
+
|
|
18
|
+
const responseActions = {
|
|
19
|
+
handleSuccess: (response: any) => {
|
|
20
|
+
dispatch(setAnalytics(response));
|
|
21
|
+
},
|
|
22
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
await handleRequest(callback, responseActions, [])(dispatch);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.log(e);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function updateAnalytics(analyticsState: IAnalytics, siteId?: number | null): (dispatch: Dispatch) => Promise<boolean> {
|
|
33
|
+
return async (dispatch) => {
|
|
34
|
+
try {
|
|
35
|
+
const { scriptCode, dimensions, groups } = analyticsState;
|
|
36
|
+
const callback = async () => {
|
|
37
|
+
const promises = [];
|
|
38
|
+
const site = siteId || "global";
|
|
39
|
+
promises.push(analytics.updateScriptCode(site, { scriptCode }));
|
|
40
|
+
promises.push(analytics.createDimensions(site, { dimensions }));
|
|
41
|
+
promises.push(analytics.createDimensionsGroups(site, { groups }));
|
|
42
|
+
return Promise.all(promises);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const responseActions = {
|
|
46
|
+
handleSuccess: () => {
|
|
47
|
+
getAnalytics(siteId)(dispatch);
|
|
48
|
+
},
|
|
49
|
+
handleError: (response: any) => {
|
|
50
|
+
const {
|
|
51
|
+
data: { message },
|
|
52
|
+
} = response;
|
|
53
|
+
const isMultiple = Array.isArray(message) && message.length > 1;
|
|
54
|
+
const msg = isMultiple ? `The action failed due to ${message.length} errors.` : undefined;
|
|
55
|
+
appActions.handleError(response, isMultiple, msg)(dispatch);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.log(e);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function updateScriptCode(scriptCode: string, siteId?: number | null): (dispatch: Dispatch) => Promise<boolean> {
|
|
68
|
+
return async (dispatch) => {
|
|
69
|
+
try {
|
|
70
|
+
const callback = async () => {
|
|
71
|
+
return analytics.updateScriptCode(siteId || "global", { scriptCode });
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const responseActions = {
|
|
75
|
+
handleSuccess: () => {
|
|
76
|
+
getAnalytics(siteId)(dispatch);
|
|
77
|
+
},
|
|
78
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.log(e);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function deleteScriptCode(siteId?: number | null): (dispatch: Dispatch) => Promise<boolean> {
|
|
90
|
+
return async (dispatch) => {
|
|
91
|
+
try {
|
|
92
|
+
const callback = async () => analytics.deleteScriptCode(siteId || "global");
|
|
93
|
+
|
|
94
|
+
const responseActions = {
|
|
95
|
+
handleSuccess: () => {
|
|
96
|
+
getAnalytics(siteId)(dispatch);
|
|
97
|
+
},
|
|
98
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return await handleRequest(callback, responseActions, [])(dispatch);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.log(e);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { setAnalytics, getAnalytics, updateAnalytics, updateScriptCode, deleteScriptCode };
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as analyticsActions from "./actions";
|
|
2
|
+
import { analyticsReducer } from "./reducer";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
setAnalytics,
|
|
6
|
-
getAnalytics,
|
|
7
|
-
updateAnalytics,
|
|
8
|
-
updateScriptCode,
|
|
9
|
-
deleteScriptCode,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { analyticsActions };
|
|
13
|
-
|
|
14
|
-
export type { IAnalyticsState } from "./slice";
|
|
15
|
-
export { analyticsInitialState, analyticsReducer } from "./slice";
|
|
4
|
+
export { analyticsActions, analyticsReducer };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IDimension, IDimensionsGroup } from "@ax/types";
|
|
2
|
+
import { SET_ANALYTICS } from "./constants";
|
|
3
|
+
import type { AnalyticsActionsCreators } from "./interfaces";
|
|
4
|
+
|
|
5
|
+
export interface IAnalyticsState {
|
|
6
|
+
scriptCode: string;
|
|
7
|
+
siteScriptCodeExists: boolean;
|
|
8
|
+
dimensions: IDimension[];
|
|
9
|
+
groups: IDimensionsGroup[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const initialState = {
|
|
13
|
+
scriptCode: "",
|
|
14
|
+
siteScriptCodeExists: false,
|
|
15
|
+
dimensions: [],
|
|
16
|
+
groups: [],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function reducer(state = initialState, action: AnalyticsActionsCreators): IAnalyticsState {
|
|
20
|
+
switch (action.type) {
|
|
21
|
+
case SET_ANALYTICS:
|
|
22
|
+
return { ...state, ...action.payload };
|
|
23
|
+
default:
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { initialState as analyticsInitialState, reducer as analyticsReducer };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { domains } from "@ax/api";
|
|
2
|
+
import { appActions } from "@ax/containers/App";
|
|
3
|
+
import { handleRequest } from "@ax/helpers";
|
|
4
|
+
import type { IDomainRobot } from "@ax/types";
|
|
5
|
+
import { SET_DOMAINS_ROBOTS } from "./constants";
|
|
6
|
+
import type { ISetDomainsRobots } from "./interfaces";
|
|
7
|
+
|
|
8
|
+
function setDomainsRobots(robots: IDomainRobot[]): ISetDomainsRobots {
|
|
9
|
+
return { type: SET_DOMAINS_ROBOTS, payload: { robots } };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getDomainsRobots(): (dispatch: any) => Promise<void> {
|
|
13
|
+
return async (dispatch) => {
|
|
14
|
+
try {
|
|
15
|
+
const callback = async () => domains.getDomainsRobots();
|
|
16
|
+
|
|
17
|
+
const responseActions = {
|
|
18
|
+
handleSuccess: (response: any) => {
|
|
19
|
+
dispatch(setDomainsRobots(response));
|
|
20
|
+
},
|
|
21
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
await handleRequest(callback, responseActions, [appActions.setIsLoading])(dispatch);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.log(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function updateDomainsRobots(robots: IDomainRobot[]): (dispatch: any) => Promise<boolean> {
|
|
32
|
+
return async (dispatch) => {
|
|
33
|
+
try {
|
|
34
|
+
const callback = async () => domains.updateDomainsRobots(robots);
|
|
35
|
+
|
|
36
|
+
const responseActions = {
|
|
37
|
+
handleSuccess: () => {
|
|
38
|
+
dispatch(getDomainsRobots());
|
|
39
|
+
},
|
|
40
|
+
handleError: (response: any) => {
|
|
41
|
+
const {
|
|
42
|
+
data: { message },
|
|
43
|
+
} = response;
|
|
44
|
+
const isMultiple = Array.isArray(message) && message.length > 1;
|
|
45
|
+
const msg = isMultiple ? `The action failed due to ${message.length} errors.` : undefined;
|
|
46
|
+
appActions.handleError(response, isMultiple, msg)(dispatch);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.log(e);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { getDomainsRobots, updateDomainsRobots };
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as domainsActions from "./actions";
|
|
2
|
+
import { domainsReducer } from "./reducer";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
setDomainsRobots,
|
|
6
|
-
getDomainsRobots,
|
|
7
|
-
updateDomainsRobots,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export { domainsActions };
|
|
11
|
-
|
|
12
|
-
export type { IDomainsState } from "./slice";
|
|
13
|
-
export { domainsInitialState, domainsReducer } from "./slice";
|
|
4
|
+
export { domainsActions, domainsReducer };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IDomainRobot } from "@ax/types";
|
|
2
|
+
import type { SET_DOMAINS_ROBOTS } from "./constants";
|
|
3
|
+
|
|
4
|
+
export interface ISetDomainsRobots {
|
|
5
|
+
type: typeof SET_DOMAINS_ROBOTS;
|
|
6
|
+
payload: { robots: IDomainRobot[] };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type DomainsActionsCreators = ISetDomainsRobots;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IDomainRobot } from "@ax/types";
|
|
2
|
+
import { SET_DOMAINS_ROBOTS } from "./constants";
|
|
3
|
+
import type { DomainsActionsCreators } from "./interfaces";
|
|
4
|
+
|
|
5
|
+
export interface IDomainsState {
|
|
6
|
+
robots: IDomainRobot[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const initialState = {
|
|
10
|
+
robots: [],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function reducer(state = initialState, action: DomainsActionsCreators): IDomainsState {
|
|
14
|
+
switch (action.type) {
|
|
15
|
+
case SET_DOMAINS_ROBOTS:
|
|
16
|
+
return { ...state, ...action.payload };
|
|
17
|
+
default:
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { initialState as domainsInitialState, reducer as domainsReducer };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { redirects } from "@ax/api";
|
|
2
|
+
import { appActions } from "@ax/containers/App";
|
|
3
|
+
import { handleRequest } from "@ax/helpers";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_PARAMS,
|
|
6
|
+
ERROR_CODE,
|
|
7
|
+
SET_IMPORTS,
|
|
8
|
+
SET_REDIRECTS,
|
|
9
|
+
SET_TOTAL_IMPORTS,
|
|
10
|
+
SET_TOTAL_ITEMS,
|
|
11
|
+
} from "./constants";
|
|
12
|
+
import type { ISetImports, ISetRedirects, ISetTotalImports, ISetTotalItems } from "./interfaces";
|
|
13
|
+
|
|
14
|
+
function setRedirects(redirects: any[]): ISetRedirects {
|
|
15
|
+
return { type: SET_REDIRECTS, payload: { redirects } };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function setTotalItems(totalItems: number): ISetTotalItems {
|
|
19
|
+
return { type: SET_TOTAL_ITEMS, payload: { totalItems } };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setImports(imports: any): ISetImports {
|
|
23
|
+
return { type: SET_IMPORTS, payload: { imports } };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function setTotalImports(totalImports: number): ISetTotalImports {
|
|
27
|
+
return { type: SET_TOTAL_IMPORTS, payload: { totalImports } };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getRedirects(params: any, filters?: string): (dispatch: any) => Promise<void> {
|
|
31
|
+
return async (dispatch) => {
|
|
32
|
+
try {
|
|
33
|
+
dispatch(setRedirects([]));
|
|
34
|
+
const callback = async () => redirects.getRedirects(params, filters);
|
|
35
|
+
|
|
36
|
+
const responseActions = {
|
|
37
|
+
handleSuccess: (response: any) => {
|
|
38
|
+
const { items, totalItems } = response;
|
|
39
|
+
dispatch(setRedirects(items));
|
|
40
|
+
dispatch(setTotalItems(totalItems));
|
|
41
|
+
},
|
|
42
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
await handleRequest(callback, responseActions, [appActions.setIsLoading])(dispatch);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.log(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function addRedirect(
|
|
53
|
+
redirect: { from: string; to: string | number },
|
|
54
|
+
errorAction: () => void,
|
|
55
|
+
force?: boolean,
|
|
56
|
+
filter?: string,
|
|
57
|
+
): (dispatch: any, getState: any) => Promise<void> {
|
|
58
|
+
return async (dispatch, getState) => {
|
|
59
|
+
try {
|
|
60
|
+
const {
|
|
61
|
+
sites: { currentSiteInfo },
|
|
62
|
+
} = getState();
|
|
63
|
+
|
|
64
|
+
const callback = async () => redirects.createRedirect(redirect, force);
|
|
65
|
+
|
|
66
|
+
const responseActions = {
|
|
67
|
+
handleSuccess: () => {
|
|
68
|
+
const params = { ...DEFAULT_PARAMS };
|
|
69
|
+
const siteFilterQuery = currentSiteInfo && currentSiteInfo.id ? `&sites=${currentSiteInfo.id}` : filter;
|
|
70
|
+
dispatch(getRedirects(params, siteFilterQuery));
|
|
71
|
+
},
|
|
72
|
+
handleError: (response: any) => {
|
|
73
|
+
const { status } = response;
|
|
74
|
+
|
|
75
|
+
status === ERROR_CODE.isBeingUsed ? errorAction() : appActions.handleError(response)(dispatch);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
await handleRequest(callback, responseActions, [])(dispatch);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.log(e);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function updateRedirect(
|
|
87
|
+
redirect: { from: string; to: string | number },
|
|
88
|
+
redirectID: number,
|
|
89
|
+
filter?: string,
|
|
90
|
+
): (dispatch: any, getState: any) => Promise<void> {
|
|
91
|
+
return async (dispatch, getState) => {
|
|
92
|
+
try {
|
|
93
|
+
const {
|
|
94
|
+
sites: { currentSiteInfo },
|
|
95
|
+
} = getState();
|
|
96
|
+
|
|
97
|
+
const callback = async () => redirects.updateRedirect(redirect, redirectID);
|
|
98
|
+
|
|
99
|
+
const responseActions = {
|
|
100
|
+
handleSuccess: () => {
|
|
101
|
+
const params = { ...DEFAULT_PARAMS };
|
|
102
|
+
const siteFilterQuery = currentSiteInfo && currentSiteInfo.id ? `&sites=${currentSiteInfo.id}` : filter;
|
|
103
|
+
dispatch(getRedirects(params, siteFilterQuery));
|
|
104
|
+
},
|
|
105
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
await handleRequest(callback, responseActions, [])(dispatch);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.log(e);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function deleteRedirect(
|
|
116
|
+
redirectID: number | number[],
|
|
117
|
+
filter?: string,
|
|
118
|
+
): (dispatch: any, getState: any) => Promise<boolean> {
|
|
119
|
+
return async (dispatch, getState) => {
|
|
120
|
+
try {
|
|
121
|
+
const {
|
|
122
|
+
sites: { currentSiteInfo },
|
|
123
|
+
} = getState();
|
|
124
|
+
|
|
125
|
+
const callback = async () =>
|
|
126
|
+
Array.isArray(redirectID) ? redirects.deleteRedirectsBulk(redirectID) : redirects.deleteRedirect(redirectID);
|
|
127
|
+
|
|
128
|
+
const responseActions = {
|
|
129
|
+
handleSuccess: () => {
|
|
130
|
+
const params = { ...DEFAULT_PARAMS };
|
|
131
|
+
const siteFilterQuery = currentSiteInfo?.id ? `&sites=${currentSiteInfo.id}` : filter;
|
|
132
|
+
dispatch(getRedirects(params, siteFilterQuery));
|
|
133
|
+
},
|
|
134
|
+
handleError: (response: any) => {
|
|
135
|
+
const {
|
|
136
|
+
data: { message },
|
|
137
|
+
} = response;
|
|
138
|
+
const isMultiple = Array.isArray(message) && message.length > 1;
|
|
139
|
+
const msg = isMultiple ? `The delete action failed due to ${message.length} errors.` : undefined;
|
|
140
|
+
appActions.handleError(response, isMultiple, msg)(dispatch);
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.log(e);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function importRedirects(
|
|
153
|
+
redirect: { from: string; to: string | number }[],
|
|
154
|
+
check: boolean,
|
|
155
|
+
): (dispatch: any) => Promise<boolean> {
|
|
156
|
+
return async (dispatch) => {
|
|
157
|
+
try {
|
|
158
|
+
const callback = async () =>
|
|
159
|
+
check ? redirects.createRedirectsBulkCheck(redirect) : redirects.createRedirectsBulk(redirect);
|
|
160
|
+
|
|
161
|
+
const responseActions = {
|
|
162
|
+
handleSuccess: (response: any) => {
|
|
163
|
+
if (check) {
|
|
164
|
+
const { total, error, existing, ok } = response;
|
|
165
|
+
dispatch(setImports({ error, existing, ok }));
|
|
166
|
+
dispatch(setTotalImports(total));
|
|
167
|
+
} else {
|
|
168
|
+
const params = { ...DEFAULT_PARAMS };
|
|
169
|
+
dispatch(getRedirects(params));
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
handleError: (response: any) => {
|
|
173
|
+
const {
|
|
174
|
+
data: { message },
|
|
175
|
+
} = response;
|
|
176
|
+
const isMultiple = Array.isArray(message) && message.length > 1;
|
|
177
|
+
const msg = isMultiple ? `The import action failed due to ${message.length} errors.` : undefined;
|
|
178
|
+
appActions.handleError(response, isMultiple, msg)(dispatch);
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
return await handleRequest(callback, responseActions, [])(dispatch);
|
|
183
|
+
} catch (e) {
|
|
184
|
+
console.log(e);
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { getRedirects, addRedirect, updateRedirect, deleteRedirect, importRedirects };
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
const NAME = "redirects";
|
|
2
|
+
|
|
3
|
+
const SET_REDIRECTS = `${NAME}/SET_REDIRECTS`;
|
|
4
|
+
const SET_TOTAL_ITEMS = `${NAME}/SET_TOTAL_ITEMS`;
|
|
5
|
+
const SET_TOTAL_IMPORTS = `${NAME}/SET_TOTAL_IMPORTS`;
|
|
6
|
+
const SET_IMPORTS = `${NAME}/SET_IMPORTS`;
|
|
7
|
+
|
|
1
8
|
const ITEMS_PER_PAGE = 50;
|
|
2
9
|
|
|
3
10
|
const DEFAULT_PARAMS = {
|
|
@@ -10,4 +17,13 @@ const ERROR_CODE = {
|
|
|
10
17
|
isBeingUsed: 409,
|
|
11
18
|
};
|
|
12
19
|
|
|
13
|
-
export {
|
|
20
|
+
export {
|
|
21
|
+
NAME,
|
|
22
|
+
SET_REDIRECTS,
|
|
23
|
+
SET_TOTAL_ITEMS,
|
|
24
|
+
ERROR_CODE,
|
|
25
|
+
DEFAULT_PARAMS,
|
|
26
|
+
ITEMS_PER_PAGE,
|
|
27
|
+
SET_IMPORTS,
|
|
28
|
+
SET_TOTAL_IMPORTS,
|
|
29
|
+
};
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as redirectsActions from "./actions";
|
|
2
|
+
import { redirectsReducer } from "./reducer";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
getRedirects,
|
|
5
|
-
addRedirect,
|
|
6
|
-
updateRedirect,
|
|
7
|
-
deleteRedirect,
|
|
8
|
-
importRedirects,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { redirectsActions };
|
|
12
|
-
|
|
13
|
-
export type { IRedirectsState } from "./slice";
|
|
14
|
-
export { redirectsInitialState, redirectsReducer } from "./slice";
|
|
15
|
-
export type { IAddRedirectResult, IRedirectsQuery } from "./thunks";
|
|
4
|
+
export { redirectsActions, redirectsReducer };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SET_IMPORTS, SET_REDIRECTS, SET_TOTAL_IMPORTS, SET_TOTAL_ITEMS } from "./constants";
|
|
2
|
+
|
|
3
|
+
export interface ISetRedirects {
|
|
4
|
+
type: typeof SET_REDIRECTS;
|
|
5
|
+
payload: { redirects: any[] };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ISetTotalItems {
|
|
9
|
+
type: typeof SET_TOTAL_ITEMS;
|
|
10
|
+
payload: { totalItems: number };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ISetImports {
|
|
14
|
+
type: typeof SET_IMPORTS;
|
|
15
|
+
payload: { imports: any };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ISetTotalImports {
|
|
19
|
+
type: typeof SET_TOTAL_IMPORTS;
|
|
20
|
+
payload: { totalImports: number };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type RedirectsActionsCreators = ISetRedirects | ISetTotalItems | ISetImports | ISetTotalImports;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IRedirect } from "@ax/types";
|
|
2
|
+
import { SET_IMPORTS, SET_REDIRECTS, SET_TOTAL_IMPORTS, SET_TOTAL_ITEMS } from "./constants";
|
|
3
|
+
import type { RedirectsActionsCreators } from "./interfaces";
|
|
4
|
+
|
|
5
|
+
export interface IRedirectsState {
|
|
6
|
+
redirects: any[];
|
|
7
|
+
totalItems: number;
|
|
8
|
+
totalImports: number;
|
|
9
|
+
imports: null | {
|
|
10
|
+
error: IRedirect[];
|
|
11
|
+
existing: IRedirect[];
|
|
12
|
+
ok: IRedirect[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const initialState = {
|
|
17
|
+
redirects: [],
|
|
18
|
+
totalItems: 0,
|
|
19
|
+
totalImports: 0,
|
|
20
|
+
imports: null,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function reducer(state = initialState, action: RedirectsActionsCreators): IRedirectsState {
|
|
24
|
+
switch (action.type) {
|
|
25
|
+
case SET_REDIRECTS:
|
|
26
|
+
case SET_TOTAL_ITEMS:
|
|
27
|
+
case SET_IMPORTS:
|
|
28
|
+
case SET_TOTAL_IMPORTS:
|
|
29
|
+
return { ...state, ...action.payload };
|
|
30
|
+
default:
|
|
31
|
+
return state;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { initialState as redirectsInitialState, reducer as redirectsReducer };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Dispatch } from "redux";
|
|
2
|
+
import type { ISiteLanguage } from "@ax/types";
|
|
3
|
+
import { handleRequest } from "@ax/helpers";
|
|
4
|
+
import { languages } from "@ax/api";
|
|
5
|
+
import { appActions } from "@ax/containers/App";
|
|
6
|
+
import { sitesActions } from "@ax/containers/Sites";
|
|
7
|
+
import { UPDATE_FORM, CREATE_FORM } from "./constants";
|
|
8
|
+
import { languagesInitialState } from "./reducer";
|
|
9
|
+
|
|
10
|
+
const { setIsSaving, setIsLoading } = appActions;
|
|
11
|
+
const { getSiteLanguages } = sitesActions;
|
|
12
|
+
function setForm(form: any) {
|
|
13
|
+
return { type: CREATE_FORM, payload: { form } };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function updateForm(form: any) {
|
|
17
|
+
return { type: UPDATE_FORM, payload: { form } };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function updateFormValue(valueObj: any): (dispatch: Dispatch, getState: any) => void {
|
|
21
|
+
return (dispatch, getState) => {
|
|
22
|
+
const {
|
|
23
|
+
languages: { form },
|
|
24
|
+
} = getState();
|
|
25
|
+
const updatedForm = { ...form, ...valueObj };
|
|
26
|
+
dispatch(updateForm(updatedForm));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resetForm(): (dispatch: Dispatch) => void {
|
|
31
|
+
return (dispatch) => {
|
|
32
|
+
const { form } = languagesInitialState;
|
|
33
|
+
dispatch(updateForm(form));
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function createSiteLanguage(siteID: number, data: ISiteLanguage): (dispatch: Dispatch) => Promise<void> {
|
|
38
|
+
return async (dispatch) => {
|
|
39
|
+
try {
|
|
40
|
+
const responseActions = {
|
|
41
|
+
handleSuccess: () => getSiteLanguages(siteID)(dispatch),
|
|
42
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const callback = async () => languages.createSiteLanguage(siteID, data);
|
|
46
|
+
|
|
47
|
+
await handleRequest(callback, responseActions, [setIsSaving])(dispatch);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.log(e); // TODO: capturar error bien
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function updateSiteLanguage(siteID: number, data: ISiteLanguage): (dispatch: Dispatch) => Promise<void> {
|
|
55
|
+
return async (dispatch) => {
|
|
56
|
+
try {
|
|
57
|
+
const responseActions = {
|
|
58
|
+
handleSuccess: () => getSiteLanguages(siteID)(dispatch),
|
|
59
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const callback = async () => languages.updateSiteLanguage(siteID, data);
|
|
63
|
+
|
|
64
|
+
await handleRequest(callback, responseActions, [setIsSaving])(dispatch);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.log(e); // TODO: capturar error bien
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function deleteSiteLanguage(siteID: number, id: number): (dispatch: Dispatch) => Promise<void> {
|
|
72
|
+
return async (dispatch) => {
|
|
73
|
+
try {
|
|
74
|
+
const responseActions = {
|
|
75
|
+
handleSuccess: () => getSiteLanguages(siteID)(dispatch),
|
|
76
|
+
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const callback = async () => languages.deleteSiteLanguage(siteID, id);
|
|
80
|
+
|
|
81
|
+
await handleRequest(callback, responseActions, [setIsLoading])(dispatch);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.log(e); // TODO: capturar error bien
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { createSiteLanguage, updateSiteLanguage, setForm, updateForm, updateFormValue, resetForm, deleteSiteLanguage };
|