@capillarytech/creatives-library 2.0.25 → 2.0.27
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/components/CmsTemplatesComponent/index.js +33 -0
- package/components/CmsTemplatesComponent/messages.js +17 -0
- package/components/CmsTemplatesComponent/tests/index.test.js +10 -0
- package/containers/CreativesContainer/SlideBoxContent.js +18 -3
- package/containers/CreativesContainer/SlideBoxFooter.js +18 -11
- package/containers/CreativesContainer/index.js +16 -2
- package/containers/CreativesContainer/messages.js +17 -0
- package/containers/Email/index.js +119 -222
- package/containers/EmailWrapper/actions.js +15 -0
- package/containers/EmailWrapper/constants.js +7 -0
- package/containers/EmailWrapper/index.js +187 -0
- package/containers/EmailWrapper/messages.js +37 -0
- package/containers/EmailWrapper/reducer.js +23 -0
- package/containers/EmailWrapper/sagas.js +11 -0
- package/containers/EmailWrapper/selectors.js +25 -0
- package/containers/EmailWrapper/tests/actions.test.js +18 -0
- package/containers/EmailWrapper/tests/index.test.js +10 -0
- package/containers/EmailWrapper/tests/reducer.test.js +9 -0
- package/containers/EmailWrapper/tests/sagas.test.js +15 -0
- package/containers/EmailWrapper/tests/selectors.test.js +10 -0
- package/containers/Sms/Create/index.js +1 -0
- package/containers/Templates/index.js +1 -2
- package/containers/Templates/messages.js +4 -0
- package/containers/Templates/selectors.js +21 -1
- package/package.json +1 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* EmailWrapper
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { connect } from 'react-redux';
|
|
9
|
+
import { FormattedMessage, injectIntl } from 'react-intl';
|
|
10
|
+
import { createStructuredSelector } from 'reselect';
|
|
11
|
+
import { bindActionCreators } from 'redux';
|
|
12
|
+
import _ from 'lodash';
|
|
13
|
+
import {CapInput, CapRadioCard, CapHeader} from '@capillarytech/cap-ui-library';
|
|
14
|
+
import { UserIsAuthenticated } from '../../utils/authWrapper';
|
|
15
|
+
import {selectEmailLayout, selectCmsTemplates, selectEdmEditor} from '../Templates/selectors';
|
|
16
|
+
import * as templatesActionsCreators from '../Templates/actions';
|
|
17
|
+
import Email from '../Email';
|
|
18
|
+
import CmsTemplatesComponent from '../../components/CmsTemplatesComponent';
|
|
19
|
+
import messages from './messages';
|
|
20
|
+
export class EmailWrapper extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
21
|
+
constructor(props) {
|
|
22
|
+
super(props);
|
|
23
|
+
this.state = {
|
|
24
|
+
routeParams: {
|
|
25
|
+
pathname: `/email/create`,
|
|
26
|
+
query: {},
|
|
27
|
+
},
|
|
28
|
+
modeContent: {
|
|
29
|
+
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
};
|
|
33
|
+
this.modes = [
|
|
34
|
+
{
|
|
35
|
+
title: <FormattedMessage {...messages.zipUpload}/>,
|
|
36
|
+
content: <FormattedMessage {...messages.zipUploadDesc}/>,
|
|
37
|
+
value: 'upload',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: <FormattedMessage {...messages.useEditor}/>,
|
|
41
|
+
content: <FormattedMessage {...messages.useEditorDesc}/>,
|
|
42
|
+
value: 'editor',
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
componentDidUpdate() {
|
|
47
|
+
const {emailCreateMode, EmailLayout, CmsTemplates, step} = this.props;
|
|
48
|
+
if (step === "modeSelection") {
|
|
49
|
+
if (emailCreateMode === 'upload' && !EmailLayout) {
|
|
50
|
+
document.getElementById('filename').click();
|
|
51
|
+
} else if (emailCreateMode === "editor" && !CmsTemplates) {
|
|
52
|
+
this.props.templatesActions.getEdmDefaultTemplates();
|
|
53
|
+
}
|
|
54
|
+
} else if (step === "createTemplate") {
|
|
55
|
+
const {modeContent} = this.state;
|
|
56
|
+
if (emailCreateMode === 'upload' && !EmailLayout) {
|
|
57
|
+
this.handleFileUpload(modeContent.e, modeContent.files);
|
|
58
|
+
} else if (emailCreateMode === "editor" && !CmsTemplates) {
|
|
59
|
+
this.handleEdmDefaultTemplateSelection(modeContent.id);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
onChange = (e) => {
|
|
64
|
+
this.props.onEmailModeChange( e.target.value );
|
|
65
|
+
};
|
|
66
|
+
handleFileUpload = (e, files) => {
|
|
67
|
+
const {location, templatesActions } = this.props;
|
|
68
|
+
if (files.length === 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const fileExtension = files[0].name.split('.').pop();
|
|
72
|
+
const supportedZipFormats = ['zip'];
|
|
73
|
+
const module = location.query.module || 'default';
|
|
74
|
+
const isLanguageSupport = location.query.isLanguageSupport || true;
|
|
75
|
+
const isEdmSupport = (location.query.isEdmSupport !== "false") || false;
|
|
76
|
+
|
|
77
|
+
if (supportedZipFormats.indexOf(fileExtension.toLowerCase()) !== -1) {
|
|
78
|
+
templatesActions.handleZipUpload(files[0]);
|
|
79
|
+
document.getElementById("filename").value = "";
|
|
80
|
+
} else if (fileExtension === 'html' || fileExtension === 'htm') {
|
|
81
|
+
const reader = new FileReader();
|
|
82
|
+
reader.onload = () => {
|
|
83
|
+
const text = reader.result;
|
|
84
|
+
templatesActions.handleHtmlUpload(text);
|
|
85
|
+
document.getElementById("filename").value = "";
|
|
86
|
+
const type = location.query.type;
|
|
87
|
+
this.setState({routeParams: {
|
|
88
|
+
pathname: `/email/create`,
|
|
89
|
+
query: type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module},
|
|
90
|
+
}});
|
|
91
|
+
};
|
|
92
|
+
reader.readAsText(files[0]);
|
|
93
|
+
} else {
|
|
94
|
+
// const message = getMessageObject('error', this.props.intl.formatMessage(messages.invalidUploadFileError), true);
|
|
95
|
+
// this.props.globalActions.addMessageToQueue(message);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
handleEdmDefaultTemplateSelection = (id) => {
|
|
100
|
+
const {CmsTemplates, templatesActions } = this.props;
|
|
101
|
+
const data = _.find(CmsTemplates, {_id: id});
|
|
102
|
+
const module = 'default'; //location.query.module || 'default';
|
|
103
|
+
const isLanguageSupport = true; //location.query.isLanguageSupport || true;
|
|
104
|
+
const isEdmSupport = true; //(location.query.isEdmSupport !== "false") || false;
|
|
105
|
+
|
|
106
|
+
templatesActions.setEdmTemplate(data);
|
|
107
|
+
const getQuery = {module, isLanguageSupport, isEdmSupport};
|
|
108
|
+
this.setState({routeParams: {
|
|
109
|
+
pathname: `/email/create`,
|
|
110
|
+
query: getQuery,
|
|
111
|
+
}});
|
|
112
|
+
};
|
|
113
|
+
useFileUpload = (e, {files}) => {
|
|
114
|
+
this.setState({modeContent: {e, files}});
|
|
115
|
+
}
|
|
116
|
+
useEditor = (id) => {
|
|
117
|
+
this.setState({modeContent: {id}});
|
|
118
|
+
}
|
|
119
|
+
render() {
|
|
120
|
+
const {emailCreateMode, isGetFormData, getFormData, type, EmailLayout, CmsTemplates, SelectedEdmDefaultTemplate} = this.props;
|
|
121
|
+
const isShowEmailCreate = (emailCreateMode === "upload" && EmailLayout !== null) || (emailCreateMode === "editor" && SelectedEdmDefaultTemplate);
|
|
122
|
+
return (
|
|
123
|
+
<div>
|
|
124
|
+
<input type="file" id="filename" style={{ display: 'none'}} accept=".zip, .html, .htm" onChange={(event) => this.useFileUpload(event, {files: event.target.files})} />
|
|
125
|
+
|
|
126
|
+
{!emailCreateMode ?
|
|
127
|
+
<div>
|
|
128
|
+
<CapInput
|
|
129
|
+
label={<FormattedMessage {...messages.creativeName}/>}
|
|
130
|
+
labelPosition="top"/>
|
|
131
|
+
<CapHeader type="h4"><FormattedMessage {...messages.createMode}/></CapHeader>
|
|
132
|
+
<CapRadioCard
|
|
133
|
+
panes={this.modes}
|
|
134
|
+
onChange={this.onChange}
|
|
135
|
+
selected={emailCreateMode}
|
|
136
|
+
/>
|
|
137
|
+
</div>
|
|
138
|
+
:
|
|
139
|
+
<div>
|
|
140
|
+
{isShowEmailCreate && <Email
|
|
141
|
+
key="email-create-template"
|
|
142
|
+
location={this.state.routeParams}
|
|
143
|
+
route={{ name: 'email' }}
|
|
144
|
+
params={{}}
|
|
145
|
+
isGetFormData={isGetFormData}
|
|
146
|
+
getFormdata={getFormData}
|
|
147
|
+
getFormSubscriptionData={getFormData}
|
|
148
|
+
getDefaultTags={type}
|
|
149
|
+
/>}
|
|
150
|
+
{CmsTemplates && !isShowEmailCreate && <CmsTemplatesComponent cmsTemplates={CmsTemplates} handleEdmDefaultTemplateSelection={this.useEditor}/>}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
</div>
|
|
154
|
+
}
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
EmailWrapper.propTypes = {
|
|
161
|
+
onEmailModeChange: PropTypes.func.isRequired,
|
|
162
|
+
isGetFormData: PropTypes.bool,
|
|
163
|
+
getFormData: PropTypes.func,
|
|
164
|
+
type: PropTypes.string,
|
|
165
|
+
emailCreateMode: PropTypes.string,
|
|
166
|
+
EmailLayout: PropTypes.object,
|
|
167
|
+
location: PropTypes.object,
|
|
168
|
+
route: PropTypes.object,
|
|
169
|
+
templatesActions: PropTypes.object,
|
|
170
|
+
CmsTemplates: PropTypes.arrayOf(PropTypes.object),
|
|
171
|
+
SelectedEdmDefaultTemplate: PropTypes.object,
|
|
172
|
+
step: PropTypes.string,
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const mapStateToProps = createStructuredSelector({
|
|
176
|
+
EmailLayout: selectEmailLayout(),
|
|
177
|
+
CmsTemplates: selectCmsTemplates(),
|
|
178
|
+
SelectedEdmDefaultTemplate: selectEdmEditor(),
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
function mapDispatchToProps(dispatch) {
|
|
182
|
+
return {
|
|
183
|
+
templatesActions: bindActionCreators(templatesActionsCreators, dispatch),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export default UserIsAuthenticated(connect(mapStateToProps, mapDispatchToProps)(injectIntl(EmailWrapper)));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* EmailWrapper Messages
|
|
3
|
+
*
|
|
4
|
+
* This contains all the text for the EmailWrapper component.
|
|
5
|
+
*/
|
|
6
|
+
import { defineMessages } from 'react-intl';
|
|
7
|
+
|
|
8
|
+
export default defineMessages({
|
|
9
|
+
header: {
|
|
10
|
+
id: 'app.containers.EmailWrapper.header',
|
|
11
|
+
defaultMessage: 'This is EmailWrapper container !',
|
|
12
|
+
},
|
|
13
|
+
useEditor: {
|
|
14
|
+
id: 'app.containers.EmailWrapper.useEditor',
|
|
15
|
+
defaultMessage: 'Create using editor',
|
|
16
|
+
},
|
|
17
|
+
useEditorDesc: {
|
|
18
|
+
id: 'app.containers.EmailWrapper.useEditorDesc',
|
|
19
|
+
defaultMessage: 'Create using in-built template',
|
|
20
|
+
},
|
|
21
|
+
zipUpload: {
|
|
22
|
+
id: 'app.containers.EmailWrapper.zipUpload',
|
|
23
|
+
defaultMessage: 'Upload zip file',
|
|
24
|
+
},
|
|
25
|
+
zipUploadDesc: {
|
|
26
|
+
id: 'app.containers.EmailWrapper.zipUploadDesc',
|
|
27
|
+
defaultMessage: 'Upload compressed file (Zip) containing HTML & images',
|
|
28
|
+
},
|
|
29
|
+
creativeName: {
|
|
30
|
+
id: 'app.containers.EmailWrapper.creativeName',
|
|
31
|
+
defaultMessage: 'Creative name',
|
|
32
|
+
},
|
|
33
|
+
createMode: {
|
|
34
|
+
id: 'app.containers.EmailWrapper.createMode',
|
|
35
|
+
defaultMessage: 'How do you want to create ?',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* EmailWrapper reducer
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { fromJS } from 'immutable';
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_ACTION,
|
|
10
|
+
} from './constants';
|
|
11
|
+
|
|
12
|
+
const initialState = fromJS({});
|
|
13
|
+
|
|
14
|
+
function emailWrapperReducer(state = initialState, action) {
|
|
15
|
+
switch (action.type) {
|
|
16
|
+
case DEFAULT_ACTION:
|
|
17
|
+
return state;
|
|
18
|
+
default:
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default emailWrapperReducer;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// import { take, call, put, select } from 'redux-saga/effects';
|
|
2
|
+
|
|
3
|
+
// Individual exports for testing
|
|
4
|
+
export function* defaultSaga() {
|
|
5
|
+
// See example in containers/HomePage/sagas.js
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// All sagas to be loaded
|
|
9
|
+
export default [
|
|
10
|
+
defaultSaga,
|
|
11
|
+
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Direct selector to the emailWrapper state domain
|
|
5
|
+
*/
|
|
6
|
+
const selectEmailWrapperDomain = () => (state) => state.get('emailWrapper');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Other specific selectors
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Default selector used by EmailWrapper
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const makeSelectEmailWrapper = () => createSelector(
|
|
18
|
+
selectEmailWrapperDomain(),
|
|
19
|
+
(substate) => substate.toJS()
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export default makeSelectEmailWrapper;
|
|
23
|
+
export {
|
|
24
|
+
selectEmailWrapperDomain,
|
|
25
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
defaultAction,
|
|
4
|
+
} from '../actions';
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_ACTION,
|
|
7
|
+
} from '../constants';
|
|
8
|
+
|
|
9
|
+
describe('EmailWrapper actions', () => {
|
|
10
|
+
describe('Default Action', () => {
|
|
11
|
+
it('has a type of DEFAULT_ACTION', () => {
|
|
12
|
+
const expected = {
|
|
13
|
+
type: DEFAULT_ACTION,
|
|
14
|
+
};
|
|
15
|
+
expect(defaultAction()).toEqual(expected);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test sagas
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* eslint-disable redux-saga/yield-effects */
|
|
6
|
+
// import { take, call, put, select } from 'redux-saga/effects';
|
|
7
|
+
// import { defaultSaga } from '../sagas';
|
|
8
|
+
|
|
9
|
+
// const generator = defaultSaga();
|
|
10
|
+
|
|
11
|
+
describe('defaultSaga Saga', () => {
|
|
12
|
+
it('Expect to have unit tests specified', () => {
|
|
13
|
+
expect(true).toEqual(false);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// import { fromJS } from 'immutable';
|
|
2
|
+
// import { makeSelectEmailWrapperDomain } from '../selectors';
|
|
3
|
+
|
|
4
|
+
// const selector = makeSelectEmailWrapperDomain();
|
|
5
|
+
|
|
6
|
+
describe('makeSelectEmailWrapperDomain', () => {
|
|
7
|
+
it('Expect to have unit tests specified', () => {
|
|
8
|
+
expect(true).toEqual(false);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -254,6 +254,7 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
254
254
|
value: result,
|
|
255
255
|
postAction: value || 'next',
|
|
256
256
|
validity: this.state.isFormValid,
|
|
257
|
+
type: 'SMS',
|
|
257
258
|
};
|
|
258
259
|
this.setState({checkValidation: true});
|
|
259
260
|
console.log('posting final result internal', response);
|
|
@@ -184,7 +184,6 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
184
184
|
} else if (nextProps.route.name.toLowerCase() === 'line') {
|
|
185
185
|
channel = 'Line';
|
|
186
186
|
}
|
|
187
|
-
//
|
|
188
187
|
this.setState({ channel }, () => {
|
|
189
188
|
if (this.state.channel.toLowerCase() === 'line' || this.state.channel.toLowerCase() === 'sms' || this.state.channel.toLowerCase() === 'email' || this.state.channel.toLowerCase() === 'ebill' || (this.state.channel.toLowerCase() === 'wechat' && !_.isEmpty(nextProps.Templates.selectedWeChatAccount))) {
|
|
190
189
|
if (this.state.channel.toLowerCase() === 'wechat' && !_.isEmpty(nextProps.Templates.selectedWeChatAccount)) {
|
|
@@ -349,7 +348,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
|
|
|
349
348
|
// this.setState({defaultAccount: false});
|
|
350
349
|
}
|
|
351
350
|
|
|
352
|
-
onAccountSelect(value
|
|
351
|
+
onAccountSelect(value) {
|
|
353
352
|
this.setState({selectedAccount: value}, () => {
|
|
354
353
|
const params = {
|
|
355
354
|
name: this.state.searchText,
|
|
@@ -35,6 +35,26 @@ const selectTemplateContent = () => createSelector(
|
|
|
35
35
|
}
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
+
const selectEmailLayout = () => createSelector(makeSelectTemplates(), (templates) => {
|
|
39
|
+
const {selectedEmailLayout, sendingFile} = templates;
|
|
40
|
+
if (!sendingFile) {
|
|
41
|
+
return selectedEmailLayout;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const selectCmsTemplates = () => createSelector(makeSelectTemplates(), (templates) => {
|
|
47
|
+
const {getCmsTemplatesInProgress, cmsTemplates} = templates;
|
|
48
|
+
if (!getCmsTemplatesInProgress) {
|
|
49
|
+
return cmsTemplates;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const selectEdmEditor = () => createSelector(makeSelectTemplates(), (templates) => {
|
|
55
|
+
const {edmTemplate} = templates;
|
|
56
|
+
return edmTemplate || null;
|
|
57
|
+
});
|
|
38
58
|
export {
|
|
39
|
-
makeSelectTemplates, makeSelectTemplatesResponse, selectTemplateContent,
|
|
59
|
+
makeSelectTemplates, makeSelectTemplatesResponse, selectTemplateContent, selectEmailLayout, selectCmsTemplates, selectEdmEditor,
|
|
40
60
|
};
|