@capillarytech/creatives-library 7.10.8 → 7.10.9
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/app.js +4 -2
- package/package.json +1 -1
- package/routes.js +19 -0
- package/services/api.js +18 -5
- package/v2Containers/App/constants.js +2 -0
- package/v2Containers/Cap/index.js +9 -4
- package/v2Containers/Cap/reducer.js +4 -1
- package/v2Containers/Cap/sagas.js +32 -21
package/app.js
CHANGED
|
@@ -6,6 +6,7 @@ import createHistory from 'history/lib/createBrowserHistory';
|
|
|
6
6
|
import { applyRouterMiddleware, Router, useRouterHistory } from 'react-router';
|
|
7
7
|
import { syncHistoryWithStore } from 'react-router-redux';
|
|
8
8
|
import { useScroll } from 'react-router-scroll';
|
|
9
|
+
import CapSomethingWentWrong from '@capillarytech/cap-ui-library/CapSomethingWentWrong';
|
|
9
10
|
import Bugsnag from '@bugsnag/js';
|
|
10
11
|
import BugsnagPluginReact from '@bugsnag/plugin-react';
|
|
11
12
|
import CapV2 from 'v2Containers/Cap';
|
|
@@ -105,7 +106,8 @@ const rootRoute = {
|
|
|
105
106
|
if (
|
|
106
107
|
props.location.pathname === 'v2' ||
|
|
107
108
|
props.location.pathname === 'v2/' ||
|
|
108
|
-
props.location.pathname === 'v2/loyalty'
|
|
109
|
+
props.location.pathname === 'v2/loyalty' ||
|
|
110
|
+
props.location.pathname === 'v2/somethingwentwrong'
|
|
109
111
|
) {
|
|
110
112
|
return <CapV2 {...props} />;
|
|
111
113
|
}
|
|
@@ -114,7 +116,7 @@ const rootRoute = {
|
|
|
114
116
|
childRoutes: createRoutes(store),
|
|
115
117
|
};
|
|
116
118
|
|
|
117
|
-
const ErrorScreen = () => <
|
|
119
|
+
const ErrorScreen = () => <CapSomethingWentWrong url={`${pathConfig.publicPath}v2`} />
|
|
118
120
|
|
|
119
121
|
const render = (messages) => {
|
|
120
122
|
ReactDOM.render(
|
package/package.json
CHANGED
package/routes.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// They are all wrapped in the App component, which should contain the navbar etc
|
|
3
3
|
// See http://blog.mxstbr.com/2016/01/react-apps-with-pages for more information
|
|
4
4
|
// about the code splitting business
|
|
5
|
+
import React from 'react';
|
|
5
6
|
import { getAsyncInjectors } from 'utils/asyncInjectors';
|
|
7
|
+
import pathConfig from './config/path'
|
|
6
8
|
import * as rootSaga from 'containers/Cap/sagas';
|
|
7
9
|
import * as smsSagas from 'containers/Sms/Create/sagas';
|
|
8
10
|
import * as smsEditSagas from 'containers/Sms/Edit/sagas';
|
|
@@ -22,6 +24,13 @@ const loadModule = (cb) => (componentModule) => {
|
|
|
22
24
|
cb(null, componentModule.default);
|
|
23
25
|
};
|
|
24
26
|
|
|
27
|
+
const loadModuleWithProps = (cb) => (ComponentModule, props) => {
|
|
28
|
+
cb(
|
|
29
|
+
null,
|
|
30
|
+
() => <ComponentModule.default {...props} />
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
25
34
|
export default function createRoutes(store) {
|
|
26
35
|
// Create reusable async injectors using getAsyncInjectors factory
|
|
27
36
|
updateCharCount("", false); // calling here to get unsubscribeurl from api.
|
|
@@ -598,6 +607,16 @@ export default function createRoutes(store) {
|
|
|
598
607
|
|
|
599
608
|
importModules.catch(errorLoading);
|
|
600
609
|
},
|
|
610
|
+
}, {
|
|
611
|
+
path: '/v2/somethingwentwrong',
|
|
612
|
+
name: 'somethingwentwrong',
|
|
613
|
+
getComponent(nextState, cb) {
|
|
614
|
+
import('@capillarytech/cap-ui-library/CapSomethingWentWrong')
|
|
615
|
+
.then((Component) => {
|
|
616
|
+
loadModuleWithProps(cb)(Component, { url: `${pathConfig.publicPath}v2` });
|
|
617
|
+
})
|
|
618
|
+
.catch(errorLoading);
|
|
619
|
+
},
|
|
601
620
|
},
|
|
602
621
|
{
|
|
603
622
|
path: '/v2(/:channel)',
|
package/services/api.js
CHANGED
|
@@ -90,12 +90,18 @@ function checkStatus(response) {
|
|
|
90
90
|
const isLoginPage = window.location.pathname.indexOf('/login') !== -1;
|
|
91
91
|
if (!isLoginPage) redirectIfUnauthenticated(response);
|
|
92
92
|
|
|
93
|
-
const error = new Error(statusText);
|
|
93
|
+
const error = new Error({ statusText, status });
|
|
94
94
|
error.response = response;
|
|
95
|
+
error.isError = true;
|
|
96
|
+
error.status = status;
|
|
95
97
|
throw error;
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
function
|
|
100
|
+
function showSomethingwentWrong() {
|
|
101
|
+
window.history.pushState({}, '', `${pathConfig.publicPath}v2/somethingwentwrong`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function request(url, options, handleUnauthorizedStatus) {
|
|
99
105
|
try {
|
|
100
106
|
requestCallerName = getCallerName();
|
|
101
107
|
} catch (e) {
|
|
@@ -103,8 +109,14 @@ function request(url, options) {
|
|
|
103
109
|
}
|
|
104
110
|
const fetchUrl = url.indexOf('?') !== -1 ? `${url}&time=${Date.now()}` : `${url}?time=${Date.now()}`;
|
|
105
111
|
return fetch(fetchUrl, options)
|
|
106
|
-
.then(
|
|
107
|
-
|
|
112
|
+
.then(response => {
|
|
113
|
+
if (response.status === 403 && handleUnauthorizedStatus) {
|
|
114
|
+
showSomethingwentWrong();
|
|
115
|
+
}
|
|
116
|
+
return checkStatus(response);
|
|
117
|
+
})
|
|
118
|
+
.then(parseJSON)
|
|
119
|
+
.catch(error => error);
|
|
108
120
|
}
|
|
109
121
|
|
|
110
122
|
function getAPICallObject(method, body, isFileUpload = false, loadCampaignHeaders = false) {
|
|
@@ -196,9 +208,10 @@ export const getSidebar = () => {
|
|
|
196
208
|
return response;
|
|
197
209
|
};
|
|
198
210
|
|
|
211
|
+
// if 403, show SWR page
|
|
199
212
|
export const getUserData = () => {
|
|
200
213
|
const url = `${API_AUTH_ENDPOINT}/user?include_features=1`;
|
|
201
|
-
return request(url, getAPICallObject('GET'));
|
|
214
|
+
return request(url, getAPICallObject('GET'), true);
|
|
202
215
|
};
|
|
203
216
|
|
|
204
217
|
export const createTemplate = ({template}) => {
|
|
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import Helmet from 'react-helmet';
|
|
4
4
|
import { connect } from 'react-redux';
|
|
5
|
-
import { CapNotification, CapModal, CapSnackBar } from '@capillarytech/cap-ui-library';
|
|
5
|
+
import { CapNotification, CapModal, CapSnackBar, CapSomethingWentWrong } from '@capillarytech/cap-ui-library';
|
|
6
6
|
import { bindActionCreators } from 'redux';
|
|
7
7
|
import styled from 'styled-components';
|
|
8
8
|
import { createStructuredSelector } from 'reselect';
|
|
@@ -18,8 +18,8 @@ import * as locationActions from '../LanguageProvider/actions';
|
|
|
18
18
|
import * as appActions from '../App/actions';
|
|
19
19
|
import config from '../../config/app';
|
|
20
20
|
import NavigationBar from '../../v2Components/NavigationBar';
|
|
21
|
-
import { engagePlusPublicPath } from '../../config/path';
|
|
22
|
-
import { GTM_TRACKING_ID, CREATIVES_UI_VIEW } from '../App/constants';
|
|
21
|
+
import { engagePlusPublicPath, publicPath } from '../../config/path';
|
|
22
|
+
import { GTM_TRACKING_ID, CREATIVES_UI_VIEW, FAILURE } from '../App/constants';
|
|
23
23
|
import { makeSelectLocale } from '../../v2Containers/LanguageProvider/selectors';
|
|
24
24
|
import {
|
|
25
25
|
ORG_SETTINGS_URL,
|
|
@@ -415,7 +415,7 @@ export class Cap extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
415
415
|
|
|
416
416
|
render() {
|
|
417
417
|
const { Global, location } = this.props;
|
|
418
|
-
const { topbarMenuData, isLoggedIn, currentOrgDetails } = Global;
|
|
418
|
+
const { topbarMenuData, isLoggedIn, currentOrgDetails = {}, getUserDataStatus, getUserDataCode } = Global;
|
|
419
419
|
const topbarMenuDataOptions = topbarMenuData && topbarMenuData.data ? topbarMenuData.data : [];
|
|
420
420
|
const type = this.props.location.query.type;
|
|
421
421
|
const toastMessages = this.props.Global.messages;
|
|
@@ -438,6 +438,11 @@ export class Cap extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
438
438
|
]}
|
|
439
439
|
/>
|
|
440
440
|
<div className="wrapper">
|
|
441
|
+
{
|
|
442
|
+
getUserDataStatus === FAILURE &&
|
|
443
|
+
getUserDataCode !== 401 &&
|
|
444
|
+
<CapSomethingWentWrong url={`${window.location.origin}${publicPath}v2`} />
|
|
445
|
+
}
|
|
441
446
|
{isLoggedIn && type !== 'embedded' ?
|
|
442
447
|
<NavigationBar
|
|
443
448
|
userData={Global}
|
|
@@ -5,6 +5,7 @@ import { fromJS } from 'immutable';
|
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
import * as types from './constants';
|
|
7
7
|
import initialState from '../../initialState';
|
|
8
|
+
import { FAILURE } from '../App/constants';
|
|
8
9
|
|
|
9
10
|
function capReducer(state = fromJS(initialState.cap), action) {
|
|
10
11
|
switch (action.type) {
|
|
@@ -73,7 +74,9 @@ function capReducer(state = fromJS(initialState.cap), action) {
|
|
|
73
74
|
case types.GET_USER_DATA_FAILURE:
|
|
74
75
|
return state
|
|
75
76
|
.set('fetching_userdata', false)
|
|
76
|
-
.set('isLoggedIn', false)
|
|
77
|
+
.set('isLoggedIn', false)
|
|
78
|
+
.set('getUserDataStatus', FAILURE)
|
|
79
|
+
.set('getUserDataCode', action.status);
|
|
77
80
|
case types.GET_SCHEMA_FOR_ENTITY_REQUEST:
|
|
78
81
|
return state
|
|
79
82
|
.set('fetchingSchema', true);
|
|
@@ -77,27 +77,38 @@ function* logoutFlow() {
|
|
|
77
77
|
export function* fetchUserInfo(option) {
|
|
78
78
|
try {
|
|
79
79
|
const result = yield call(Api.getUserData);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
80
|
+
if (result?.isError || result?.status === 401) {
|
|
81
|
+
yield call(LocalStorage.clearItem, 'user');
|
|
82
|
+
yield put({
|
|
83
|
+
type: types.GET_USER_DATA_FAILURE,
|
|
84
|
+
error: result,
|
|
85
|
+
status: result?.status,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
else {
|
|
90
|
+
const userData = result.user;
|
|
91
|
+
// const orgId = yield select(makeSelectOrgId());
|
|
92
|
+
// yield put({type: types.GET_ORG_DETAILS_REQUEST, orgId});
|
|
93
|
+
const currentOrgDetails = result.currentOrgDetails;
|
|
94
|
+
if (!(currentOrgDetails && currentOrgDetails.basic_details && currentOrgDetails.basic_details.base_language && (currentOrgDetails.basic_details.base_language !== "" || currentOrgDetails.basic_details.base_language === null))) {
|
|
95
|
+
currentOrgDetails.basic_details.base_language = 'en';
|
|
96
|
+
}
|
|
97
|
+
if (!(currentOrgDetails && currentOrgDetails.basic_details && currentOrgDetails.basic_details.supported_languages && currentOrgDetails.basic_details.supported_languages.length > 0)) {
|
|
98
|
+
currentOrgDetails.basic_details.supported_languages = [
|
|
99
|
+
{
|
|
100
|
+
lang_id: 69,
|
|
101
|
+
language: "English",
|
|
102
|
+
iso_code: "en",
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
yield call(LocalStorage.saveItem, 'orgID', result.currentOrgId);
|
|
107
|
+
yield call(LocalStorage.saveItem, 'user', userData);
|
|
108
|
+
yield put({type: types.GET_USER_DATA_SUCCESS, userData, currentOrgId: result.currentOrgId, currentOrgDetails});
|
|
109
|
+
if (option.callback) {
|
|
110
|
+
option.callback(userData);
|
|
111
|
+
}
|
|
101
112
|
}
|
|
102
113
|
} catch (error) {
|
|
103
114
|
yield call(LocalStorage.clearItem, 'user');
|