@capillarytech/creatives-library 8.0.292-alpha.0 → 8.0.293

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 (80) hide show
  1. package/constants/unified.js +1 -3
  2. package/initialState.js +2 -0
  3. package/package.json +1 -1
  4. package/utils/common.js +8 -5
  5. package/utils/commonUtils.js +85 -4
  6. package/utils/tagValidations.js +223 -83
  7. package/utils/tests/commonUtil.test.js +124 -147
  8. package/utils/tests/tagValidations.test.js +358 -441
  9. package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +33 -0
  10. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +422 -0
  11. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.scss +35 -0
  12. package/v2Components/CommonTestAndPreview/DeliverySettings/TECH_DETAILING_DELIVERY_SETTINGS.md +725 -0
  13. package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +92 -0
  14. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +251 -0
  15. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +111 -0
  16. package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +91 -0
  17. package/v2Components/CommonTestAndPreview/SendTestMessage.js +51 -1
  18. package/v2Components/CommonTestAndPreview/actions.js +20 -0
  19. package/v2Components/CommonTestAndPreview/constants.js +10 -0
  20. package/v2Components/CommonTestAndPreview/index.js +148 -15
  21. package/v2Components/CommonTestAndPreview/reducer.js +47 -0
  22. package/v2Components/CommonTestAndPreview/sagas.js +60 -0
  23. package/v2Components/CommonTestAndPreview/selectors.js +51 -0
  24. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +889 -0
  25. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +222 -0
  26. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +235 -0
  27. package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +135 -0
  28. package/v2Components/CommonTestAndPreview/tests/actions.test.js +50 -0
  29. package/v2Components/CommonTestAndPreview/tests/constants.test.js +18 -0
  30. package/v2Components/CommonTestAndPreview/tests/index.test.js +342 -1
  31. package/v2Components/CommonTestAndPreview/tests/reducer.test.js +118 -0
  32. package/v2Components/CommonTestAndPreview/tests/sagas.test.js +145 -0
  33. package/v2Components/CommonTestAndPreview/tests/selectors.test.js +146 -0
  34. package/v2Components/ErrorInfoNote/index.js +5 -2
  35. package/v2Components/FormBuilder/index.js +203 -137
  36. package/v2Components/FormBuilder/messages.js +8 -0
  37. package/v2Components/HtmlEditor/HTMLEditor.js +5 -0
  38. package/v2Components/HtmlEditor/__tests__/HTMLEditor.apiErrors.test.js +1 -0
  39. package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +15 -0
  40. package/v2Components/HtmlEditor/components/CodeEditorPane/index.js +2 -1
  41. package/v2Components/TestAndPreviewSlidebox/index.js +14 -0
  42. package/v2Containers/Cap/mockData.js +14 -0
  43. package/v2Containers/Cap/reducer.js +55 -3
  44. package/v2Containers/Cap/tests/reducer.test.js +102 -0
  45. package/v2Containers/CreativesContainer/SlideBoxContent.js +1 -5
  46. package/v2Containers/CreativesContainer/SlideBoxFooter.js +5 -13
  47. package/v2Containers/CreativesContainer/index.js +7 -30
  48. package/v2Containers/Email/index.js +5 -1
  49. package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +70 -23
  50. package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +137 -29
  51. package/v2Containers/FTP/index.js +51 -2
  52. package/v2Containers/FTP/messages.js +4 -0
  53. package/v2Containers/InApp/index.js +104 -4
  54. package/v2Containers/InApp/tests/index.test.js +6 -17
  55. package/v2Containers/InappAdvance/index.js +108 -4
  56. package/v2Containers/InappAdvance/tests/index.test.js +0 -2
  57. package/v2Containers/Line/Container/Text/index.js +1 -0
  58. package/v2Containers/MobilePush/Create/index.js +19 -42
  59. package/v2Containers/MobilePush/Edit/index.js +19 -42
  60. package/v2Containers/MobilePushNew/index.js +32 -12
  61. package/v2Containers/MobilepushWrapper/index.js +1 -3
  62. package/v2Containers/Rcs/index.js +37 -12
  63. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +697 -12
  64. package/v2Containers/Sms/Create/index.js +3 -39
  65. package/v2Containers/Sms/Create/messages.js +0 -4
  66. package/v2Containers/Sms/Edit/index.js +3 -35
  67. package/v2Containers/Sms/commonMethods.js +6 -3
  68. package/v2Containers/SmsTrai/Edit/index.js +52 -12
  69. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +207 -6
  70. package/v2Containers/SmsWrapper/index.js +0 -2
  71. package/v2Containers/Viber/index.js +1 -0
  72. package/v2Containers/WebPush/Create/hooks/useTagManagement.js +3 -1
  73. package/v2Containers/WebPush/Create/hooks/useTagManagement.test.js +7 -0
  74. package/v2Containers/WebPush/Create/index.js +2 -2
  75. package/v2Containers/WebPush/Create/utils/validation.js +2 -17
  76. package/v2Containers/WebPush/Create/utils/validation.test.js +24 -59
  77. package/v2Containers/Whatsapp/index.js +18 -10
  78. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +26242 -4225
  79. package/v2Containers/Zalo/index.js +11 -3
  80. package/v2Containers/Sms/tests/commonMethods.test.js +0 -122
@@ -105,6 +105,10 @@ const CommonTestAndPreview = (props) => {
105
105
  updatePreviewErrors,
106
106
  fetchPrefilledValuesError,
107
107
  fetchPrefilledValuesErrors,
108
+ senderDetailsByChannel = {},
109
+ wecrmAccounts = [],
110
+ isLoadingSenderDetails = false,
111
+ orgUnitId = -1,
108
112
  // Email-specific props
109
113
  beeInstance,
110
114
  currentTab = 1,
@@ -146,6 +150,100 @@ const CommonTestAndPreview = (props) => {
146
150
  const [selectedTestEntities, setSelectedTestEntities] = useState([]);
147
151
  const [beeContent, setBeeContent] = useState(''); // Track BEE editor content separately (EMAIL only)
148
152
  const previousBeeContentRef = useRef(''); // Track previous BEE content (EMAIL only)
153
+ // Delivery settings for Test and Preview (SMS, Email, WhatsApp) — user selection only
154
+ const [testPreviewDeliverySettings, setTestPreviewDeliverySettings] = useState({
155
+ [CHANNELS.SMS]: {
156
+ domainId: null, domainGatewayMapId: null, gsmSenderId: '', cdmaSenderId: '',
157
+ },
158
+ [CHANNELS.EMAIL]: {
159
+ domainId: null, domainGatewayMapId: null, senderEmail: '', senderLabel: '', senderReplyTo: '',
160
+ },
161
+ [CHANNELS.WHATSAPP]: {
162
+ domainId: null, senderMobNum: '', sourceAccountIdentifier: '',
163
+ },
164
+ });
165
+
166
+ const channelsWithDeliverySettings = [CHANNELS.SMS, CHANNELS.EMAIL, CHANNELS.WHATSAPP];
167
+ const formDataForSendTest = formData ?? (content && typeof content === 'object' && !Array.isArray(content) ? content : formData);
168
+ const smsTemplateConfigs = formDataForSendTest?.templateConfigs || {};
169
+ const smsTraiDltEnabled = !!smsTemplateConfigs?.traiDltEnabled;
170
+ const registeredSenderIds = smsTemplateConfigs?.registeredSenderIds || [];
171
+
172
+ // Fetch sender details and WeCRM accounts when Test & Preview opens for SMS/Email/WhatsApp
173
+ useEffect(() => {
174
+ if (!show || !channel) {
175
+ return;
176
+ }
177
+ if (channelsWithDeliverySettings.includes(channel)) {
178
+ if (actions.getSenderDetailsRequested) {
179
+ actions.getSenderDetailsRequested({ channel, orgUnitId: orgUnitId ?? -1 });
180
+ }
181
+ if (channel === CHANNELS.WHATSAPP && actions.getWeCrmAccountsRequested) {
182
+ actions.getWeCrmAccountsRequested({ sourceName: CHANNELS.WHATSAPP });
183
+ }
184
+ }
185
+ }, [show, channel, orgUnitId, actions]);
186
+
187
+ const findDefault = (arr) => (arr && arr.find((x) => x.default)) || (arr && arr[0]) || {};
188
+
189
+ // Auto-set default delivery setting when sender details load (campaigns-style: first domain + default/first sender)
190
+ useEffect(() => {
191
+ if (!channel || !channelsWithDeliverySettings.includes(channel)) return;
192
+ const domains = senderDetailsByChannel[channel];
193
+ if (!domains || domains.length === 0) return;
194
+ const current = testPreviewDeliverySettings[channel];
195
+ const isEmptySelection = !current?.domainId && !current?.gsmSenderId && !current?.senderEmail && !current?.senderMobNum;
196
+ if (!isEmptySelection) return;
197
+
198
+ const whatsappAccountFromForm = channel === CHANNELS.WHATSAPP ? formData?.accountName : undefined;
199
+ const matchedWhatsappAccount = whatsappAccountFromForm
200
+ ? (wecrmAccounts || []).find((account) => account?.name === whatsappAccountFromForm)
201
+ : null;
202
+ const smsDomains = channel === CHANNELS.SMS && smsTraiDltEnabled
203
+ ? domains.filter((domain) => (domain.gsmSenders || []).some((gsm) => registeredSenderIds.includes(gsm.value)))
204
+ : domains;
205
+ const [defaultDomain] = domains;
206
+ const [firstSmsDomain] = smsDomains;
207
+ let firstDomain = defaultDomain;
208
+ if (channel === CHANNELS.WHATSAPP && matchedWhatsappAccount?.sourceAccountIdentifier) {
209
+ firstDomain = domains.find((domain) => domain?.sourceAccountIdentifier === matchedWhatsappAccount.sourceAccountIdentifier) || defaultDomain;
210
+ } else if (channel === CHANNELS.SMS) {
211
+ firstDomain = firstSmsDomain;
212
+ }
213
+ if (!firstDomain) return;
214
+ setTestPreviewDeliverySettings((prev) => {
215
+ const next = { ...prev };
216
+ if (channel === CHANNELS.SMS) {
217
+ const smsGsmSenders = smsTraiDltEnabled
218
+ ? (firstDomain.gsmSenders || []).filter((gsm) => registeredSenderIds.includes(gsm.value))
219
+ : firstDomain.gsmSenders;
220
+ next[channel] = {
221
+ domainId: firstDomain.domainId,
222
+ domainGatewayMapId: firstDomain.dgmId,
223
+ gsmSenderId: findDefault(smsGsmSenders)?.value || smsGsmSenders?.[0]?.value || '',
224
+ cdmaSenderId: findDefault(firstDomain.cdmaSenders)?.value || '',
225
+ };
226
+ } else if (channel === CHANNELS.EMAIL) {
227
+ const defSender = findDefault(firstDomain.emailSenders);
228
+ const defReply = findDefault(firstDomain.emailRepliers);
229
+ next[channel] = {
230
+ domainId: firstDomain.domainId,
231
+ domainGatewayMapId: firstDomain.dgmId,
232
+ senderEmail: defSender?.value || '',
233
+ senderLabel: defSender?.label || '',
234
+ senderReplyTo: defReply?.value || '',
235
+ };
236
+ } else if (channel === CHANNELS.WHATSAPP) {
237
+ const accId = firstDomain.sourceAccountIdentifier;
238
+ next[channel] = {
239
+ domainId: firstDomain.domainId,
240
+ senderMobNum: firstDomain.gsmSenders?.[0]?.value || '',
241
+ sourceAccountIdentifier: matchedWhatsappAccount?.sourceAccountIdentifier || accId || '',
242
+ };
243
+ }
244
+ return next;
245
+ });
246
+ }, [channel, formData?.accountName, senderDetailsByChannel, smsTraiDltEnabled, registeredSenderIds, wecrmAccounts]);
149
247
 
150
248
  // ============================================
151
249
  // MEMOIZED VALUES
@@ -442,7 +540,7 @@ const CommonTestAndPreview = (props) => {
442
540
  * Prepare payload for test message sending based on channel
443
541
  * Updated to match API structure with ouId, sourceEntityId, module, deliverySettings, etc.
444
542
  */
445
- const prepareTestMessagePayload = (channelType, formDataObj, contentStr, customValuesObj, recipientDetails, previewDataObj) => {
543
+ const prepareTestMessagePayload = (channelType, formDataObj, contentStr, customValuesObj, recipientDetails, previewDataObj, deliverySettingsOverride) => {
446
544
  // Base payload structure common to all channels
447
545
  const basePayload = {
448
546
  ouId: -1,
@@ -468,6 +566,14 @@ const CommonTestAndPreview = (props) => {
468
566
  ? resolveTagsInText(subject, customValuesObj)
469
567
  : subject;
470
568
 
569
+ const emailChannelSettings = {
570
+ channel: CHANNELS.EMAIL,
571
+ senderLabel: deliverySettingsOverride?.senderLabel ?? '',
572
+ senderId: deliverySettingsOverride?.senderEmail ?? '',
573
+ replyToId: deliverySettingsOverride?.senderReplyTo ?? '',
574
+ domainGatewayMapId: deliverySettingsOverride?.domainGatewayMapId ?? '',
575
+ domainId: deliverySettingsOverride?.domainId ?? '',
576
+ };
471
577
  return {
472
578
  ...basePayload,
473
579
  emailDeliverySettings: {
@@ -478,12 +584,7 @@ const CommonTestAndPreview = (props) => {
478
584
  skipRateLimit: false,
479
585
  bypassControlUser: false,
480
586
  },
481
- channelSettings: {
482
- channel: CHANNELS.EMAIL,
483
- senderLabel: '',
484
- senderId: '',
485
- replyToId: '',
486
- },
587
+ channelSettings: emailChannelSettings,
487
588
  },
488
589
  emailMessageContent: {
489
590
  channel: CHANNELS.EMAIL,
@@ -520,8 +621,12 @@ const CommonTestAndPreview = (props) => {
520
621
  },
521
622
  smsDeliverySettings: {
522
623
  channelSettings: {
523
- gsmSenderId: '',
524
- domainId: null,
624
+ gsmSenderId: deliverySettingsOverride?.gsmSenderId ?? '',
625
+ domainId: deliverySettingsOverride?.domainId ?? null,
626
+ domainGatewayMapId: deliverySettingsOverride?.domainGatewayMapId ?? '',
627
+ targetNdnc: false,
628
+ cdmaSenderId: deliverySettingsOverride?.cdmaSenderId ?? '',
629
+ channel: CHANNELS.SMS,
525
630
  },
526
631
  additionalSettings: {
527
632
  useTinyUrl: false,
@@ -657,16 +762,17 @@ const CommonTestAndPreview = (props) => {
657
762
  templateConfigs.mediaType = formDataObj?.carouselMediaType?.toUpperCase() || MEDIA_TYPE_IMAGE;
658
763
  }
659
764
 
660
- // Extract delivery settings
661
- const senderMobNum = formDataObj?.senderMobNum || additionalProps?.senderMobNum || '';
662
- const domainId = formDataObj?.domainId || additionalProps?.domainId || null;
765
+ // Extract delivery settings (override from Test & Preview delivery settings when present)
766
+ const senderMobNum = deliverySettingsOverride?.senderMobNum ?? formDataObj?.senderMobNum ?? additionalProps?.senderMobNum ?? '';
767
+ const domainId = deliverySettingsOverride?.domainId ?? formDataObj?.domainId ?? additionalProps?.domainId ?? null;
768
+ const sourceAccountIdentifier = deliverySettingsOverride?.sourceAccountIdentifier ?? formDataObj?.sourceAccountIdentifier ?? '';
663
769
 
664
770
  return {
665
771
  ...basePayload,
666
772
  whatsappMessageContent: {
667
773
  messageBody: templateEditorValue || '',
668
774
  accountId: formDataObj?.accountId || '',
669
- sourceAccountIdentifier: formDataObj?.sourceAccountIdentifier || '',
775
+ sourceAccountIdentifier: sourceAccountIdentifier || formDataObj?.sourceAccountIdentifier || '',
670
776
  accountName: formDataObj?.accountName || '',
671
777
  templateConfigs,
672
778
  channel: CHANNELS.WHATSAPP,
@@ -2370,6 +2476,10 @@ const CommonTestAndPreview = (props) => {
2370
2476
  });
2371
2477
  const uniqueUserIds = [...new Set(allUserIds)];
2372
2478
 
2479
+ const deliveryOverride = [CHANNELS.SMS, CHANNELS.EMAIL, CHANNELS.WHATSAPP].includes(channel)
2480
+ ? testPreviewDeliverySettings[channel]
2481
+ : null;
2482
+
2373
2483
  // Create initial payload based on channel
2374
2484
  const initialPayload = prepareTestMessagePayload(
2375
2485
  channel,
@@ -2377,7 +2487,8 @@ const CommonTestAndPreview = (props) => {
2377
2487
  getCurrentContent,
2378
2488
  customValues,
2379
2489
  uniqueUserIds,
2380
- previewData
2490
+ previewData,
2491
+ deliveryOverride
2381
2492
  );
2382
2493
 
2383
2494
  actions.createMessageMetaRequested(
@@ -2449,6 +2560,13 @@ const CommonTestAndPreview = (props) => {
2449
2560
  />
2450
2561
  );
2451
2562
 
2563
+ const handleSaveDeliverySettings = (values) => {
2564
+ setTestPreviewDeliverySettings((prev) => ({
2565
+ ...prev,
2566
+ [channel]: values,
2567
+ }));
2568
+ };
2569
+
2452
2570
  const renderSendTestMessage = () => (
2453
2571
  <SendTestMessage
2454
2572
  isFetchingTestCustomers={isFetchingTestCustomers}
@@ -2457,11 +2575,18 @@ const CommonTestAndPreview = (props) => {
2457
2575
  handleTestEntitiesChange={handleTestEntitiesChange}
2458
2576
  selectedTestEntities={selectedTestEntities}
2459
2577
  handleSendTestMessage={handleSendTestMessage}
2460
- formData={formData}
2578
+ formData={formDataForSendTest}
2461
2579
  content={getCurrentContent}
2462
2580
  channel={channel}
2463
2581
  isSendingTestMessage={isSendingTestMessage}
2464
2582
  formatMessage={formatMessage}
2583
+ deliverySettings={testPreviewDeliverySettings[channel]}
2584
+ senderDetailsOptions={senderDetailsByChannel[channel]}
2585
+ wecrmAccounts={wecrmAccounts}
2586
+ onSaveDeliverySettings={handleSaveDeliverySettings}
2587
+ isLoadingSenderDetails={isLoadingSenderDetails}
2588
+ smsTraiDltEnabled={smsTraiDltEnabled}
2589
+ registeredSenderIds={registeredSenderIds}
2465
2590
  />
2466
2591
  );
2467
2592
 
@@ -2562,6 +2687,10 @@ CommonTestAndPreview.propTypes = {
2562
2687
  })),
2563
2688
  isSendingTestMessage: PropTypes.bool.isRequired,
2564
2689
  intl: PropTypes.object.isRequired,
2690
+ senderDetailsByChannel: PropTypes.object,
2691
+ wecrmAccounts: PropTypes.array,
2692
+ isLoadingSenderDetails: PropTypes.bool,
2693
+ orgUnitId: PropTypes.number,
2565
2694
 
2566
2695
  // Email-specific props
2567
2696
  beeInstance: PropTypes.object,
@@ -2597,6 +2726,10 @@ CommonTestAndPreview.defaultProps = {
2597
2726
  rcsOrientation: null,
2598
2727
  rcsIosPreview: false,
2599
2728
  templateLayoutType: null,
2729
+ senderDetailsByChannel: {},
2730
+ wecrmAccounts: [],
2731
+ isLoadingSenderDetails: false,
2732
+ orgUnitId: -1,
2600
2733
  };
2601
2734
 
2602
2735
  // ============================================
@@ -31,6 +31,13 @@ import {
31
31
  GET_PREFILLED_VALUES_FAILURE,
32
32
  CLEAR_PREFILLED_VALUES,
33
33
  CLEAR_PREVIEW_ERRORS,
34
+ GET_SENDER_DETAILS_REQUESTED,
35
+ GET_SENDER_DETAILS_SUCCESS,
36
+ GET_SENDER_DETAILS_FAILURE,
37
+ GET_WECRM_ACCOUNTS_REQUESTED,
38
+ GET_WECRM_ACCOUNTS_SUCCESS,
39
+ GET_WECRM_ACCOUNTS_FAILURE,
40
+ CHANNELS,
34
41
  } from './constants';
35
42
 
36
43
  const initialState = fromJS({
@@ -85,6 +92,16 @@ const initialState = fromJS({
85
92
  isFetchingPrefilledValues: false,
86
93
  fetchPrefilledValuesError: null,
87
94
  fetchPrefilledValuesErrors: [],
95
+
96
+ senderDetailsByChannel: fromJS({
97
+ [CHANNELS.SMS]: [],
98
+ [CHANNELS.EMAIL]: [],
99
+ [CHANNELS.WHATSAPP]: [],
100
+ }),
101
+ wecrmAccounts: fromJS([]),
102
+ isLoadingSenderDetails: false,
103
+ fetchSenderDetailsError: null,
104
+ fetchWeCrmAccountsError: null,
88
105
  });
89
106
 
90
107
  const previewAndTestReducer = (state = initialState, action) => {
@@ -250,6 +267,36 @@ const previewAndTestReducer = (state = initialState, action) => {
250
267
  .set('fetchPrefilledValuesError', null)
251
268
  .set('fetchPrefilledValuesErrors', fromJS([]));
252
269
 
270
+ case GET_SENDER_DETAILS_REQUESTED:
271
+ return state
272
+ .set('isLoadingSenderDetails', true)
273
+ .set('fetchSenderDetailsError', null);
274
+
275
+ case GET_SENDER_DETAILS_SUCCESS: {
276
+ const { channel, domains } = action.payload || {};
277
+ if (!channel) return state;
278
+ return state
279
+ .setIn(['senderDetailsByChannel', channel], fromJS(domains || []))
280
+ .set('isLoadingSenderDetails', false)
281
+ .set('fetchSenderDetailsError', null);
282
+ }
283
+
284
+ case GET_SENDER_DETAILS_FAILURE:
285
+ return state
286
+ .set('isLoadingSenderDetails', false)
287
+ .set('fetchSenderDetailsError', action.payload?.error ?? action.payload);
288
+
289
+ case GET_WECRM_ACCOUNTS_REQUESTED:
290
+ return state.set('fetchWeCrmAccountsError', null);
291
+
292
+ case GET_WECRM_ACCOUNTS_SUCCESS:
293
+ return state
294
+ .set('wecrmAccounts', fromJS(action.payload?.accounts || []))
295
+ .set('fetchWeCrmAccountsError', null);
296
+
297
+ case GET_WECRM_ACCOUNTS_FAILURE:
298
+ return state.set('fetchWeCrmAccountsError', action.payload?.error ?? action.payload);
299
+
253
300
  default:
254
301
  return state;
255
302
  }
@@ -35,8 +35,15 @@ import {
35
35
  GET_PREFILLED_VALUES_REQUESTED,
36
36
  GET_PREFILLED_VALUES_SUCCESS,
37
37
  GET_PREFILLED_VALUES_FAILURE,
38
+ GET_SENDER_DETAILS_REQUESTED,
39
+ GET_SENDER_DETAILS_SUCCESS,
40
+ GET_SENDER_DETAILS_FAILURE,
41
+ GET_WECRM_ACCOUNTS_REQUESTED,
42
+ GET_WECRM_ACCOUNTS_SUCCESS,
43
+ GET_WECRM_ACCOUNTS_FAILURE,
38
44
  ERROR_MESSAGES,
39
45
  } from './constants';
46
+ import { parseSenderDetailsResponse } from './DeliverySettings/utils/parseSenderDetailsResponse';
40
47
 
41
48
  // Search Customers Saga
42
49
  export function* searchCustomersSaga(action) {
@@ -285,6 +292,57 @@ export function* watchGetPrefilledValues() {
285
292
  yield takeLatest(GET_PREFILLED_VALUES_REQUESTED, getPrefilledValuesSaga);
286
293
  }
287
294
 
295
+ export function* getSenderDetailsSaga(action) {
296
+ const { channel, orgUnitId } = action.payload || {};
297
+ if (!channel) return;
298
+ try {
299
+ const response = yield call(Api.getSenderDetails, channel, orgUnitId ?? -1);
300
+ if (response?.errors?.length) {
301
+ yield put({
302
+ type: GET_SENDER_DETAILS_FAILURE,
303
+ payload: { channel, error: response.errors },
304
+ });
305
+ return;
306
+ }
307
+ const parsed = parseSenderDetailsResponse(channel, response);
308
+ yield put({
309
+ type: GET_SENDER_DETAILS_SUCCESS,
310
+ payload: { channel, domains: parsed.domains || [] },
311
+ });
312
+ } catch (error) {
313
+ yield put({
314
+ type: GET_SENDER_DETAILS_FAILURE,
315
+ payload: { channel, error: error.message || error },
316
+ });
317
+ }
318
+ }
319
+
320
+ export function* getWeCrmAccountsSaga(action) {
321
+ const { sourceName } = action.payload || {};
322
+ try {
323
+ const result = yield call(Api.fetchWeCrmAccounts, sourceName || 'WHATSAPP');
324
+ const accounts = get(result, 'response') || get(result, 'entity') || (result?.success ? result.response : null) || [];
325
+ const list = Array.isArray(accounts) ? accounts : (accounts && accounts.data) || [];
326
+ yield put({
327
+ type: GET_WECRM_ACCOUNTS_SUCCESS,
328
+ payload: { accounts: list },
329
+ });
330
+ } catch (error) {
331
+ yield put({
332
+ type: GET_WECRM_ACCOUNTS_FAILURE,
333
+ payload: { error: error.message || error },
334
+ });
335
+ }
336
+ }
337
+
338
+ export function* watchGetSenderDetails() {
339
+ yield takeLatest(GET_SENDER_DETAILS_REQUESTED, getSenderDetailsSaga);
340
+ }
341
+
342
+ export function* watchGetWeCrmAccounts() {
343
+ yield takeLatest(GET_WECRM_ACCOUNTS_REQUESTED, getWeCrmAccountsSaga);
344
+ }
345
+
288
346
  // Root saga
289
347
  export function* commonTestAndPreviewSaga() {
290
348
  yield all([
@@ -296,5 +354,7 @@ export function* commonTestAndPreviewSaga() {
296
354
  watchFetchTestGroups(),
297
355
  watchCreateMessageMeta(),
298
356
  watchGetPrefilledValues(),
357
+ watchGetSenderDetails(),
358
+ watchGetWeCrmAccounts(),
299
359
  ]);
300
360
  }
@@ -144,6 +144,51 @@ const makeSelectFetchPrefilledValuesErrors = () => createSelector(
144
144
  (substate) => substate.get('fetchPrefilledValuesErrors')?.toJS() || [],
145
145
  );
146
146
 
147
+ const makeSelectSenderDetailsForChannel = (channel) => createSelector(
148
+ selectCommonTestAndPreviewDomain,
149
+ (substate) => {
150
+ if (!substate) return [];
151
+ const byChannel = substate.get('senderDetailsByChannel');
152
+ if (!byChannel) return [];
153
+ const list = byChannel.get(channel);
154
+ return list ? list.toJS() : [];
155
+ },
156
+ );
157
+
158
+ const makeSelectSenderDetailsByChannel = () => createSelector(
159
+ selectCommonTestAndPreviewDomain,
160
+ (substate) => {
161
+ if (!substate) return {};
162
+ const byChannel = substate.get('senderDetailsByChannel');
163
+ if (!byChannel) return {};
164
+ return byChannel.toJS ? byChannel.toJS() : {};
165
+ },
166
+ );
167
+
168
+ const makeSelectWeCrmAccounts = () => createSelector(
169
+ selectCommonTestAndPreviewDomain,
170
+ (substate) => {
171
+ if (!substate) return [];
172
+ const list = substate.get('wecrmAccounts');
173
+ return list ? list.toJS() : [];
174
+ },
175
+ );
176
+
177
+ const makeSelectIsLoadingSenderDetails = () => createSelector(
178
+ selectCommonTestAndPreviewDomain,
179
+ (substate) => substate.get('isLoadingSenderDetails') || false,
180
+ );
181
+
182
+ const makeSelectFetchSenderDetailsError = () => createSelector(
183
+ selectCommonTestAndPreviewDomain,
184
+ (substate) => substate.get('fetchSenderDetailsError'),
185
+ );
186
+
187
+ const makeSelectFetchWeCrmAccountsError = () => createSelector(
188
+ selectCommonTestAndPreviewDomain,
189
+ (substate) => substate.get('fetchWeCrmAccountsError'),
190
+ );
191
+
147
192
  export {
148
193
  makeSelectCommonTestAndPreview,
149
194
  makeSelectCustomers,
@@ -171,4 +216,10 @@ export {
171
216
  makeSelectUpdatePreviewErrors,
172
217
  makeSelectFetchPrefilledValuesError,
173
218
  makeSelectFetchPrefilledValuesErrors,
219
+ makeSelectSenderDetailsForChannel,
220
+ makeSelectSenderDetailsByChannel,
221
+ makeSelectWeCrmAccounts,
222
+ makeSelectIsLoadingSenderDetails,
223
+ makeSelectFetchSenderDetailsError,
224
+ makeSelectFetchWeCrmAccountsError,
174
225
  };