@capillarytech/creatives-library 7.14.7 → 7.14.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/assets/pdfIcon.svg +9 -0
- package/package.json +1 -1
- package/v2Components/CapDocumentUpload/index.js +209 -0
- package/v2Components/CapDocumentUpload/index.scss +63 -0
- package/v2Components/CapDocumentUpload/messages.js +38 -0
- package/v2Components/CapDocumentUpload/tests/index.test.js +60 -0
- package/v2Components/CapVideoUpload/constants.js +1 -0
- package/v2Components/CapVideoUpload/index.js +68 -37
- package/v2Components/CapVideoUpload/index.scss +10 -0
- package/v2Components/CapVideoUpload/messages.js +11 -3
- package/v2Components/CapVideoUpload/tests/index.test.js +59 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +6 -0
- package/v2Components/TemplatePreview/index.js +12 -0
- package/v2Containers/CreativesContainer/index.js +40 -7
- package/v2Containers/Facebook/Advertisement/index.js +1 -1
- package/v2Containers/Templates/_templates.scss +16 -0
- package/v2Containers/Templates/index.js +2 -1
- package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +9 -0
- package/v2Containers/Whatsapp/constants.js +5 -0
- package/v2Containers/Whatsapp/index.js +127 -6
- package/v2Containers/Whatsapp/index.scss +17 -0
- package/v2Containers/Whatsapp/styles.scss +38 -0
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +64 -140
- package/v2Containers/Whatsapp/tests/utils.test.js +2 -0
- package/v2Containers/Whatsapp/utils.js +47 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
2
|
+
<rect width="32" height="32" fill="url(#pattern0)"/>
|
|
3
|
+
<defs>
|
|
4
|
+
<pattern id="pattern0" patternContentUnits="objectBoundingBox" width="1" height="1">
|
|
5
|
+
<use xlink:href="#image0_21_60903" transform="scale(0.0078125)"/>
|
|
6
|
+
</pattern>
|
|
7
|
+
<image id="image0_21_60903" width="128" height="128" xlink:href="data:image/png;base64,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"/>
|
|
8
|
+
</defs>
|
|
9
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import React, { useState, useEffect, useCallback } from 'react';
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import LabelHOC from '@capillarytech/cap-ui-library/assets/HOCs/ComponentWithLabelHOC';
|
|
5
|
+
import {
|
|
6
|
+
CapUploader,
|
|
7
|
+
CapHeading,
|
|
8
|
+
CapButton,
|
|
9
|
+
} from '@capillarytech/cap-ui-library';
|
|
10
|
+
import { injectIntl, FormattedMessage, intlShape} from 'react-intl';
|
|
11
|
+
import { isEmpty, get } from 'lodash';
|
|
12
|
+
import './index.scss';
|
|
13
|
+
import { WHATSAPP } from "../../v2Containers/CreativesContainer/constants";
|
|
14
|
+
import messages from './messages';
|
|
15
|
+
|
|
16
|
+
function CapDocumentUpload(props) {
|
|
17
|
+
const {
|
|
18
|
+
intl,
|
|
19
|
+
allowedExtensionsRegex,
|
|
20
|
+
documentSize,
|
|
21
|
+
uploadAsset,
|
|
22
|
+
supportedExtensions,
|
|
23
|
+
style,
|
|
24
|
+
documentSrc,
|
|
25
|
+
updateDocumentSrc,
|
|
26
|
+
updateOnReUpload,
|
|
27
|
+
index,
|
|
28
|
+
className,
|
|
29
|
+
documentData,
|
|
30
|
+
channel,
|
|
31
|
+
channelSpecificStyle,
|
|
32
|
+
whatsappDocParams,
|
|
33
|
+
setWhatsappDocParams,
|
|
34
|
+
docPreview,
|
|
35
|
+
} = props;
|
|
36
|
+
const {
|
|
37
|
+
formatMessage,
|
|
38
|
+
} = intl || {};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const docDataObj = documentData[`uploadedAssetData${index}`];
|
|
43
|
+
if (!isEmpty(docDataObj)) {
|
|
44
|
+
const { secure_file_path = '', karixFileHandle = '', name = '', file_size = '' } = get(docDataObj, 'metaInfo', {});
|
|
45
|
+
setWhatsappDocParams({
|
|
46
|
+
...whatsappDocParams,
|
|
47
|
+
whatsappDocName: name,
|
|
48
|
+
whatsappDocSize: file_size,
|
|
49
|
+
whatsappDocPages: 2,
|
|
50
|
+
whatsappDocImg: 'https://play-lh.googleusercontent.com/BkRfMfIRPR9hUnmIYGDgHHKjow-g18-ouP6B2ko__VnyUHSi1spcc78UtZ4sVUtBH4g',
|
|
51
|
+
});
|
|
52
|
+
updateDocumentSrc(secure_file_path, karixFileHandle);
|
|
53
|
+
}
|
|
54
|
+
}, [documentData[`uploadedAssetData${index}`]]);
|
|
55
|
+
|
|
56
|
+
const [isDocError, updateDocErrorMessage] = useState(false);
|
|
57
|
+
|
|
58
|
+
const {CapHeadingSpan} = CapHeading;
|
|
59
|
+
|
|
60
|
+
const DocComponent = useCallback(
|
|
61
|
+
() => (
|
|
62
|
+
<div className={`upload uploaded-container ${props.ifError ? 'error' : ''}`}>
|
|
63
|
+
{docPreview}
|
|
64
|
+
</div>
|
|
65
|
+
),
|
|
66
|
+
[documentSrc],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const WithLabel = LabelHOC(DocComponent);
|
|
70
|
+
|
|
71
|
+
const uploadDocuments = useCallback((e, {files}) => {
|
|
72
|
+
if (e) {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
}
|
|
75
|
+
const _URL = window.URL || window.webkitURL;
|
|
76
|
+
let incorrectFile = false;
|
|
77
|
+
const file = files[0];
|
|
78
|
+
if (!allowedExtensionsRegex.test(file.name)) {
|
|
79
|
+
incorrectFile = true;
|
|
80
|
+
}
|
|
81
|
+
const doc = new FileReader();
|
|
82
|
+
doc.src = _URL.createObjectURL(file);
|
|
83
|
+
const fileParams = {
|
|
84
|
+
error: false, // checking error based on file size
|
|
85
|
+
};
|
|
86
|
+
submitAction({file, type: 'document', fileParams}, incorrectFile);
|
|
87
|
+
if (e) {
|
|
88
|
+
const event = e;
|
|
89
|
+
event.target.value = null;
|
|
90
|
+
}
|
|
91
|
+
}, []);
|
|
92
|
+
|
|
93
|
+
const submitAction = useCallback((data, incorrectFile) => {
|
|
94
|
+
const {
|
|
95
|
+
file,
|
|
96
|
+
fileParams,
|
|
97
|
+
} = data || {};
|
|
98
|
+
const { size } = file || {};
|
|
99
|
+
const { error } = fileParams || {};
|
|
100
|
+
if (incorrectFile || size > documentSize || error) {
|
|
101
|
+
updateDocErrorMessage(formatMessage(messages.docErrorDesc));
|
|
102
|
+
} else {
|
|
103
|
+
updateDocErrorMessage('');
|
|
104
|
+
uploadAsset(
|
|
105
|
+
data.file,
|
|
106
|
+
data.type,
|
|
107
|
+
data.fileParams,
|
|
108
|
+
index,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}, [isDocError]);
|
|
112
|
+
|
|
113
|
+
const capUploaderCustomRequest = useCallback((uploadData) => {
|
|
114
|
+
uploadDocuments(undefined, {files: [uploadData.file]});
|
|
115
|
+
}, []);
|
|
116
|
+
|
|
117
|
+
const onReUpload = useCallback(() => {
|
|
118
|
+
updateDocumentSrc('');
|
|
119
|
+
updateOnReUpload();
|
|
120
|
+
}, []);
|
|
121
|
+
|
|
122
|
+
const getDocumentSection = useCallback(() => {
|
|
123
|
+
if (documentSrc === "") {
|
|
124
|
+
return (
|
|
125
|
+
<>
|
|
126
|
+
<CapUploader.CapDragger
|
|
127
|
+
customRequest={capUploaderCustomRequest}
|
|
128
|
+
className="form-builder-dragger whatsapp-background"
|
|
129
|
+
showUploadList={!isDocError}
|
|
130
|
+
>
|
|
131
|
+
<CapHeading className="dragger-title" type="h7">
|
|
132
|
+
<FormattedMessage {...messages.dragAndDrop} />
|
|
133
|
+
</CapHeading>
|
|
134
|
+
<CapHeading className="dragger-or" type="label6">
|
|
135
|
+
<FormattedMessage {...messages.or} />
|
|
136
|
+
</CapHeading>
|
|
137
|
+
<CapButton className="dragger-button upload-doc" type="secondary">
|
|
138
|
+
<FormattedMessage {...messages.uploadComputer} />
|
|
139
|
+
</CapButton>
|
|
140
|
+
</CapUploader.CapDragger>
|
|
141
|
+
</>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return (
|
|
145
|
+
<CapButton
|
|
146
|
+
className="dragger-button re-upload"
|
|
147
|
+
type="flat"
|
|
148
|
+
onClick={onReUpload}
|
|
149
|
+
style={channelSpecificStyle ? { marginTop: '-16px'} : {}}
|
|
150
|
+
>
|
|
151
|
+
<FormattedMessage {...messages.docReUpload} />
|
|
152
|
+
</CapButton>
|
|
153
|
+
);
|
|
154
|
+
}, [isDocError, documentSrc]);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<div style={style} className="cap-custom-document-upload">
|
|
158
|
+
<WithLabel
|
|
159
|
+
key={`with-label`}
|
|
160
|
+
errorMessage={isDocError} ifError={!!isDocError}
|
|
161
|
+
/>
|
|
162
|
+
<form encType="multipart/form-data" id={`form`} className={className}>
|
|
163
|
+
<input
|
|
164
|
+
key={`docFile`}
|
|
165
|
+
style={{ display: 'none' }}
|
|
166
|
+
id="fileName"
|
|
167
|
+
type="file"
|
|
168
|
+
onChange={(e) => uploadDocuments(e, { files: e.target.files })}
|
|
169
|
+
accept={supportedExtensions || ".pdf"}
|
|
170
|
+
/>
|
|
171
|
+
{getDocumentSection()}
|
|
172
|
+
</form>
|
|
173
|
+
<div className="image-info-wrapper">
|
|
174
|
+
{channel === WHATSAPP && (
|
|
175
|
+
<>
|
|
176
|
+
<CapHeadingSpan type="label2">
|
|
177
|
+
<FormattedMessage {...messages.whatsappDocSize} />
|
|
178
|
+
</CapHeadingSpan>
|
|
179
|
+
</>
|
|
180
|
+
)}
|
|
181
|
+
<CapHeadingSpan type="label2" className="image-format">
|
|
182
|
+
<FormattedMessage {...messages.format} />
|
|
183
|
+
</CapHeadingSpan>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
CapDocumentUpload.propTypes = {
|
|
190
|
+
allowedExtensionsRegex: PropTypes.any,
|
|
191
|
+
documentSize: PropTypes.number,
|
|
192
|
+
uploadAsset: PropTypes.func,
|
|
193
|
+
supportedExtensions: PropTypes.any,
|
|
194
|
+
style: PropTypes.any,
|
|
195
|
+
documentSrc: PropTypes.string,
|
|
196
|
+
updateDocumentSrc: PropTypes.func,
|
|
197
|
+
intl: intlShape,
|
|
198
|
+
className: PropTypes.string,
|
|
199
|
+
updateOnReUpload: PropTypes.func,
|
|
200
|
+
documentData: PropTypes.object,
|
|
201
|
+
index: PropTypes.number,
|
|
202
|
+
channel: PropTypes.string,
|
|
203
|
+
whatsappDocParams: PropTypes.string,
|
|
204
|
+
setWhatsappDocParams: PropTypes.func,
|
|
205
|
+
channelSpecificStyle: PropTypes.bool,
|
|
206
|
+
docPreview: PropTypes.any,
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export default injectIntl(CapDocumentUpload);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
@import '~@capillarytech/cap-ui-library/styles/_variables.scss';
|
|
2
|
+
|
|
3
|
+
$classPrefix: cap-custom-document-upload;
|
|
4
|
+
|
|
5
|
+
.#{$classPrefix} {
|
|
6
|
+
.upload-doc {
|
|
7
|
+
margin-right: $CAP_SPACE_08;
|
|
8
|
+
}
|
|
9
|
+
.image-info-wrapper {
|
|
10
|
+
display: flex;
|
|
11
|
+
justify-content: space-between;
|
|
12
|
+
margin-top: 8px;
|
|
13
|
+
}
|
|
14
|
+
.whatsapp-background div {
|
|
15
|
+
background: #FAFBFC;
|
|
16
|
+
.ant-upload-list-item .ant-upload-list-item-progress {
|
|
17
|
+
display: none;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
.uploaded-container {
|
|
21
|
+
width: 162px;
|
|
22
|
+
margin: auto;
|
|
23
|
+
}
|
|
24
|
+
.pdf-img-box {
|
|
25
|
+
width: 162px;
|
|
26
|
+
height: 80px;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
}
|
|
29
|
+
.pdf-preview-img {
|
|
30
|
+
width: 162px;
|
|
31
|
+
}
|
|
32
|
+
.pdf-label {
|
|
33
|
+
width: 162px;
|
|
34
|
+
height: 44px;
|
|
35
|
+
background-color: #F4F5F7;
|
|
36
|
+
display: flex;
|
|
37
|
+
.cap-image-v2 {
|
|
38
|
+
margin: 6px 4px;
|
|
39
|
+
width: 32px;
|
|
40
|
+
height: 32px;
|
|
41
|
+
}
|
|
42
|
+
.pdf-info {
|
|
43
|
+
margin: 8px 4px;
|
|
44
|
+
max-width: 114px;
|
|
45
|
+
.pdf-info-sec {
|
|
46
|
+
color: #5f6d85;
|
|
47
|
+
font-size: 8px;
|
|
48
|
+
font-weight: 400;
|
|
49
|
+
line-height: 12px;
|
|
50
|
+
}
|
|
51
|
+
.pdf-name-div {
|
|
52
|
+
display: flex;
|
|
53
|
+
.pdf-name{
|
|
54
|
+
max-width: 112px;
|
|
55
|
+
text-overflow: ellipsis;
|
|
56
|
+
overflow: hidden;
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl';
|
|
2
|
+
const scope = `creatives.componentsV2.CapDocumentUpload`;
|
|
3
|
+
|
|
4
|
+
export default defineMessages({
|
|
5
|
+
whatsappDocSize: {
|
|
6
|
+
id: `${scope}.whatsappDocSize`,
|
|
7
|
+
defaultMessage: 'Size upto: 16MB',
|
|
8
|
+
},
|
|
9
|
+
uploadComputer: {
|
|
10
|
+
id: `${scope}.uploadComputer`,
|
|
11
|
+
defaultMessage: 'Select from computer',
|
|
12
|
+
},
|
|
13
|
+
or: {
|
|
14
|
+
id: `${scope}.or`,
|
|
15
|
+
defaultMessage: 'OR',
|
|
16
|
+
},
|
|
17
|
+
dragAndDrop: {
|
|
18
|
+
id: `${scope}.dragAndDrop`,
|
|
19
|
+
defaultMessage: 'Drag and drop document here',
|
|
20
|
+
},
|
|
21
|
+
docReUpload: {
|
|
22
|
+
id: `${scope}.docReUpload`,
|
|
23
|
+
defaultMessage: 'Reupload',
|
|
24
|
+
},
|
|
25
|
+
imageDimenstionDescription: {
|
|
26
|
+
id: `${scope}.imageDimenstionDescription`,
|
|
27
|
+
defaultMessage: 'Dimensions upto: {width}px x {height}px',
|
|
28
|
+
},
|
|
29
|
+
format: {
|
|
30
|
+
id: `${scope}.format`,
|
|
31
|
+
defaultMessage: 'Format: PDF',
|
|
32
|
+
},
|
|
33
|
+
docErrorDesc: {
|
|
34
|
+
id: `${scope}.docErrorDesc`,
|
|
35
|
+
defaultMessage:
|
|
36
|
+
'Please upload the document with allowed file extension, size, dimension and aspect ratio',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { injectIntl } from 'react-intl';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import {
|
|
5
|
+
render,
|
|
6
|
+
screen,
|
|
7
|
+
fireEvent,
|
|
8
|
+
waitFor,
|
|
9
|
+
} from '../../../utils/test-utils';
|
|
10
|
+
import CapDocumentUpload from '../index';
|
|
11
|
+
|
|
12
|
+
const ComponentToRender = injectIntl(CapDocumentUpload);
|
|
13
|
+
const renderComponent = (props) => render(
|
|
14
|
+
<ComponentToRender {...props} />
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
describe("test for document upload", () => {
|
|
18
|
+
const props = {
|
|
19
|
+
allowedExtensionsRegex: (/\.(pdf)$/i),
|
|
20
|
+
documentSize: 16000000,
|
|
21
|
+
uploadAsset: jest.fn(),
|
|
22
|
+
documentSrc: '',
|
|
23
|
+
updateDocumentSrc: jest.fn(),
|
|
24
|
+
updateOnReUpload: jest.fn(),
|
|
25
|
+
index: 0,
|
|
26
|
+
className: 'cap-custom-document-upload',
|
|
27
|
+
documentData: {},
|
|
28
|
+
channel: 'WHATSAPP',
|
|
29
|
+
channelSpecificStyle: null,
|
|
30
|
+
whatsappDocParams: {},
|
|
31
|
+
setWhatsappDocParams: jest.fn(),
|
|
32
|
+
docPreview: <></>,
|
|
33
|
+
};
|
|
34
|
+
it("test for cap document upload", () => {
|
|
35
|
+
renderComponent(props);
|
|
36
|
+
expect(true).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it("test for cap document upload 1", () => {
|
|
39
|
+
const props1 = {
|
|
40
|
+
...props,
|
|
41
|
+
documentData: {
|
|
42
|
+
uploadedAssetData0: {
|
|
43
|
+
file_size: 134532,
|
|
44
|
+
name: 'sample.pdf',
|
|
45
|
+
secure_file_path: "https://www.africau.edu/images/default/sample.pdf",
|
|
46
|
+
karixFileHandle: 'abcd',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
documentSrc: "https://www.africau.edu/images/default/sample.pdf",
|
|
50
|
+
whatsappDocParams: {
|
|
51
|
+
whatsappDocName: 'sample.pdf',
|
|
52
|
+
whatsappDocSize: 134532,
|
|
53
|
+
whatsappDocPages: 2,
|
|
54
|
+
whatsappDocImg: 'https://play-lh.googleusercontent.com/BkRfMfIRPR9hUnmIYGDgHHKjow-g18-ouP6B2ko__VnyUHSi1spcc78UtZ4sVUtBH4g',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
renderComponent(props1);
|
|
58
|
+
expect(true).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const WHATSAPP = 'WHATSAPP';
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
CapNotification,
|
|
21
21
|
} from '@capillarytech/cap-ui-library';
|
|
22
22
|
import {bytes2Size} from '../../utils/common';
|
|
23
|
+
import { WHATSAPP } from './constants';
|
|
23
24
|
import './index.scss';
|
|
24
25
|
|
|
25
26
|
function CapVideoUpload(props) {
|
|
@@ -34,6 +35,8 @@ function CapVideoUpload(props) {
|
|
|
34
35
|
onVideoUploadUpdateAssestList,
|
|
35
36
|
index,
|
|
36
37
|
videoData,
|
|
38
|
+
className,
|
|
39
|
+
channel,
|
|
37
40
|
} = props;
|
|
38
41
|
const [isVideoError, updateVideoErrorMessage] = useState(false);
|
|
39
42
|
const [isVideo, updateVideoStatus] = useState(false);
|
|
@@ -80,11 +83,12 @@ function CapVideoUpload(props) {
|
|
|
80
83
|
}, []);
|
|
81
84
|
|
|
82
85
|
useEffect(() => {
|
|
83
|
-
if (videoData[`
|
|
84
|
-
const metaVideoSrc = get(videoData, `
|
|
85
|
-
const previewImgUrl = get(videoData, `
|
|
86
|
-
const metaVideoName = get(videoData, `
|
|
87
|
-
const metaVideoId = get(videoData, `
|
|
86
|
+
if (videoData[`uploadedAssetData${index}`] && Object.keys(videoData[`uploadedAssetData${index}`]).length) {
|
|
87
|
+
const metaVideoSrc = get(videoData, `uploadedAssetData${index}.metaInfo.secure_file_path`, '');
|
|
88
|
+
const previewImgUrl = get(videoData, `uploadedAssetData${index}.metaInfo.video_file_path_preview`, '');
|
|
89
|
+
const metaVideoName = get(videoData, `uploadedAssetData${index}.metaInfo.name`, '');
|
|
90
|
+
const metaVideoId = get(videoData, `uploadedAssetData${index}.videoIdResponse.fbVideo.id`, '');
|
|
91
|
+
const karixFileHandle = get(videoData, `uploadedAssetData${index}.metaInfo.karixFileHandle`, '');
|
|
88
92
|
|
|
89
93
|
if (metaVideoSrc && videoSrc === "") {
|
|
90
94
|
onVideoUploadUpdateAssestList(index, {
|
|
@@ -92,11 +96,12 @@ function CapVideoUpload(props) {
|
|
|
92
96
|
videoSrc: metaVideoSrc,
|
|
93
97
|
videoName: metaVideoName,
|
|
94
98
|
videoId: metaVideoId,
|
|
99
|
+
fileHandle: karixFileHandle,
|
|
95
100
|
},
|
|
96
101
|
);
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
|
-
}, [videoData[`
|
|
104
|
+
}, [videoData[`uploadedAssetData${index}`]]);
|
|
100
105
|
|
|
101
106
|
useEffect(() => {
|
|
102
107
|
if (videoData[`assetUploadingVideo_${index}`] && videoData[`assetUploading`] !== false) {
|
|
@@ -127,14 +132,18 @@ function CapVideoUpload(props) {
|
|
|
127
132
|
type,
|
|
128
133
|
} = data;
|
|
129
134
|
if (incorrectFile || size > videoSize) {
|
|
130
|
-
|
|
135
|
+
if (channel === WHATSAPP) {
|
|
136
|
+
updateVideoErrorMessage(formatMessage(messages.whatsappErrorMessage));
|
|
137
|
+
} else {
|
|
138
|
+
updateVideoErrorMessage(formatMessage(messages.videoIncorrectSize));
|
|
139
|
+
}
|
|
131
140
|
} else {
|
|
132
141
|
updateVideoErrorMessage('');
|
|
133
142
|
uploadAsset(
|
|
134
143
|
file,
|
|
135
144
|
type,
|
|
136
145
|
fileParams,
|
|
137
|
-
|
|
146
|
+
index,
|
|
138
147
|
);
|
|
139
148
|
}
|
|
140
149
|
}, [isVideoError]);
|
|
@@ -157,16 +166,21 @@ function CapVideoUpload(props) {
|
|
|
157
166
|
if (!e.target.paused && isPlaying) {
|
|
158
167
|
e.target.pause();
|
|
159
168
|
}
|
|
160
|
-
}, []);
|
|
169
|
+
}, [isPlaying]);
|
|
161
170
|
|
|
162
171
|
const getVideoSection = () => {
|
|
163
172
|
if (!isVideo) {
|
|
164
173
|
return (
|
|
165
174
|
(
|
|
166
175
|
<>
|
|
176
|
+
{channel === WHATSAPP &&
|
|
177
|
+
<CapError type="error" className="upload-video-error">
|
|
178
|
+
{isVideoError}
|
|
179
|
+
</CapError>
|
|
180
|
+
}
|
|
167
181
|
<CapUploader.CapDragger
|
|
168
182
|
customRequest={(data) => capUploaderCustomVideoRequest(data)}
|
|
169
|
-
className="form-builder-dragger"
|
|
183
|
+
className="form-builder-dragger whatsapp-background"
|
|
170
184
|
>
|
|
171
185
|
<CapHeading className="dragger-title" type="h7">
|
|
172
186
|
<FormattedMessage {...messages.dragAndDrop} />
|
|
@@ -175,12 +189,14 @@ function CapVideoUpload(props) {
|
|
|
175
189
|
<FormattedMessage {...messages.or} />
|
|
176
190
|
</CapHeading>
|
|
177
191
|
<CapButton className="dragger-button upload-video" type="secondary">
|
|
178
|
-
<FormattedMessage {...messages.
|
|
192
|
+
<FormattedMessage {...messages.selectFromComputer} />
|
|
179
193
|
</CapButton>
|
|
180
194
|
</CapUploader.CapDragger>
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
195
|
+
{channel !== WHATSAPP &&
|
|
196
|
+
<CapError type="error" className="upload-video-error">
|
|
197
|
+
{isVideoError}
|
|
198
|
+
</CapError>
|
|
199
|
+
}
|
|
184
200
|
</>
|
|
185
201
|
)
|
|
186
202
|
);
|
|
@@ -197,6 +213,7 @@ function CapVideoUpload(props) {
|
|
|
197
213
|
videoSrc: "",
|
|
198
214
|
videoDuration: "",
|
|
199
215
|
videoId: "",
|
|
216
|
+
fileHandle: "",
|
|
200
217
|
}
|
|
201
218
|
);
|
|
202
219
|
};
|
|
@@ -233,9 +250,9 @@ function CapVideoUpload(props) {
|
|
|
233
250
|
<FormattedMessage {...messages.imageReUpload} />
|
|
234
251
|
</CapButton>
|
|
235
252
|
</div>
|
|
236
|
-
<div style={{ display: 'flex' }}>
|
|
253
|
+
<div style={{ display: 'flex', justifyContent: 'center', margin: '4px' }}>
|
|
237
254
|
<video
|
|
238
|
-
width="230"
|
|
255
|
+
width={channel === WHATSAPP ? "300" : "230"}
|
|
239
256
|
poster={previewUrl}
|
|
240
257
|
className="line-image-src"
|
|
241
258
|
key={`${index}-video`}
|
|
@@ -248,22 +265,24 @@ function CapVideoUpload(props) {
|
|
|
248
265
|
>
|
|
249
266
|
<source src={videoSrc} type="video/mp4" />
|
|
250
267
|
</video>
|
|
251
|
-
|
|
252
|
-
<
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
268
|
+
{ channel !== WHATSAPP &&
|
|
269
|
+
<div className="video-info">
|
|
270
|
+
<CapHeading type="h6">
|
|
271
|
+
{videoName}
|
|
272
|
+
</CapHeading>
|
|
273
|
+
<CapHeading type="h6">
|
|
274
|
+
{videoDuration}
|
|
275
|
+
</CapHeading>
|
|
276
|
+
</div>
|
|
277
|
+
}
|
|
259
278
|
</div>
|
|
260
279
|
</Fragment>
|
|
261
280
|
);
|
|
262
281
|
};
|
|
263
282
|
return (
|
|
264
283
|
<CapSpin spinning={isSpinning}>
|
|
265
|
-
<div style={style} className=
|
|
266
|
-
<form encType="multipart/form-data" id={`form`} className="video-form">
|
|
284
|
+
<div style={style} className={className}>
|
|
285
|
+
<form encType="multipart/form-data" id={`form`} className={channel !== WHATSAPP && "video-form"}>
|
|
267
286
|
<input
|
|
268
287
|
key={`videoFile`}
|
|
269
288
|
style={{ display: 'none' }}
|
|
@@ -279,18 +298,28 @@ function CapVideoUpload(props) {
|
|
|
279
298
|
onClose={() => updateTemplateDrawerRequirement(false)}
|
|
280
299
|
/>
|
|
281
300
|
</form>
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
<
|
|
301
|
+
{channel !== WHATSAPP ?
|
|
302
|
+
<>
|
|
303
|
+
<CapHeading.CapHeadingSpan type="h6" className="video-description">
|
|
304
|
+
<FormattedMessage {...messages.videoRatioDescription} />
|
|
305
|
+
</CapHeading.CapHeadingSpan>
|
|
306
|
+
{' '}
|
|
307
|
+
<CapHeading.CapHeadingSpan type="h6" className="video-description file-format">
|
|
308
|
+
<FormattedMessage {...messages.fileFormat} />
|
|
289
309
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
310
|
+
</CapHeading.CapHeadingSpan>
|
|
311
|
+
<CapHeading.CapHeadingSpan type="h6" className="video-description video-details">
|
|
312
|
+
<FormattedMessage {...messages.videoSizeDescription} values={{size: bytes2Size(videoSize)}} />
|
|
313
|
+
</CapHeading.CapHeadingSpan>
|
|
314
|
+
</> :
|
|
315
|
+
<>
|
|
316
|
+
<CapHeading.CapHeadingSpan type="label2" className="">
|
|
317
|
+
<FormattedMessage {...messages.videoSizeDescription} values={{size: bytes2Size(videoSize)}} />
|
|
318
|
+
</CapHeading.CapHeadingSpan>
|
|
319
|
+
<CapHeading.CapHeadingSpan type="label2" className="whatsapp-format">
|
|
320
|
+
<FormattedMessage {...messages.whatsappFileFormat} />
|
|
321
|
+
</CapHeading.CapHeadingSpan>
|
|
322
|
+
</>}
|
|
294
323
|
</div>
|
|
295
324
|
</CapSpin>
|
|
296
325
|
);
|
|
@@ -307,6 +336,8 @@ CapVideoUpload.propTypes = {
|
|
|
307
336
|
onVideoUploadUpdateAssestList: PropTypes.func,
|
|
308
337
|
index: PropTypes.number,
|
|
309
338
|
videoData: PropTypes.object,
|
|
339
|
+
channel: PropTypes.string,
|
|
340
|
+
className: PropTypes.string,
|
|
310
341
|
};
|
|
311
342
|
|
|
312
343
|
export default injectIntl(CapVideoUpload);
|
|
@@ -29,4 +29,14 @@ $classPrefix: cap-custom-video-upload;
|
|
|
29
29
|
.file-format{
|
|
30
30
|
padding-left:9%;
|
|
31
31
|
}
|
|
32
|
+
.whatsapp-background div {
|
|
33
|
+
background: #FAFBFC;
|
|
34
|
+
.ant-upload-list-item .ant-upload-list-item-progress {
|
|
35
|
+
display: none;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.whatsapp-format {
|
|
41
|
+
float: right;
|
|
32
42
|
}
|
|
@@ -23,9 +23,9 @@ export default defineMessages({
|
|
|
23
23
|
id: `${scope}.textMessageORLabel`,
|
|
24
24
|
defaultMessage: 'OR',
|
|
25
25
|
},
|
|
26
|
-
|
|
27
|
-
id: `${scope}.
|
|
28
|
-
defaultMessage: '
|
|
26
|
+
selectFromComputer: {
|
|
27
|
+
id: `${scope}.selectFromComputer`,
|
|
28
|
+
defaultMessage: 'Select from computer',
|
|
29
29
|
},
|
|
30
30
|
or: {
|
|
31
31
|
id: `${scope}.or`,
|
|
@@ -39,6 +39,10 @@ export default defineMessages({
|
|
|
39
39
|
id: `${scope}.videoIncorrectSize`,
|
|
40
40
|
defaultMessage: 'This file format/size is not supported.',
|
|
41
41
|
},
|
|
42
|
+
whatsappErrorMessage: {
|
|
43
|
+
id: `${scope}.whatsappErrorMessage`,
|
|
44
|
+
defaultMessage: 'Please upload the document with allowed file extension and size',
|
|
45
|
+
},
|
|
42
46
|
videoRatioDescription: {
|
|
43
47
|
id: `${scope}.videoRatioDescription`,
|
|
44
48
|
defaultMessage: 'Video ratio: 9:16 to 16:9',
|
|
@@ -55,4 +59,8 @@ export default defineMessages({
|
|
|
55
59
|
id: `${scope}.fileFormat`,
|
|
56
60
|
defaultMessage: 'Format: MP4',
|
|
57
61
|
},
|
|
62
|
+
whatsappFileFormat: {
|
|
63
|
+
id: `${scope}.whatsappFileFormat`,
|
|
64
|
+
defaultMessage: 'Format: MP4 and 3gpp (H.264 video codec and AAC audio codec)',
|
|
65
|
+
},
|
|
58
66
|
});
|