@plusscommunities/pluss-core-web 1.0.2 → 1.0.6

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.
Files changed (62) hide show
  1. package/dist/index.cjs.js +7349 -1360
  2. package/dist/index.esm.js +7341 -1358
  3. package/dist/index.umd.js +7346 -1364
  4. package/package.json +5 -3
  5. package/src/actions/AuthActions.js +83 -0
  6. package/src/actions/UsersActions.js +65 -0
  7. package/src/actions/index.js +2 -2
  8. package/src/actions/types.js +9 -9
  9. package/src/analytics.js +73 -0
  10. package/src/apis/analyticsActions.js +49 -0
  11. package/src/apis/authActions.js +58 -0
  12. package/src/apis/fileActions.js +92 -94
  13. package/src/apis/index.js +7 -0
  14. package/src/apis/profileActions.js +133 -0
  15. package/src/apis/stringActions.js +25 -0
  16. package/src/apis/typeActions.js +186 -0
  17. package/src/apis/userActions.js +128 -0
  18. package/src/apis/utilityActions.js +35 -0
  19. package/src/colours.js +16 -16
  20. package/src/components/AnalyticsFilter.js +110 -0
  21. package/src/components/AudienceIncluder.js +174 -0
  22. package/src/components/AudienceSelector.js +549 -0
  23. package/src/components/CheckBox.js +77 -0
  24. package/src/components/DatePicker.js +268 -0
  25. package/src/components/DropdownInput.js +223 -0
  26. package/src/components/FileInput.js +314 -0
  27. package/src/components/ImageInput.js +971 -0
  28. package/src/components/MakerPopup.js +300 -0
  29. package/src/components/OptionsSection.js +64 -0
  30. package/src/components/P60Icon.js +40 -0
  31. package/src/components/ProfilePic.js +35 -0
  32. package/src/components/Reactions.js +77 -0
  33. package/src/components/Tag.js +62 -0
  34. package/src/components/TextFormatPopup.js +54 -0
  35. package/src/components/TimePicker.js +205 -0
  36. package/src/components/UserListing.js +64 -0
  37. package/src/components/index.js +23 -7
  38. package/src/components/svg-icons.json +6 -0
  39. package/src/config.js +10 -0
  40. package/src/helper/HelpDeskWidget.js +52 -0
  41. package/src/helper/api/getUrl.js +15 -0
  42. package/src/helper/api/getUrlParams.js +9 -0
  43. package/src/helper/api/safeReadParams.js +6 -0
  44. package/src/helper/colours.js/getAppColourFromState.js +10 -0
  45. package/src/helper/files/canvasImageUploader.js +159 -0
  46. package/src/helper/files/get1400.js +28 -0
  47. package/src/helper/files/getExtension.js +9 -0
  48. package/src/helper/files/getFileName.js +13 -0
  49. package/src/helper/files/getThumb300.js +32 -0
  50. package/src/helper/files/isVideo.js +8 -0
  51. package/src/{helper.js → helper/helper.js} +19 -130
  52. package/src/helper/index.js +29 -0
  53. package/src/helper/site/getSiteName.js +16 -0
  54. package/src/helper/site/getSiteNameFromRoles.js +12 -0
  55. package/src/helper/storage/readJSONFromStorage.js +9 -0
  56. package/src/helper/storage/setLocalStorage.js +5 -0
  57. package/src/helper/strings/isEmail.js +11 -0
  58. package/src/helper/strings/onlyAlphanumeric.js +8 -0
  59. package/src/helper/strings/randomString.js +10 -0
  60. package/src/helper/strings/toParagraphed.js +17 -0
  61. package/src/index.js +2 -1
  62. package/src/session.js +107 -107
@@ -0,0 +1,52 @@
1
+ import Config from '../config';
2
+
3
+ export const setChatUser = (auth) => {
4
+ if (!window.tidioChatApi || !window.tidioChatApi.setVisitorData) {
5
+ setTimeout(() => {
6
+ setChatUser(auth);
7
+ }, 1000);
8
+ return;
9
+ }
10
+ if (!auth.user) {
11
+ return (
12
+ window.tidioChatApi &&
13
+ window.tidioChatApi.setVisitorData({
14
+ name: undefined,
15
+ email: undefined,
16
+ phone: undefined,
17
+ site: undefined,
18
+ company: Config.env.clientName,
19
+ distinct_id: undefined,
20
+ })
21
+ );
22
+ }
23
+ return (
24
+ window.tidioChatApi &&
25
+ window.tidioChatApi.setVisitorData({
26
+ name: `${auth.user.displayName} - ${Config.env.clientName} ${auth.site}`,
27
+ email: auth.user.email,
28
+ phone: auth.user.phoneNumber,
29
+ site: auth.site,
30
+ userType: auth.auth,
31
+ company: Config.env.clientName,
32
+ distinct_id: auth.user.Id,
33
+ })
34
+ );
35
+ };
36
+
37
+ export const openChat = () => {
38
+ window.tidioChatApi.display(true);
39
+ window.tidioChatApi.open();
40
+ };
41
+
42
+ export const hideChat = () => {
43
+ if (window.tidioChatApi && window.tidioChatApi.display) {
44
+ setTimeout(() => {
45
+ window.tidioChatApi.display(false);
46
+ }, 1000);
47
+ } else {
48
+ setTimeout(() => {
49
+ hideChat();
50
+ }, 1000);
51
+ }
52
+ };
@@ -0,0 +1,15 @@
1
+ import _ from 'lodash';
2
+ import Config from '../../config';
3
+
4
+ const getUrl = (baseAction, action, query) => {
5
+ const { baseAPIUrl, baseStage } = Config.env;
6
+ let queryPart = '';
7
+ if (query) {
8
+ _.keys(query).forEach((key, index) => {
9
+ queryPart += `${index === 0 ? '?' : '&'}${key}=${query[key]}`;
10
+ });
11
+ }
12
+ return `${baseAPIUrl}/${baseAction}-${baseStage}/${action}${queryPart}`;
13
+ };
14
+
15
+ export default getUrl;
@@ -0,0 +1,9 @@
1
+ const getUrlParams = () => {
2
+ var vars = {};
3
+ window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
4
+ vars[key] = value;
5
+ });
6
+ return vars;
7
+ };
8
+
9
+ export default getUrlParams;
@@ -0,0 +1,6 @@
1
+ const safeReadParams = (props, key) => {
2
+ if (props && props.match && props.match.params) return props.match.params[key];
3
+ return null;
4
+ };
5
+
6
+ export default safeReadParams;
@@ -0,0 +1,10 @@
1
+ import { Config } from '../..';
2
+
3
+ const getAppColourFromState = (state) => {
4
+ if (!state || !state.auth || !state.auth.siteBranding || !state.auth.siteBranding.MainBrandingColour) {
5
+ return Config.env.colourBrandingApp;
6
+ }
7
+ return state.auth.siteBranding.MainBrandingColour;
8
+ };
9
+
10
+ export default getAppColourFromState;
@@ -0,0 +1,159 @@
1
+ /**
2
+ * ADAPTED FROM:
3
+ *
4
+ * Resize and rotate images by EXIF orientation on the client side during upload. This uses
5
+ * the HTML Canvas element and HTML5 FileReader.
6
+ *
7
+ * This class requires the Javascript file from https://github.com/jseidelin/exif-js
8
+ *
9
+ * See the GitHub repo for examples: https://github.com/ajgarn/CanvasImageUploader.
10
+ *
11
+ * @class CanvasImageUploader
12
+ * @author ajgarn
13
+ * @see https://github.com/ajgarn/CanvasImageUploader
14
+ */
15
+
16
+ function CanvasImageUploader(options) {
17
+ options = options || {};
18
+ if (typeof options.maxSize === 'undefined') options.maxSize = 1500;
19
+ if (typeof options.jpegQuality === 'undefined') options.jpegQuality = 0.7;
20
+
21
+ var image; // Image object (<img>)
22
+ var imageData; // Image from canvas as byte array
23
+
24
+ /**
25
+ * Converts a base64 string to byte array.
26
+ */
27
+ function base64toBlob(base64Data, contentType, sliceSize) {
28
+ contentType = contentType || '';
29
+ sliceSize = sliceSize || 512;
30
+
31
+ var byteCharacters = atob(base64Data);
32
+ var byteArrays = [];
33
+
34
+ for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
35
+ var slice = byteCharacters.slice(offset, offset + sliceSize);
36
+ var byteNumbers = new Array(slice.length);
37
+ for (var i = 0; i < slice.length; i++) {
38
+ byteNumbers[i] = slice.charCodeAt(i);
39
+ }
40
+ var byteArray = new Uint8Array(byteNumbers);
41
+ byteArrays.push(byteArray);
42
+ }
43
+
44
+ return new Blob(byteArrays, { type: contentType });
45
+ }
46
+
47
+ function calculateSize(image, maxSize) {
48
+ var size = { width: image.width, height: image.height };
49
+ if (image.width > maxSize || image.height > maxSize) {
50
+ var ratio = image.width / image.height;
51
+ if (image.width >= image.height) {
52
+ size.width = maxSize;
53
+ size.height = maxSize / ratio;
54
+ } else {
55
+ size.height = maxSize;
56
+ size.width = maxSize * ratio;
57
+ }
58
+ }
59
+ return size;
60
+ }
61
+
62
+ function setDimensions($canvas, size) {
63
+ $canvas.attr('width', size.width);
64
+ $canvas.attr('height', size.height);
65
+ }
66
+
67
+ function drawOnCanvas(image, $canvas, maxSize) {
68
+ var canvas = $canvas[0];
69
+ var ctx = canvas.getContext('2d');
70
+
71
+ var size = calculateSize(image, maxSize);
72
+ setDimensions($canvas, size);
73
+
74
+ // Clear canvas
75
+ ctx.clearRect(0, 0, $canvas.width(), $canvas.height());
76
+
77
+ ctx.drawImage(
78
+ image,
79
+ 0,
80
+ 0,
81
+ image.width,
82
+ image.height, // Source rectangle
83
+ 0,
84
+ 0,
85
+ size.width,
86
+ size.height,
87
+ ); // Destination rectangle
88
+ }
89
+
90
+ function readImageToCanvasOnLoad(image, $canvas, callback) {
91
+ drawOnCanvas(image, $canvas, options.maxSize);
92
+ if (callback) callback();
93
+ else console.warn('No callback for readImageToCanvas');
94
+ }
95
+
96
+ return {
97
+ /**
98
+ * Run to initialize CanvasImageUploader.
99
+ */
100
+ newImage: function () {
101
+ imageData = null;
102
+ image = new Image();
103
+ },
104
+
105
+ /**
106
+ * Returns the image data if any file has been read.
107
+ * @returns {Blob|null}
108
+ */
109
+ getImageData: function () {
110
+ return imageData;
111
+ },
112
+
113
+ /**
114
+ * Draw an image (<img>) or contents of a canvas to another canvas. The destination
115
+ * canvas is resized properly.
116
+ * @param source The image or source canvas to draw on a new canvas.
117
+ * @param $destination The destination canvas to draw onto.
118
+ * @param maxSize Maximum width or height of the destination canvas.
119
+ */
120
+ copyToCanvas: function (source, $destination, maxSize) {
121
+ var size = calculateSize(source, maxSize);
122
+ setDimensions($destination, size, 1);
123
+ var destCtx = $destination[0].getContext('2d');
124
+ destCtx.drawImage(source, 0, 0, source.width, source.height, 0, 0, size.width, size.height);
125
+ },
126
+
127
+ /**
128
+ * Draw an image from a file on a canvas.
129
+ * @param file The uploaded file.
130
+ * @param $canvas The canvas (jQuery) object to draw on.
131
+ * @param callback Function that is called when the operation has finished.
132
+ */
133
+ readImageToCanvas: function (file, $canvas, callback) {
134
+ this.newImage();
135
+ if (!file) return;
136
+
137
+ var reader = new FileReader();
138
+ reader.onload = function (fileReaderEvent) {
139
+ image.onload = function () {
140
+ readImageToCanvasOnLoad(this, $canvas, callback);
141
+ };
142
+ image.src = fileReaderEvent.target.result; // The URL from FileReader
143
+ };
144
+ reader.readAsDataURL(file);
145
+ },
146
+
147
+ /**
148
+ * Read the canvas data and save it as a binary byte array to image data variable.
149
+ * Get this data using the method getImageData().
150
+ * @param canvas
151
+ */
152
+ saveCanvasToImageData: function (canvas) {
153
+ var base64 = canvas.toDataURL('image/jpeg', options.jpegQuality).replace(/^data:image\/(png|jpeg|jpg|gif);base64,/, '');
154
+ imageData = base64toBlob(base64, 'image/jpeg'); // Byte array
155
+ },
156
+ };
157
+ }
158
+
159
+ export default CanvasImageUploader;
@@ -0,0 +1,28 @@
1
+ import Config from '../../config';
2
+ import getExtension from './getExtension';
3
+
4
+ const get1400 = (url) => {
5
+ if (!url) {
6
+ return url;
7
+ }
8
+ if (url.indexOf('https://plussprdstorage.blob.core.windows.net/') !== -1) {
9
+ return url.replace('https://plussprdstorage.blob.core.windows.net/', 'https://plusscdn.azureedge.net/');
10
+ }
11
+ if (url.indexOf('https://plusscdn.azureedge.net/') !== -1) {
12
+ return url.replace('/uploads/', '/uploads1400/').replace('/general/', '/general1400/');
13
+ }
14
+
15
+ const { baseUploadsUrl, baseLibraryUrl } = Config.env;
16
+
17
+ if (url.indexOf(baseUploadsUrl) !== -1 || url.indexOf(baseLibraryUrl) !== -1) {
18
+ const extension = getExtension(url);
19
+ let urlToUse = url;
20
+ if (extension !== 'jpg') {
21
+ urlToUse = `${url.substring(0, url.length - (extension.length + 1))}.jpg`;
22
+ }
23
+ return urlToUse.replace('/uploads/', '/1400/');
24
+ }
25
+ return url;
26
+ };
27
+
28
+ export default get1400;
@@ -0,0 +1,9 @@
1
+ const getExtension = (url) => {
2
+ if (!url) {
3
+ return null;
4
+ }
5
+ const fileSplit = url.split('.');
6
+ return fileSplit[fileSplit.length - 1].toLowerCase();
7
+ };
8
+
9
+ export default getExtension;
@@ -0,0 +1,13 @@
1
+ const getFileName = (url, noExtension) => {
2
+ if (!url) {
3
+ return null;
4
+ }
5
+ const fileSplit = url.split('/');
6
+ const name = fileSplit[fileSplit.length - 1].toLowerCase();
7
+ if (!noExtension) {
8
+ return name;
9
+ }
10
+ return name.split('.')[0];
11
+ };
12
+
13
+ export default getFileName;
@@ -0,0 +1,32 @@
1
+ import Config from '../../config';
2
+ import getExtension from './getExtension';
3
+
4
+ const getThumb300 = (url) => {
5
+ if (!url) {
6
+ return url;
7
+ }
8
+ if (url.indexOf('https://plussprdstorage.blob.core.windows.net/') !== -1) {
9
+ return url.replace('https://plussprdstorage.blob.core.windows.net/', 'https://plusscdn.azureedge.net/');
10
+ }
11
+ if (url.indexOf('https://plusscdn.azureedge.net/') !== -1) {
12
+ return url
13
+ .replace('/uploads/', '/uploads-thumb/')
14
+ .replace('/general/', '/general300/')
15
+ .replace('/uploads1400/', '/uploads-thumb/')
16
+ .replace('/general1400/', '/general300/');
17
+ }
18
+
19
+ const { baseUploadsUrl } = Config.env;
20
+
21
+ if (url.indexOf(baseUploadsUrl) !== -1) {
22
+ const extension = getExtension(url);
23
+ let urlToUse = url;
24
+ if (extension !== 'jpg') {
25
+ urlToUse = `${url.substring(0, url.length - (extension.length + 1))}.jpg`;
26
+ }
27
+ return urlToUse.replace('/1400/', '/thumb300/').replace('/uploads/', '/thumb300/');
28
+ }
29
+ return url;
30
+ };
31
+
32
+ export default getThumb300;
@@ -0,0 +1,8 @@
1
+ import getExtension from './getExtension';
2
+
3
+ const isVideo = (url) => {
4
+ const extension = getExtension(url);
5
+ return ['mov', 'mp4'].includes(extension);
6
+ };
7
+
8
+ export default isVideo;
@@ -1,6 +1,5 @@
1
- import React from 'react';
2
1
  import _ from 'lodash';
3
- import Config from './config';
2
+
4
3
  // import moment from 'moment';
5
4
  // import Cookies from 'js-cookie';
6
5
  // import {
@@ -30,22 +29,6 @@ import Config from './config';
30
29
  // return logo;
31
30
  // };
32
31
 
33
- export const getUrl = (baseAction, action, query) => {
34
- const { baseAPIUrl, baseStage } = Config.env;
35
- let queryPart = '';
36
- if (query) {
37
- _.keys(query).forEach((key, index) => {
38
- queryPart += `${index === 0 ? '?' : '&'}${key}=${query[key]}`;
39
- });
40
- }
41
- return `${baseAPIUrl}/${baseAction}-${baseStage}/${action}${queryPart}`;
42
- };
43
-
44
- export const safeReadParams = (props, key) => {
45
- if (props && props.match && props.match.params) return props.match.params[key];
46
- return null;
47
- };
48
-
49
32
  // export const getUrlParams = () => {
50
33
  // var vars = {};
51
34
  // window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
@@ -54,13 +37,12 @@ export const safeReadParams = (props, key) => {
54
37
  // return vars;
55
38
  // };
56
39
 
57
- export const isEmail = (email) => {
58
- if (_.isEmpty(email)) return false;
59
- const atpos = email.indexOf('@');
60
- const dotpos = email.lastIndexOf('.');
61
- if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= email.length) return false;
62
- return true;
63
- };
40
+ // export const onlyAlphanumeric = (input) => {
41
+ // if (!input) {
42
+ // return input;
43
+ // }
44
+ // return input.replace(/[^a-z0-9]/gi, '');
45
+ // };
64
46
 
65
47
  // export const isUrl = (url) => {
66
48
  // const dotpos = url.lastIndexOf('.');
@@ -70,15 +52,6 @@ export const isEmail = (email) => {
70
52
  // return true;
71
53
  // };
72
54
 
73
- export const randomString = () => {
74
- return 'xxxxxxxx4xxxyxxxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
75
- // eslint-disable-next-line
76
- var r = (Math.random() * 16) | 0,
77
- v = c === 'x' ? r : (r & 0x3) | 0x8;
78
- return v.toString(16);
79
- });
80
- };
81
-
82
55
  // export const generateImageName = (name) => {
83
56
  // return `xxxxxxxx4xxxyxxxxxxxxxxxxx${name}`.replace(/[xy]/g, (c) => {
84
57
  // // eslint-disable-next-line
@@ -102,47 +75,6 @@ export const randomString = () => {
102
75
  // return string.split(' ')[0];
103
76
  // };
104
77
 
105
- // export const getExtension = (url) => {
106
- // if (!url) {
107
- // return null;
108
- // }
109
- // const fileSplit = url.split('.');
110
- // return fileSplit[fileSplit.length - 1].toLowerCase();
111
- // };
112
-
113
- // export const getFileName = (url, noExtension) => {
114
- // if (!url) {
115
- // return null;
116
- // }
117
- // const fileSplit = url.split('/');
118
- // const name = fileSplit[fileSplit.length - 1].toLowerCase();
119
- // if (!noExtension) {
120
- // return name;
121
- // }
122
- // return name.split('.')[0];
123
- // };
124
-
125
- // export const get1400 = (url) => {
126
- // if (!url) {
127
- // return url;
128
- // }
129
- // if (url.indexOf('https://plussprdstorage.blob.core.windows.net/') !== -1) {
130
- // return url.replace('https://plussprdstorage.blob.core.windows.net/', 'https://plusscdn.azureedge.net/');
131
- // }
132
- // if (url.indexOf('https://plusscdn.azureedge.net/') !== -1) {
133
- // return url.replace('/uploads/', '/uploads1400/').replace('/general/', '/general1400/');
134
- // }
135
- // if (url.indexOf(baseUploadsUrl) !== -1 || url.indexOf(baseLibraryUrl) !== -1) {
136
- // const extension = getExtension(url);
137
- // let urlToUse = url;
138
- // if (extension !== 'jpg') {
139
- // urlToUse = `${url.substring(0, url.length - (extension.length + 1))}.jpg`;
140
- // }
141
- // return urlToUse.replace('/uploads/', '/1400/');
142
- // }
143
- // return url;
144
- // };
145
-
146
78
  // export const get300 = (url) => {
147
79
  // if (!url) {
148
80
  // return url;
@@ -164,41 +96,11 @@ export const randomString = () => {
164
96
  // return url;
165
97
  // };
166
98
 
167
- // export const getThumb300 = (url) => {
168
- // if (!url) {
169
- // return url;
170
- // }
171
- // if (url.indexOf('https://plussprdstorage.blob.core.windows.net/') !== -1) {
172
- // return url.replace('https://plussprdstorage.blob.core.windows.net/', 'https://plusscdn.azureedge.net/');
173
- // }
174
- // if (url.indexOf('https://plusscdn.azureedge.net/') !== -1) {
175
- // return url
176
- // .replace('/uploads/', '/uploads-thumb/')
177
- // .replace('/general/', '/general300/')
178
- // .replace('/uploads1400/', '/uploads-thumb/')
179
- // .replace('/general1400/', '/general300/');
180
- // }
181
- // if (url.indexOf(baseUploadsUrl) !== -1) {
182
- // const extension = getExtension(url);
183
- // let urlToUse = url;
184
- // if (extension !== 'jpg') {
185
- // urlToUse = `${url.substring(0, url.length - (extension.length + 1))}.jpg`;
186
- // }
187
- // return urlToUse.replace('/1400/', '/thumb300/').replace('/uploads/', '/thumb300/');
188
- // }
189
- // return url;
190
- // };
191
-
192
99
  // export const getCompressed = (url) => {
193
100
  // if (!url || typeof url !== 'string') return '';
194
101
  // return url.replace('/uploads/', '/compressed/');
195
102
  // };
196
103
 
197
- // export const isVideo = (url) => {
198
- // const extension = getExtension(url);
199
- // return ['mov', 'mp4'].includes(extension);
200
- // };
201
-
202
104
  // export const getTimepickerTime = (input) => {
203
105
  // var timeSplit = input.split(':');
204
106
  // if (timeSplit[1].indexOf('pm') > -1) {
@@ -230,19 +132,19 @@ export const randomString = () => {
230
132
  // return moment.utc(dateObject);
231
133
  // };
232
134
 
233
- // export const getPluralS = (count) => {
234
- // if (count === 1) {
235
- // return '';
236
- // }
237
- // return 's';
238
- // };
135
+ export const getPluralS = (count) => {
136
+ if (count === 1) {
137
+ return '';
138
+ }
139
+ return 's';
140
+ };
239
141
 
240
- // export const getPluralOptions = (count, singular, plural) => {
241
- // if (count === 1) {
242
- // return singular;
243
- // }
244
- // return plural;
245
- // };
142
+ export const getPluralOptions = (count, singular, plural) => {
143
+ if (count === 1) {
144
+ return singular;
145
+ }
146
+ return plural;
147
+ };
246
148
 
247
149
  // export const getPercentage = (count, total) => {
248
150
  // if (!count) {
@@ -266,19 +168,6 @@ export const randomString = () => {
266
168
  // return _.map(users, getUserPreview);
267
169
  // };
268
170
 
269
- export const toParagraphed = (text, style) => {
270
- if (!text) return text;
271
- text = text.replace(/\t/g, '\u00a0\u00a0\u00a0\u00a0');
272
- const textSplit = text.split('\n');
273
- return _.map(textSplit, (t, i) => {
274
- return (
275
- <span key={`paragraph_${i}`} style={{ display: 'block', ...style }}>
276
- {t || '\u00A0'}
277
- </span>
278
- );
279
- });
280
- };
281
-
282
171
  // export const getSiteNameFromRoles = (site, roles) => {
283
172
  // return getSiteName(
284
173
  // site,