@capillarytech/creatives-library 8.0.295 → 8.0.296
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/package.json +1 -1
- package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +33 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +425 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.scss +36 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +92 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +251 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +111 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +88 -0
- package/v2Components/CommonTestAndPreview/SendTestMessage.js +51 -1
- package/v2Components/CommonTestAndPreview/actions.js +20 -0
- package/v2Components/CommonTestAndPreview/constants.js +15 -0
- package/v2Components/CommonTestAndPreview/index.js +200 -16
- package/v2Components/CommonTestAndPreview/reducer.js +47 -0
- package/v2Components/CommonTestAndPreview/sagas.js +61 -0
- package/v2Components/CommonTestAndPreview/selectors.js +51 -0
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +889 -0
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +222 -0
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +235 -0
- package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +135 -0
- package/v2Components/CommonTestAndPreview/tests/actions.test.js +50 -0
- package/v2Components/CommonTestAndPreview/tests/constants.test.js +18 -0
- package/v2Components/CommonTestAndPreview/tests/index.test.js +783 -2
- package/v2Components/CommonTestAndPreview/tests/reducer.test.js +118 -0
- package/v2Components/CommonTestAndPreview/tests/sagas.test.js +145 -0
- package/v2Components/CommonTestAndPreview/tests/selectors.test.js +146 -0
- package/v2Components/FormBuilder/index.js +1 -1
- package/v2Components/HtmlEditor/HTMLEditor.js +0 -1
- package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +0 -1
- package/v2Components/HtmlEditor/hooks/__tests__/useValidation.test.js +3 -132
- package/v2Components/HtmlEditor/hooks/useValidation.js +9 -12
- package/v2Components/HtmlEditor/utils/htmlValidator.js +2 -4
- package/v2Components/TestAndPreviewSlidebox/index.js +14 -0
- package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +2 -2
- package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +18 -110
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +697 -12
- package/v2Containers/SmsTrai/Edit/index.js +5 -1
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +201 -0
- package/v2Containers/Whatsapp/index.js +1 -1
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +26242 -4225
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeliverySettings — summary row + CapSlideBox trigger for Test and Preview.
|
|
3
|
+
* Rendered only for SMS, Email, WhatsApp. Uses cap-ui-library only.
|
|
4
|
+
*
|
|
5
|
+
* Reference: cap-campaigns-v2 DeliverySettingsV2 (summary + modify panel).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, { useState, useCallback } from "react";
|
|
9
|
+
import PropTypes from "prop-types";
|
|
10
|
+
import {
|
|
11
|
+
CapRow,
|
|
12
|
+
CapHeading,
|
|
13
|
+
CapIcon,
|
|
14
|
+
CapLabel,
|
|
15
|
+
CapSlideBox,
|
|
16
|
+
} from "@capillarytech/cap-ui-library";
|
|
17
|
+
import { FormattedMessage } from "react-intl";
|
|
18
|
+
import get from "lodash/get";
|
|
19
|
+
import messages from "./messages";
|
|
20
|
+
import ModifyDeliverySettings from "./ModifyDeliverySettings";
|
|
21
|
+
import {
|
|
22
|
+
CHANNELS,
|
|
23
|
+
CHANNELS_WITH_DELIVERY_SETTINGS,
|
|
24
|
+
NOT_CONFIGURED_LABEL,
|
|
25
|
+
SUMMARY_EMPTY_PLACEHOLDER,
|
|
26
|
+
HEADING_TYPE_H10,
|
|
27
|
+
ROW_TYPE_FLEX,
|
|
28
|
+
DELIVERY_SETTING_KEY_DOMAIN_ID,
|
|
29
|
+
DELIVERY_SETTING_KEY_GSM_SENDER_ID,
|
|
30
|
+
DELIVERY_SETTING_KEY_SENDER_EMAIL,
|
|
31
|
+
DELIVERY_SETTING_KEY_SENDER_LABEL,
|
|
32
|
+
DELIVERY_SETTING_KEY_SENDER_REPLY_TO,
|
|
33
|
+
DELIVERY_SETTING_KEY_SOURCE_ACCOUNT_IDENTIFIER,
|
|
34
|
+
DELIVERY_SETTING_KEY_SENDER_MOB_NUM,
|
|
35
|
+
LABEL_TYPE_LABEL1,
|
|
36
|
+
LABEL_TYPE_LABEL2,
|
|
37
|
+
LABEL_TYPE_LABEL9,
|
|
38
|
+
ICON_TYPE_EDIT,
|
|
39
|
+
SLIDE_BOX_SIZE_L,
|
|
40
|
+
TEST_ID_DELIVERY_SETTINGS_EDIT,
|
|
41
|
+
} from "./constants";
|
|
42
|
+
import "./DeliverySettings.scss";
|
|
43
|
+
|
|
44
|
+
const DeliverySettings = (props) => {
|
|
45
|
+
const {
|
|
46
|
+
channel,
|
|
47
|
+
deliverySettings = {},
|
|
48
|
+
senderDetailsOptions = [],
|
|
49
|
+
wecrmAccounts = [],
|
|
50
|
+
onSaveDeliverySettings,
|
|
51
|
+
isLoadingSenderDetails,
|
|
52
|
+
formatMessage,
|
|
53
|
+
smsTraiDltEnabled,
|
|
54
|
+
registeredSenderIds,
|
|
55
|
+
whatsappAccountFromForm,
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
const [isSlideBoxOpen, setSlideBoxOpen] = useState(false);
|
|
59
|
+
|
|
60
|
+
const openSlideBox = useCallback(() => setSlideBoxOpen(true), []);
|
|
61
|
+
const closeSlideBox = useCallback(() => setSlideBoxOpen(false), []);
|
|
62
|
+
|
|
63
|
+
const handleSave = useCallback(
|
|
64
|
+
(values) => {
|
|
65
|
+
onSaveDeliverySettings(values);
|
|
66
|
+
closeSlideBox();
|
|
67
|
+
},
|
|
68
|
+
[onSaveDeliverySettings, closeSlideBox]
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (!CHANNELS_WITH_DELIVERY_SETTINGS.includes(channel)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const notConfiguredLabel = formatMessage
|
|
76
|
+
? formatMessage(messages.notConfigured)
|
|
77
|
+
: NOT_CONFIGURED_LABEL;
|
|
78
|
+
|
|
79
|
+
const getSummaryText = () => {
|
|
80
|
+
const empty = SUMMARY_EMPTY_PLACEHOLDER;
|
|
81
|
+
if (channel === CHANNELS.SMS) {
|
|
82
|
+
const domain = (senderDetailsOptions || []).find(
|
|
83
|
+
(d) => d.domainId === get(deliverySettings, DELIVERY_SETTING_KEY_DOMAIN_ID),
|
|
84
|
+
);
|
|
85
|
+
const domainName = domain?.domainName || empty;
|
|
86
|
+
const senderId = get(deliverySettings, DELIVERY_SETTING_KEY_GSM_SENDER_ID) || empty;
|
|
87
|
+
return { senderDomain: domainName, senderId };
|
|
88
|
+
}
|
|
89
|
+
if (channel === CHANNELS.EMAIL) {
|
|
90
|
+
const domain = (senderDetailsOptions || []).find(
|
|
91
|
+
(d) => d.domainId === get(deliverySettings, DELIVERY_SETTING_KEY_DOMAIN_ID),
|
|
92
|
+
);
|
|
93
|
+
const emailDomain = domain?.domainName || empty;
|
|
94
|
+
const senderEmail = get(deliverySettings, DELIVERY_SETTING_KEY_SENDER_EMAIL) || empty;
|
|
95
|
+
const senderLabel = get(deliverySettings, DELIVERY_SETTING_KEY_SENDER_LABEL) || empty;
|
|
96
|
+
const replyToId = get(deliverySettings, DELIVERY_SETTING_KEY_SENDER_REPLY_TO) || empty;
|
|
97
|
+
return {
|
|
98
|
+
emailDomain,
|
|
99
|
+
senderEmail,
|
|
100
|
+
senderLabel,
|
|
101
|
+
replyToId,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (channel === CHANNELS.WHATSAPP) {
|
|
105
|
+
const account = (wecrmAccounts || []).find(
|
|
106
|
+
(a) => a.sourceAccountIdentifier
|
|
107
|
+
=== get(deliverySettings, DELIVERY_SETTING_KEY_SOURCE_ACCOUNT_IDENTIFIER),
|
|
108
|
+
);
|
|
109
|
+
const accountName = account?.name || empty;
|
|
110
|
+
const senderNumber = get(deliverySettings, DELIVERY_SETTING_KEY_SENDER_MOB_NUM) || empty;
|
|
111
|
+
return { account: accountName, senderNumber };
|
|
112
|
+
}
|
|
113
|
+
return { account: empty, sender: empty };
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const summary = getSummaryText();
|
|
117
|
+
let hasValues = false;
|
|
118
|
+
if (channel === CHANNELS.SMS) {
|
|
119
|
+
hasValues = summary.senderDomain !== SUMMARY_EMPTY_PLACEHOLDER
|
|
120
|
+
|| summary.senderId !== SUMMARY_EMPTY_PLACEHOLDER;
|
|
121
|
+
} else if (channel === CHANNELS.EMAIL) {
|
|
122
|
+
hasValues = summary.emailDomain !== SUMMARY_EMPTY_PLACEHOLDER
|
|
123
|
+
|| summary.senderEmail !== SUMMARY_EMPTY_PLACEHOLDER
|
|
124
|
+
|| summary.senderLabel !== SUMMARY_EMPTY_PLACEHOLDER
|
|
125
|
+
|| summary.replyToId !== SUMMARY_EMPTY_PLACEHOLDER;
|
|
126
|
+
} else if (channel === CHANNELS.WHATSAPP) {
|
|
127
|
+
hasValues = summary.account !== SUMMARY_EMPTY_PLACEHOLDER
|
|
128
|
+
|| summary.senderNumber !== SUMMARY_EMPTY_PLACEHOLDER;
|
|
129
|
+
} else {
|
|
130
|
+
hasValues = summary.account !== SUMMARY_EMPTY_PLACEHOLDER
|
|
131
|
+
|| summary.sender !== SUMMARY_EMPTY_PLACEHOLDER;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const getSummaryObject = () => {
|
|
135
|
+
if (!hasValues) return null;
|
|
136
|
+
const label = (msg) => formatMessage(msg);
|
|
137
|
+
if (channel === CHANNELS.SMS) {
|
|
138
|
+
return {
|
|
139
|
+
[label(messages.senderDomainSummary)]: summary.senderDomain,
|
|
140
|
+
[label(messages.senderId)]: summary.senderId,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (channel === CHANNELS.EMAIL) {
|
|
144
|
+
return {
|
|
145
|
+
[label(messages.emailDomain)]: summary.emailDomain,
|
|
146
|
+
[label(messages.senderId)]: summary.senderEmail,
|
|
147
|
+
[label(messages.senderName)]: summary.senderLabel,
|
|
148
|
+
[label(messages.replyToId)]: summary.replyToId,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (channel === CHANNELS.WHATSAPP) {
|
|
152
|
+
return {
|
|
153
|
+
[label(messages.account)]: summary.account,
|
|
154
|
+
[label(messages.senderNumber)]: summary.senderNumber,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
[label(messages.account)]: summary.account,
|
|
159
|
+
[label(messages.senderNumber)]: summary.sender,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const summaryObject = getSummaryObject();
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<CapRow className="delivery-settings">
|
|
167
|
+
<CapRow className="delivery-settings__heading-row">
|
|
168
|
+
<CapHeading type={HEADING_TYPE_H10}>
|
|
169
|
+
<FormattedMessage {...messages.deliverySettings} />
|
|
170
|
+
</CapHeading>
|
|
171
|
+
</CapRow>
|
|
172
|
+
<CapRow type={ROW_TYPE_FLEX} className="delivery-settings__summary-row">
|
|
173
|
+
<CapRow type={ROW_TYPE_FLEX} className="delivery-settings__summary-inner">
|
|
174
|
+
{summaryObject == null ? (
|
|
175
|
+
<CapLabel type={LABEL_TYPE_LABEL2}>{notConfiguredLabel}</CapLabel>
|
|
176
|
+
) : (
|
|
177
|
+
Object.entries(summaryObject).map(([key, value]) => (
|
|
178
|
+
<CapRow type={ROW_TYPE_FLEX} key={key} className="delivery-settings__summary-entry">
|
|
179
|
+
<CapLabel type={LABEL_TYPE_LABEL1} className="delivery-settings__summary-key">{key}</CapLabel>
|
|
180
|
+
<CapLabel type={LABEL_TYPE_LABEL9}>
|
|
181
|
+
:
|
|
182
|
+
{' '}
|
|
183
|
+
{value}
|
|
184
|
+
</CapLabel>
|
|
185
|
+
</CapRow>
|
|
186
|
+
))
|
|
187
|
+
)}
|
|
188
|
+
</CapRow>
|
|
189
|
+
<CapIcon
|
|
190
|
+
type={ICON_TYPE_EDIT}
|
|
191
|
+
onClick={openSlideBox}
|
|
192
|
+
className="delivery-settings__edit-icon"
|
|
193
|
+
data-testid={TEST_ID_DELIVERY_SETTINGS_EDIT}
|
|
194
|
+
size="s"
|
|
195
|
+
/>
|
|
196
|
+
</CapRow>
|
|
197
|
+
|
|
198
|
+
{isSlideBoxOpen && (
|
|
199
|
+
<CapSlideBox
|
|
200
|
+
show
|
|
201
|
+
size={SLIDE_BOX_SIZE_L}
|
|
202
|
+
header={<FormattedMessage {...messages.deliverySettings} />}
|
|
203
|
+
handleClose={closeSlideBox}
|
|
204
|
+
content={(
|
|
205
|
+
<ModifyDeliverySettings
|
|
206
|
+
channel={channel}
|
|
207
|
+
deliverySettings={deliverySettings}
|
|
208
|
+
senderDetailsOptions={senderDetailsOptions}
|
|
209
|
+
wecrmAccounts={wecrmAccounts}
|
|
210
|
+
onSaveDeliverySettings={handleSave}
|
|
211
|
+
onClose={closeSlideBox}
|
|
212
|
+
isLoading={isLoadingSenderDetails}
|
|
213
|
+
formatMessage={formatMessage}
|
|
214
|
+
smsTraiDltEnabled={smsTraiDltEnabled}
|
|
215
|
+
registeredSenderIds={registeredSenderIds}
|
|
216
|
+
whatsappAccountFromForm={whatsappAccountFromForm}
|
|
217
|
+
/>
|
|
218
|
+
)}
|
|
219
|
+
/>
|
|
220
|
+
)}
|
|
221
|
+
</CapRow>
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
DeliverySettings.propTypes = {
|
|
226
|
+
channel: PropTypes.string.isRequired,
|
|
227
|
+
deliverySettings: PropTypes.object,
|
|
228
|
+
senderDetailsOptions: PropTypes.array,
|
|
229
|
+
wecrmAccounts: PropTypes.array,
|
|
230
|
+
onSaveDeliverySettings: PropTypes.func.isRequired,
|
|
231
|
+
isLoadingSenderDetails: PropTypes.bool,
|
|
232
|
+
formatMessage: PropTypes.func,
|
|
233
|
+
smsTraiDltEnabled: PropTypes.bool,
|
|
234
|
+
registeredSenderIds: PropTypes.array,
|
|
235
|
+
whatsappAccountFromForm: PropTypes.shape({
|
|
236
|
+
accountName: PropTypes.string,
|
|
237
|
+
}),
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
DeliverySettings.defaultProps = {
|
|
241
|
+
deliverySettings: {},
|
|
242
|
+
senderDetailsOptions: [],
|
|
243
|
+
wecrmAccounts: [],
|
|
244
|
+
isLoadingSenderDetails: false,
|
|
245
|
+
formatMessage: undefined,
|
|
246
|
+
smsTraiDltEnabled: false,
|
|
247
|
+
registeredSenderIds: [],
|
|
248
|
+
whatsappAccountFromForm: undefined,
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export default DeliverySettings;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeliverySettings messages for Test and Preview.
|
|
3
|
+
* Aligned with cap-campaigns-v2 DeliverySettingsV2 and ModifyDeliverySettings messages.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { defineMessages } from 'react-intl';
|
|
7
|
+
|
|
8
|
+
const prefix = 'creatives.CommonTestAndPreview.DeliverySettings';
|
|
9
|
+
|
|
10
|
+
export default defineMessages({
|
|
11
|
+
deliverySettings: {
|
|
12
|
+
id: `${prefix}.deliverySettings`,
|
|
13
|
+
defaultMessage: 'Delivery settings',
|
|
14
|
+
},
|
|
15
|
+
notConfigured: {
|
|
16
|
+
id: `${prefix}.notConfigured`,
|
|
17
|
+
defaultMessage: 'Not configured',
|
|
18
|
+
},
|
|
19
|
+
account: {
|
|
20
|
+
id: `${prefix}.account`,
|
|
21
|
+
defaultMessage: 'Account',
|
|
22
|
+
},
|
|
23
|
+
senderNumber: {
|
|
24
|
+
id: `${prefix}.senderNumber`,
|
|
25
|
+
defaultMessage: 'Sender number',
|
|
26
|
+
},
|
|
27
|
+
senderDomain: {
|
|
28
|
+
id: `${prefix}.senderDomain`,
|
|
29
|
+
defaultMessage: 'Sender domain',
|
|
30
|
+
},
|
|
31
|
+
senderId: {
|
|
32
|
+
id: `${prefix}.senderId`,
|
|
33
|
+
defaultMessage: 'Sender ID',
|
|
34
|
+
},
|
|
35
|
+
senderName: {
|
|
36
|
+
id: `${prefix}.senderName`,
|
|
37
|
+
defaultMessage: 'Sender name',
|
|
38
|
+
},
|
|
39
|
+
replyToId: {
|
|
40
|
+
id: `${prefix}.replyToId`,
|
|
41
|
+
defaultMessage: 'Reply-to ID',
|
|
42
|
+
},
|
|
43
|
+
done: {
|
|
44
|
+
id: `${prefix}.done`,
|
|
45
|
+
defaultMessage: 'Done',
|
|
46
|
+
},
|
|
47
|
+
smsDomain: {
|
|
48
|
+
id: `${prefix}.smsDomain`,
|
|
49
|
+
defaultMessage: 'SMS Domain',
|
|
50
|
+
},
|
|
51
|
+
/** SMS summary & form: "Sender Domain" (capital D) for summary line */
|
|
52
|
+
senderDomainSummary: {
|
|
53
|
+
id: `${prefix}.senderDomainSummary`,
|
|
54
|
+
defaultMessage: 'Sender Domain',
|
|
55
|
+
},
|
|
56
|
+
/** SMS form label with colon: "Sender domain:" */
|
|
57
|
+
senderDomainLabel: {
|
|
58
|
+
id: `${prefix}.senderDomainLabel`,
|
|
59
|
+
defaultMessage: 'Sender domain:',
|
|
60
|
+
},
|
|
61
|
+
/** SMS form label with colon: "Sender ID:" */
|
|
62
|
+
senderIdLabel: {
|
|
63
|
+
id: `${prefix}.senderIdLabel`,
|
|
64
|
+
defaultMessage: 'Sender ID:',
|
|
65
|
+
},
|
|
66
|
+
emailDomain: {
|
|
67
|
+
id: `${prefix}.emailDomain`,
|
|
68
|
+
defaultMessage: 'Email Domain',
|
|
69
|
+
},
|
|
70
|
+
/** Email form/summary: "Email domain:" (with colon) */
|
|
71
|
+
emailDomainLabel: {
|
|
72
|
+
id: `${prefix}.emailDomainLabel`,
|
|
73
|
+
defaultMessage: 'Email domain:',
|
|
74
|
+
},
|
|
75
|
+
/** Email form: "Sender ID:" (with colon) */
|
|
76
|
+
senderNameLabelEmail: {
|
|
77
|
+
id: `${prefix}.senderIdLabelEmail`,
|
|
78
|
+
defaultMessage: 'Sender Name:',
|
|
79
|
+
},
|
|
80
|
+
/** Email form/summary: "Reply-to ID:" (with colon) */
|
|
81
|
+
replyToIdLabel: {
|
|
82
|
+
id: `${prefix}.replyToIdLabel`,
|
|
83
|
+
defaultMessage: 'Reply-to ID:',
|
|
84
|
+
},
|
|
85
|
+
whatsappBusinessAcc: {
|
|
86
|
+
id: `${prefix}.whatsappBusinessAcc`,
|
|
87
|
+
defaultMessage: 'WhatsApp business account',
|
|
88
|
+
},
|
|
89
|
+
whatsappSenderNum: {
|
|
90
|
+
id: `${prefix}.whatsappSenderNum`,
|
|
91
|
+
defaultMessage: 'WhatsApp sender number',
|
|
92
|
+
},
|
|
93
|
+
/** WhatsApp form/summary: "Account:" (with colon) */
|
|
94
|
+
accountLabel: {
|
|
95
|
+
id: `${prefix}.accountLabel`,
|
|
96
|
+
defaultMessage: 'Account:',
|
|
97
|
+
},
|
|
98
|
+
/** WhatsApp form/summary: "Sender number:" (with colon) */
|
|
99
|
+
senderNumberLabel: {
|
|
100
|
+
id: `${prefix}.senderNumberLabel`,
|
|
101
|
+
defaultMessage: 'Sender number:',
|
|
102
|
+
},
|
|
103
|
+
noOptions: {
|
|
104
|
+
id: `${prefix}.noOptions`,
|
|
105
|
+
defaultMessage: 'No options',
|
|
106
|
+
},
|
|
107
|
+
disabledMessage: {
|
|
108
|
+
id: `${prefix}.disabledMessage`,
|
|
109
|
+
defaultMessage: 'Message template selected belongs to this account',
|
|
110
|
+
},
|
|
111
|
+
});
|
package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize getSenderDetails(channel, orgUnitId) API response for a single channel.
|
|
3
|
+
* Output shape matches cap-campaigns-v2 parseSenderDetails so UI can consume
|
|
4
|
+
* domains with domainId, domainName, gsmSenders, emailSenders, emailRepliers, etc.
|
|
5
|
+
*
|
|
6
|
+
* Reference: cap-campaigns-v2 app/utils/parseSenderDetails.js
|
|
7
|
+
* No cross-repo imports; logic aligned with campaigns domain structure.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import get from 'lodash/get';
|
|
11
|
+
import { CHANNELS } from '../../constants';
|
|
12
|
+
|
|
13
|
+
const getSenderOptions = (contactInfo, key) =>
|
|
14
|
+
(contactInfo || [])
|
|
15
|
+
.filter((contactInfoItem) => contactInfoItem.type === key && contactInfoItem.valid)
|
|
16
|
+
.sort((contact) => (contact.default ? -1 : 0));
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse raw API response for one channel into { domains: [...] }
|
|
20
|
+
* @param {string} channel - SMS | EMAIL | WHATSAPP
|
|
21
|
+
* @param {Object} response - API response (e.g. { entity: { SMS: [...] } } or { entity: [...] })
|
|
22
|
+
* @returns {{ domains: Array }} - domains array compatible with campaigns DeliverySettingsV2
|
|
23
|
+
*/
|
|
24
|
+
export function parseSenderDetailsResponse(channel, response) {
|
|
25
|
+
const entity = get(response, 'entity', response);
|
|
26
|
+
if (!entity) {
|
|
27
|
+
return { domains: [] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Single-channel API: entity may be { [channel]: [...] } or direct array
|
|
31
|
+
let channelSenderDetails = get(entity, channel, null);
|
|
32
|
+
if (channelSenderDetails == null && Array.isArray(entity)) {
|
|
33
|
+
channelSenderDetails = entity;
|
|
34
|
+
}
|
|
35
|
+
if (!Array.isArray(channelSenderDetails)) {
|
|
36
|
+
return { domains: [] };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const domains = [];
|
|
40
|
+
|
|
41
|
+
channelSenderDetails.forEach((element) => {
|
|
42
|
+
const { id: dgmId, priority, domainProperties = {} } = element;
|
|
43
|
+
const {
|
|
44
|
+
domainName,
|
|
45
|
+
id = -1,
|
|
46
|
+
contactInfo,
|
|
47
|
+
connectionProperties: {
|
|
48
|
+
sourceAccountIdentifier = '',
|
|
49
|
+
wabaId = '',
|
|
50
|
+
userid = '',
|
|
51
|
+
} = {},
|
|
52
|
+
} = domainProperties;
|
|
53
|
+
|
|
54
|
+
const domain = {
|
|
55
|
+
dgmId,
|
|
56
|
+
domainName,
|
|
57
|
+
domainId: id,
|
|
58
|
+
priority: priority != null ? priority : 0,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if ([CHANNELS.SMS, CHANNELS.WHATSAPP].includes(channel)) {
|
|
62
|
+
domain.cdmaSenders = getSenderOptions(contactInfo, 'cdma_sender_id');
|
|
63
|
+
domain.gsmSenders = getSenderOptions(contactInfo, 'gsm_sender_id');
|
|
64
|
+
domain.sourceAccountIdentifier =
|
|
65
|
+
sourceAccountIdentifier || wabaId || userid || '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (channel === CHANNELS.EMAIL) {
|
|
69
|
+
domain.emailSenders = getSenderOptions(contactInfo, 'sender_id');
|
|
70
|
+
domain.emailRepliers = getSenderOptions(contactInfo, 'reply_to_id');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
domains.push(domain);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Sort by priority and dedupe by domainName (match campaigns behaviour)
|
|
77
|
+
domains.sort((a, b) => (a.priority || 0) - (b.priority || 0));
|
|
78
|
+
const deduped = domains.reduce((acc, domain) => {
|
|
79
|
+
if (!acc.find((d) => d.domainName === domain.domainName)) {
|
|
80
|
+
acc.push(domain);
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
return { domains: deduped };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default parseSenderDetailsResponse;
|
|
@@ -8,6 +8,10 @@ import CapStepsAccordian from '@capillarytech/cap-ui-library/CapStepsAccordian';
|
|
|
8
8
|
import CapTreeSelect from '@capillarytech/cap-ui-library/CapTreeSelect';
|
|
9
9
|
import isEmpty from 'lodash/isEmpty';
|
|
10
10
|
import messages from './messages';
|
|
11
|
+
import DeliverySettings from './DeliverySettings';
|
|
12
|
+
import { CHANNELS } from './constants';
|
|
13
|
+
|
|
14
|
+
const CHANNELS_WITH_DELIVERY_SETTINGS = [CHANNELS.SMS, CHANNELS.EMAIL, CHANNELS.WHATSAPP];
|
|
11
15
|
|
|
12
16
|
const SendTestMessage = ({
|
|
13
17
|
isFetchingTestCustomers,
|
|
@@ -17,8 +21,16 @@ const SendTestMessage = ({
|
|
|
17
21
|
selectedTestEntities,
|
|
18
22
|
handleSendTestMessage,
|
|
19
23
|
formData,
|
|
24
|
+
channel,
|
|
20
25
|
isSendingTestMessage,
|
|
21
26
|
formatMessage,
|
|
27
|
+
deliverySettings,
|
|
28
|
+
senderDetailsOptions,
|
|
29
|
+
wecrmAccounts,
|
|
30
|
+
onSaveDeliverySettings,
|
|
31
|
+
isLoadingSenderDetails,
|
|
32
|
+
smsTraiDltEnabled,
|
|
33
|
+
registeredSenderIds,
|
|
22
34
|
}) => (
|
|
23
35
|
<CapStepsAccordian
|
|
24
36
|
showNumberSteps={false}
|
|
@@ -43,6 +55,24 @@ const SendTestMessage = ({
|
|
|
43
55
|
multiple
|
|
44
56
|
placeholder={formatMessage(messages.testCustomersPlaceholder)}
|
|
45
57
|
/>
|
|
58
|
+
{CHANNELS_WITH_DELIVERY_SETTINGS.includes(channel) && (
|
|
59
|
+
<DeliverySettings
|
|
60
|
+
channel={channel}
|
|
61
|
+
deliverySettings={deliverySettings || {}}
|
|
62
|
+
senderDetailsOptions={senderDetailsOptions || []}
|
|
63
|
+
wecrmAccounts={wecrmAccounts || []}
|
|
64
|
+
onSaveDeliverySettings={onSaveDeliverySettings}
|
|
65
|
+
isLoadingSenderDetails={isLoadingSenderDetails}
|
|
66
|
+
formatMessage={formatMessage}
|
|
67
|
+
smsTraiDltEnabled={smsTraiDltEnabled}
|
|
68
|
+
registeredSenderIds={registeredSenderIds}
|
|
69
|
+
whatsappAccountFromForm={
|
|
70
|
+
channel === CHANNELS.WHATSAPP && formData?.accountName
|
|
71
|
+
? { accountName: formData.accountName }
|
|
72
|
+
: undefined
|
|
73
|
+
}
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
46
76
|
<CapButton onClick={handleSendTestMessage} disabled={isEmpty(selectedTestEntities) || isSendingTestMessage}>
|
|
47
77
|
<FormattedMessage {...messages.sendTestButton} />
|
|
48
78
|
</CapButton>
|
|
@@ -60,9 +90,29 @@ SendTestMessage.propTypes = {
|
|
|
60
90
|
handleTestEntitiesChange: PropTypes.func.isRequired,
|
|
61
91
|
selectedTestEntities: PropTypes.array.isRequired,
|
|
62
92
|
handleSendTestMessage: PropTypes.func.isRequired,
|
|
63
|
-
formData: PropTypes.object
|
|
93
|
+
formData: PropTypes.object,
|
|
94
|
+
channel: PropTypes.string,
|
|
64
95
|
isSendingTestMessage: PropTypes.bool.isRequired,
|
|
65
96
|
formatMessage: PropTypes.func.isRequired,
|
|
97
|
+
deliverySettings: PropTypes.object,
|
|
98
|
+
senderDetailsOptions: PropTypes.array,
|
|
99
|
+
wecrmAccounts: PropTypes.array,
|
|
100
|
+
onSaveDeliverySettings: PropTypes.func,
|
|
101
|
+
isLoadingSenderDetails: PropTypes.bool,
|
|
102
|
+
smsTraiDltEnabled: PropTypes.bool,
|
|
103
|
+
registeredSenderIds: PropTypes.array,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
SendTestMessage.defaultProps = {
|
|
107
|
+
formData: undefined,
|
|
108
|
+
channel: undefined,
|
|
109
|
+
deliverySettings: {},
|
|
110
|
+
senderDetailsOptions: [],
|
|
111
|
+
wecrmAccounts: [],
|
|
112
|
+
onSaveDeliverySettings: undefined,
|
|
113
|
+
isLoadingSenderDetails: false,
|
|
114
|
+
smsTraiDltEnabled: false,
|
|
115
|
+
registeredSenderIds: [],
|
|
66
116
|
};
|
|
67
117
|
|
|
68
118
|
export default SendTestMessage;
|
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
GET_PREFILLED_VALUES_REQUESTED,
|
|
19
19
|
CLEAR_PREFILLED_VALUES,
|
|
20
20
|
CLEAR_PREVIEW_ERRORS,
|
|
21
|
+
GET_SENDER_DETAILS_REQUESTED,
|
|
22
|
+
GET_WECRM_ACCOUNTS_REQUESTED,
|
|
21
23
|
} from './constants';
|
|
22
24
|
|
|
23
25
|
// ============================================
|
|
@@ -125,3 +127,21 @@ export const clearPrefilledValues = () => ({
|
|
|
125
127
|
export const clearPreviewErrors = () => ({
|
|
126
128
|
type: CLEAR_PREVIEW_ERRORS,
|
|
127
129
|
});
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Request sender details for a channel (SMS, EMAIL, WHATSAPP) for delivery settings
|
|
133
|
+
* @param {Object} payload - { channel, orgUnitId }
|
|
134
|
+
*/
|
|
135
|
+
export const getSenderDetailsRequested = (payload) => ({
|
|
136
|
+
type: GET_SENDER_DETAILS_REQUESTED,
|
|
137
|
+
payload,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Request WeCRM accounts (e.g. for WhatsApp account dropdown)
|
|
142
|
+
* @param {Object} payload - { sourceName } e.g. { sourceName: 'WHATSAPP' }
|
|
143
|
+
*/
|
|
144
|
+
export const getWeCrmAccountsRequested = (payload) => ({
|
|
145
|
+
type: GET_WECRM_ACCOUNTS_REQUESTED,
|
|
146
|
+
payload,
|
|
147
|
+
});
|
|
@@ -55,6 +55,16 @@ export const CLEAR_SEARCH_RESULTS = 'app/CommonTestAndPreview/CLEAR_SEARCH_RESUL
|
|
|
55
55
|
export const CLEAR_PREFILLED_VALUES = 'app/CommonTestAndPreview/CLEAR_PREFILLED_VALUES';
|
|
56
56
|
export const CLEAR_PREVIEW_ERRORS = 'app/CommonTestAndPreview/CLEAR_PREVIEW_ERRORS';
|
|
57
57
|
|
|
58
|
+
// Get Sender Details (delivery settings for Test and Preview)
|
|
59
|
+
export const GET_SENDER_DETAILS_REQUESTED = 'app/CommonTestAndPreview/GET_SENDER_DETAILS_REQUESTED';
|
|
60
|
+
export const GET_SENDER_DETAILS_SUCCESS = 'app/CommonTestAndPreview/GET_SENDER_DETAILS_SUCCESS';
|
|
61
|
+
export const GET_SENDER_DETAILS_FAILURE = 'app/CommonTestAndPreview/GET_SENDER_DETAILS_FAILURE';
|
|
62
|
+
|
|
63
|
+
// Get WeCRM Accounts (WhatsApp account list)
|
|
64
|
+
export const GET_WECRM_ACCOUNTS_REQUESTED = 'app/CommonTestAndPreview/GET_WECRM_ACCOUNTS_REQUESTED';
|
|
65
|
+
export const GET_WECRM_ACCOUNTS_SUCCESS = 'app/CommonTestAndPreview/GET_WECRM_ACCOUNTS_SUCCESS';
|
|
66
|
+
export const GET_WECRM_ACCOUNTS_FAILURE = 'app/CommonTestAndPreview/GET_WECRM_ACCOUNTS_FAILURE';
|
|
67
|
+
|
|
58
68
|
// ============================================
|
|
59
69
|
// CHANNEL CONSTANTS
|
|
60
70
|
// ============================================
|
|
@@ -169,6 +179,11 @@ export const UNSUBSCRIBE_TAG_NAME = 'unsubscribe';
|
|
|
169
179
|
export const IN_APP_CHANNEL_NAME = 'in-app';
|
|
170
180
|
export const MOBILE_PUSH_CHANNEL_NAME = 'mobile push';
|
|
171
181
|
export const CHANNEL = 'channel';
|
|
182
|
+
export const PHONE_NUMBER = 'PHONE_NUMBER';
|
|
183
|
+
export const DYNAMIC_URL = 'DYNAMIC_URL';
|
|
184
|
+
export const IMAGE = 'IMAGE';
|
|
185
|
+
export const VIDEO = 'VIDEO';
|
|
186
|
+
export const URL = 'URL';
|
|
172
187
|
|
|
173
188
|
// Initial Payload Template (for reference)
|
|
174
189
|
export const INITIAL_PAYLOAD = {
|