@embedreach/components 0.1.77 → 0.1.78

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.
@@ -34169,6 +34169,9 @@ const PaginatedTable = ({
34169
34169
  cursor: newCursor,
34170
34170
  limit: itemsPerPage
34171
34171
  });
34172
+ if (!response.items) {
34173
+ return;
34174
+ }
34172
34175
  if (newCursor) {
34173
34176
  setItems((prev) => [...prev, ...response.items]);
34174
34177
  } else {
@@ -34419,7 +34422,7 @@ const AutomationTable = memo$1(
34419
34422
  search: searchQuery || void 0
34420
34423
  });
34421
34424
  return {
34422
- items: response.data,
34425
+ items: response.results,
34423
34426
  cursor: response.pagination.cursor ?? void 0
34424
34427
  };
34425
34428
  },
@@ -43353,7 +43356,7 @@ const AllSegmentList = () => {
43353
43356
  search: searchQuery || void 0
43354
43357
  });
43355
43358
  return {
43356
- items: response.data,
43359
+ items: response.results,
43357
43360
  cursor: response.pagination.cursor ?? void 0
43358
43361
  };
43359
43362
  },
@@ -43539,13 +43542,25 @@ const validateAutomationStep = async (args) => {
43539
43542
  }
43540
43543
  }
43541
43544
  if (currentStep === 3) {
43545
+ const isOneTime = isOneTimeTriggerMetadata(automation2.trigger_metadata);
43546
+ if (isOneTime) {
43547
+ const oneTimeMetadata = automation2.trigger_metadata;
43548
+ return {
43549
+ canMove: Boolean(
43550
+ oneTimeMetadata.scheduled_at && new Date(oneTimeMetadata.scheduled_at) > /* @__PURE__ */ new Date() && automation2.action_data?.some(
43551
+ (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
43552
+ )
43553
+ ),
43554
+ errorMessage: "Please ensure you have set a valid future date for your one-time automation"
43555
+ };
43556
+ }
43542
43557
  return {
43543
43558
  canMove: Boolean(
43544
- isOneTimeTriggerMetadata(automation2.trigger_metadata) && automation2.trigger_metadata.scheduled_at && new Date(automation2.trigger_metadata.scheduled_at) > /* @__PURE__ */ new Date() && automation2.action_data?.some(
43559
+ automation2.action_data?.some(
43545
43560
  (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
43546
43561
  )
43547
43562
  ),
43548
- errorMessage: "Please ensure you have set a valid future date for scheduling"
43563
+ errorMessage: null
43549
43564
  };
43550
43565
  }
43551
43566
  return {
@@ -43950,7 +43965,7 @@ const AutomationContent = ({
43950
43965
  setLoading2(true);
43951
43966
  try {
43952
43967
  const emailChannelSenderId = communicationGroup.email_channel_sender_id;
43953
- const emailChannelSender = channelSenders.data.find(
43968
+ const emailChannelSender = channelSenders.results.find(
43954
43969
  (sender) => sender.id === emailChannelSenderId
43955
43970
  );
43956
43971
  if (emailChannelSender && communicationGroup.email_html_body) {
@@ -43964,7 +43979,7 @@ const AutomationContent = ({
43964
43979
  });
43965
43980
  }
43966
43981
  const smsChannelSenderId = communicationGroup.sms_channel_sender_id;
43967
- const smsChannelSender = channelSenders.data.find(
43982
+ const smsChannelSender = channelSenders.results.find(
43968
43983
  (sender) => sender.id === smsChannelSenderId
43969
43984
  );
43970
43985
  if (smsChannelSender && (smsChannelSender.channel_sender_metadata.from || smsChannelSender.channel_sender_metadata.messageServiceSid) && communicationGroup.sms_message_body) {
@@ -46074,8 +46089,8 @@ const EmailPreview = ({
46074
46089
  const { channelAccounts } = useChannelAccount();
46075
46090
  const { updateChannelSender: updateChannelSender2 } = useUpdateChannelSender();
46076
46091
  const emailChannelSendersWithChannelAccounts = useMemo(
46077
- () => channelSenders?.data?.filter((sender) => sender.channel_sender_metadata.userPart)?.flatMap((sender) => {
46078
- const channelAccount = channelAccounts?.data?.find(
46092
+ () => channelSenders?.results?.filter((sender) => sender.channel_sender_metadata.userPart)?.flatMap((sender) => {
46093
+ const channelAccount = channelAccounts?.results?.find(
46079
46094
  (account) => account.id === sender.channel_account_id
46080
46095
  );
46081
46096
  if (!channelAccount) return [];
@@ -46089,7 +46104,7 @@ const EmailPreview = ({
46089
46104
  }
46090
46105
  return [];
46091
46106
  }) || [],
46092
- [channelSenders?.data, channelAccounts?.data]
46107
+ [channelSenders?.results, channelAccounts?.results]
46093
46108
  );
46094
46109
  const [stripoDialogDimensions, setStripoDialogDimensions] = useState({
46095
46110
  width: 0,
@@ -46168,8 +46183,8 @@ const EmailPreview = ({
46168
46183
  updateCommunicationGroup2
46169
46184
  ]);
46170
46185
  useEffect(() => {
46171
- if (channelSenders?.data && fromEmail) {
46172
- const channelSender = channelSenders.data.find(
46186
+ if (channelSenders?.results && fromEmail) {
46187
+ const channelSender = channelSenders.results.find(
46173
46188
  (sender) => sender.id === fromEmail
46174
46189
  );
46175
46190
  if (channelSender) {
@@ -46180,24 +46195,35 @@ const EmailPreview = ({
46180
46195
  setIsFormLoading(false);
46181
46196
  }
46182
46197
  }
46183
- }, [channelSenders?.data, fromEmail, userModifiedEmail, isFormLoading]);
46198
+ }, [channelSenders?.results, fromEmail, userModifiedEmail, isFormLoading]);
46184
46199
  useEffect(() => {
46185
- if (channelSenders?.data && !fromEmail && !initialRenderRef.current) {
46186
- const allEmailSenders = channelSenders.data.filter(
46200
+ if (channelSenders?.results && !fromEmail) {
46201
+ const allEmailSenders = channelSenders.results.filter(
46187
46202
  (sender) => sender.channel_sender_metadata.userPart
46188
46203
  );
46189
46204
  if (allEmailSenders[0]) {
46190
46205
  const channelSender = allEmailSenders[0];
46191
46206
  setFromEmail(channelSender.id);
46207
+ updateCommunicationGroup2({
46208
+ groupId: communicationGroup.id,
46209
+ params: {
46210
+ email_channel_sender_id: channelSender.id
46211
+ }
46212
+ });
46192
46213
  }
46193
46214
  }
46194
- }, [channelSenders?.data, fromEmail]);
46215
+ }, [
46216
+ channelSenders?.results,
46217
+ fromEmail,
46218
+ communicationGroup.id,
46219
+ updateCommunicationGroup2
46220
+ ]);
46195
46221
  useEffect(() => {
46196
46222
  if (!initialRenderRef.current && debouncedFromName && fromEmail) {
46197
46223
  setIsUpdating(true);
46198
46224
  const updateSender = async () => {
46199
46225
  try {
46200
- const channelSender = channelSenders?.data?.find(
46226
+ const channelSender = channelSenders?.results?.find(
46201
46227
  (sender) => sender.id === fromEmail
46202
46228
  );
46203
46229
  if (channelSender) {
@@ -46219,7 +46245,12 @@ const EmailPreview = ({
46219
46245
  };
46220
46246
  updateSender();
46221
46247
  }
46222
- }, [debouncedFromName, channelSenders?.data, fromEmail, updateChannelSender2]);
46248
+ }, [
46249
+ debouncedFromName,
46250
+ channelSenders?.results,
46251
+ fromEmail,
46252
+ updateChannelSender2
46253
+ ]);
46223
46254
  useEffect(() => {
46224
46255
  if (debouncedReplyToEmail) {
46225
46256
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -46236,7 +46267,7 @@ const EmailPreview = ({
46236
46267
  setIsUpdating(true);
46237
46268
  const updateReplyTo = async () => {
46238
46269
  try {
46239
- const channelSender = channelSenders?.data?.find(
46270
+ const channelSender = channelSenders?.results?.find(
46240
46271
  (sender) => sender.id === fromEmail
46241
46272
  );
46242
46273
  if (channelSender) {
@@ -46260,7 +46291,7 @@ const EmailPreview = ({
46260
46291
  }
46261
46292
  }, [
46262
46293
  debouncedReplyToEmail,
46263
- channelSenders?.data,
46294
+ channelSenders?.results,
46264
46295
  fromEmail,
46265
46296
  updateChannelSender2,
46266
46297
  replyToEmailError
@@ -46710,7 +46741,6 @@ const SMSPreview = ({ automation: automation2, iconDefinitions, mergeFieldsRespo
46710
46741
  const [initCompanyName, setInitCompanyName] = useState(false);
46711
46742
  const [companyName, setCompanyName] = useState(null);
46712
46743
  const [message2, setMessage] = useState(null);
46713
- const [initialStateSet, setInitialStateSet] = useState(false);
46714
46744
  const [showSmsEditor, setShowSmsEditor] = useState(false);
46715
46745
  const { channelSenders } = useChannelSender();
46716
46746
  const { data: me2, isLoading: isMeLoading } = useMe();
@@ -46768,16 +46798,26 @@ const SMSPreview = ({ automation: automation2, iconDefinitions, mergeFieldsRespo
46768
46798
  if (channelSenders === void 0) {
46769
46799
  return;
46770
46800
  }
46771
- if (initialStateSet === false) {
46772
- const smsChannelSenders2 = channelSenders.data?.filter(
46801
+ if (!fromNumber) {
46802
+ const smsChannelSenders2 = channelSenders.results.filter(
46773
46803
  (sender) => sender.channel_sender_metadata.from
46774
46804
  );
46775
46805
  if (smsChannelSenders2?.[0]) {
46776
46806
  setFromNumber(smsChannelSenders2[0].id);
46807
+ if (communicationGroup?.id) {
46808
+ updateCommunicationGroup2({
46809
+ groupId: communicationGroup.id,
46810
+ params: { sms_channel_sender_id: smsChannelSenders2[0].id }
46811
+ });
46812
+ }
46777
46813
  }
46778
- setInitialStateSet(true);
46779
46814
  }
46780
- }, [channelSenders, initialStateSet]);
46815
+ }, [
46816
+ channelSenders,
46817
+ fromNumber,
46818
+ communicationGroup?.id,
46819
+ updateCommunicationGroup2
46820
+ ]);
46781
46821
  useEffect(() => {
46782
46822
  if (!companyName && me2?.name && !initCompanyName) {
46783
46823
  setInitCompanyName(true);
@@ -46787,7 +46827,7 @@ const SMSPreview = ({ automation: automation2, iconDefinitions, mergeFieldsRespo
46787
46827
  if (!channelAccounts || !channelSenders || isMeLoading) {
46788
46828
  return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(SpinLoader, { text: ["Loading..."] }) });
46789
46829
  }
46790
- const smsChannelSenders = channelSenders.data?.filter(
46830
+ const smsChannelSenders = channelSenders.results.filter(
46791
46831
  (sender) => sender.channel_sender_metadata.from || sender.channel_sender_metadata.messageServiceSid
46792
46832
  );
46793
46833
  return /* @__PURE__ */ jsxs("div", { children: [
@@ -46927,7 +46967,6 @@ const EditCampaignContent = ({
46927
46967
  updateCommunicationGroup: updateCommunicationGroup2
46928
46968
  }) => {
46929
46969
  const [selectedChannels, setSelectedChannels] = useState(null);
46930
- const [expandedChannels, setExpandedChannels] = useState(null);
46931
46970
  const emailContainerRef = useRef(null);
46932
46971
  const { toast: toast2 } = useToast();
46933
46972
  const { getMergeFields: getMergeFields2, isGetting: isGetMergeFieldsLoading } = useGetMergeFields(communicationGroup?.id ?? void 0);
@@ -46956,12 +46995,11 @@ const EditCampaignContent = ({
46956
46995
  }, [selectedChannels, updateCommunicationGroup2, communicationGroup]);
46957
46996
  useEffect(() => {
46958
46997
  const finalCommunicationGroupId = communicationGroup?.id;
46959
- if (!finalCommunicationGroupId) {
46998
+ if (!finalCommunicationGroupId && !selectedChannels) {
46960
46999
  setSelectedChannels(["email"]);
46961
- setExpandedChannels(["email"]);
46962
47000
  return;
46963
47001
  }
46964
- }, [automation2, communicationGroup]);
47002
+ }, [automation2, communicationGroup, selectedChannels]);
46965
47003
  const setSelectedChannelsBasedOnCommunicationGroup = useCallback(
46966
47004
  (data) => {
46967
47005
  const finalSelectedChannels = [];
@@ -46975,15 +47013,18 @@ const EditCampaignContent = ({
46975
47013
  finalSelectedChannels.push("email");
46976
47014
  }
46977
47015
  setSelectedChannels(finalSelectedChannels);
46978
- setExpandedChannels(finalSelectedChannels);
46979
47016
  },
46980
47017
  []
46981
47018
  );
46982
47019
  useEffect(() => {
46983
- if (communicationGroup) {
47020
+ if (communicationGroup && !selectedChannels) {
46984
47021
  setSelectedChannelsBasedOnCommunicationGroup(communicationGroup);
46985
47022
  }
46986
- }, [communicationGroup, setSelectedChannelsBasedOnCommunicationGroup]);
47023
+ }, [
47024
+ communicationGroup,
47025
+ setSelectedChannelsBasedOnCommunicationGroup,
47026
+ selectedChannels
47027
+ ]);
46987
47028
  useEffect(() => {
46988
47029
  if (isGetMergeFieldsLoading) {
46989
47030
  return;
@@ -47108,7 +47149,7 @@ const EditCampaignContent = ({
47108
47149
  mergeFieldsResponse,
47109
47150
  setSelectedChannelsBasedOnCommunicationGroup
47110
47151
  ]);
47111
- if (!selectedChannels || !expandedChannels || isGetMergeFieldsLoading || !mergeFieldsResponse) {
47152
+ if (!selectedChannels || isGetMergeFieldsLoading || !mergeFieldsResponse) {
47112
47153
  return /* @__PURE__ */ jsx("div", { className: "flex justify-center items-center flex-1 h-full bg-white rounded-2xl w-full border border-gray-200 p-6 space-y-4 relative", children: /* @__PURE__ */ jsx(SpinLoader, { text: ["Fetching Content..."] }) });
47113
47154
  }
47114
47155
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 flex-shrink-0", children: [
@@ -47681,15 +47722,15 @@ const PreviewAndSchedule = ({
47681
47722
  if (communicationGroup && channelSenderData && channelAccountsData) {
47682
47723
  const emailChannelSenderId = communicationGroup.email_channel_sender_id;
47683
47724
  const smsChannelSenderId = communicationGroup.sms_channel_sender_id;
47684
- const emailChannelSender = channelSenderData.data.find(
47725
+ const emailChannelSender = channelSenderData.results.find(
47685
47726
  (sender) => sender.id === emailChannelSenderId
47686
47727
  );
47687
- const smsChannelSender = channelSenderData.data.find(
47728
+ const smsChannelSender = channelSenderData.results.find(
47688
47729
  (sender) => sender.id === smsChannelSenderId
47689
47730
  );
47690
47731
  if (emailChannelSender && communicationGroup.email_subject && communicationGroup.email_html_body) {
47691
47732
  const userPart = emailChannelSender.channel_sender_metadata?.userPart;
47692
- const channelAccount = channelAccountsData.data.find(
47733
+ const channelAccount = channelAccountsData.results.find(
47693
47734
  (account) => account.id === emailChannelSender.channel_account_id
47694
47735
  );
47695
47736
  if (channelAccount) {
@@ -47859,7 +47900,7 @@ const SelectSegments = ({
47859
47900
  SegmentSection,
47860
47901
  {
47861
47902
  segments: includedSegments,
47862
- allSegments: segments?.data || [],
47903
+ allSegments: segments?.results || [],
47863
47904
  onAddSegment: (id2) => handleAddSegment(id2, "include"),
47864
47905
  onRemoveSegment: (id2) => handleRemoveSegment(id2, "include"),
47865
47906
  setOpenCreateSegmentDialog,
@@ -47899,7 +47940,7 @@ const SelectSegments = ({
47899
47940
  SegmentSection,
47900
47941
  {
47901
47942
  segments: excludedSegments,
47902
- allSegments: segments?.data || [],
47943
+ allSegments: segments?.results || [],
47903
47944
  onAddSegment: (id2) => handleAddSegment(id2, "exclude"),
47904
47945
  onRemoveSegment: (id2) => handleRemoveSegment(id2, "exclude"),
47905
47946
  setOpenCreateSegmentDialog,
@@ -47925,7 +47966,7 @@ const SelectAudience = ({ iconDefinitions, automation: automation2 }) => {
47925
47966
  const allUsersSelected = includedSegments.length === 1 && excludedSegments.length === 0 && /**
47926
47967
  * Check if the all users segment is selected in the atuomation
47927
47968
  */
47928
- segments?.data?.find(
47969
+ segments?.results?.find(
47929
47970
  (segment2) => segment2.type === BusinessSegmentTypeEnum.ALL_USERS && segment2.id === includedSegments[0]
47930
47971
  ) !== void 0;
47931
47972
  const [selectedAudience, setSelectedAudience] = useState(
@@ -47962,7 +48003,7 @@ const SelectAudience = ({ iconDefinitions, automation: automation2 }) => {
47962
48003
  automation2.id
47963
48004
  ]);
47964
48005
  const getAllUsersSegment = useCallback(() => {
47965
- return segments?.data?.find(
48006
+ return segments?.results?.find(
47966
48007
  (segment2) => segment2.type === BusinessSegmentTypeEnum.ALL_USERS
47967
48008
  );
47968
48009
  }, [segments]);
@@ -48145,22 +48186,7 @@ const lineVariant = {
48145
48186
  }
48146
48187
  };
48147
48188
  const TriggerEditAutomation = ({ automation: automation2 }) => {
48148
- const [getSegmentResponse, setGetSegmentResponse] = useState(void 0);
48149
- useEffect(() => {
48150
- const getSegmentData = async () => {
48151
- if (automation2.trigger_metadata.trigger_type !== AutomationTriggerType.TRIGGER_BASED) {
48152
- return;
48153
- }
48154
- const triggerSegmentId = automation2.trigger_metadata.event_filter.segment_id;
48155
- const segmentResponse = await getSegment(triggerSegmentId);
48156
- if (!segmentResponse) {
48157
- return;
48158
- }
48159
- setGetSegmentResponse(segmentResponse);
48160
- };
48161
- getSegmentData();
48162
- }, [automation2.trigger_metadata, automation2.trigger_metadata.trigger_type]);
48163
- if (!getSegmentResponse) {
48189
+ if (!automation2.name) {
48164
48190
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-[200px]", children: /* @__PURE__ */ jsx(SpinLoader, {}) });
48165
48191
  }
48166
48192
  return /* @__PURE__ */ jsx("div", { className: "w-full flex justify-center flex-wrap gap-4", children: /* @__PURE__ */ jsxs(
@@ -48206,32 +48232,22 @@ const TriggerEditAutomation = ({ automation: automation2 }) => {
48206
48232
  )
48207
48233
  }
48208
48234
  ),
48209
- /* @__PURE__ */ jsxs("div", { children: [
48210
- /* @__PURE__ */ jsx(
48211
- motion.h2,
48212
- {
48213
- className: "text-2xl font-semibold text-gray-900 group",
48214
- variants: itemVariants,
48215
- children: getSegmentResponse.name
48216
- }
48217
- ),
48218
- /* @__PURE__ */ jsx(
48219
- motion.p,
48220
- {
48221
- className: "text-gray-600 text-lg mt-2 leading-relaxed",
48222
- variants: itemVariants,
48223
- children: getSegmentResponse.description
48224
- }
48225
- )
48226
- ] })
48235
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
48236
+ motion.h2,
48237
+ {
48238
+ className: "text-2xl font-semibold text-primary group",
48239
+ variants: itemVariants,
48240
+ children: automation2.name
48241
+ }
48242
+ ) })
48227
48243
  ] }),
48228
48244
  /* @__PURE__ */ jsx(
48229
48245
  motion.div,
48230
48246
  {
48231
- className: "mt-6 bg-blue-50 rounded-xl p-4",
48247
+ className: "mt-6 bg-muted rounded-xl p-4",
48232
48248
  variants: itemVariants,
48233
48249
  custom: 2,
48234
- children: /* @__PURE__ */ jsx("p", { className: "text-blue-800 text-sm leading-relaxed", children: "This automation will start automatically for any user who matches this criteria. When a user qualifies, their automation journey will begin immediately." })
48250
+ children: /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm leading-relaxed", children: automation2.description })
48235
48251
  }
48236
48252
  ),
48237
48253
  /* @__PURE__ */ jsx("div", { className: "mt-8", children: /* @__PURE__ */ jsx(
@@ -48278,7 +48294,8 @@ const useAutomationSteps = ({
48278
48294
  automation: automation2
48279
48295
  }
48280
48296
  )
48281
- }
48297
+ },
48298
+ "trigger"
48282
48299
  ),
48283
48300
  footerConfig: {
48284
48301
  backText: "Cancel",
@@ -48307,7 +48324,8 @@ const useAutomationSteps = ({
48307
48324
  automation: automation2
48308
48325
  }
48309
48326
  )
48310
- }
48327
+ },
48328
+ "audience"
48311
48329
  ),
48312
48330
  footerConfig: {
48313
48331
  backText: "Back",
@@ -48342,20 +48360,27 @@ const useAutomationSteps = ({
48342
48360
  }
48343
48361
  return true;
48344
48362
  },
48345
- content: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 w-full p-6 rounded-xl bg-gray-100 flex-1 h-full", children: [
48346
- /* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold", children: "Edit Content" }),
48347
- /* @__PURE__ */ jsx(
48348
- EditCampaignContent,
48349
- {
48350
- automation: automation2,
48351
- updateAutomation: updateAutomation2,
48352
- communicationGroup,
48353
- updateCommunicationGroup: updateCommunicationGroup2,
48354
- iconDefinitions,
48355
- getExtraMergeFields
48356
- }
48357
- )
48358
- ] }),
48363
+ content: /* @__PURE__ */ jsxs(
48364
+ "div",
48365
+ {
48366
+ className: "flex flex-col gap-4 w-full p-6 rounded-xl bg-gray-100 flex-1 h-full",
48367
+ children: [
48368
+ /* @__PURE__ */ jsx("h2", { className: "text-2xl font-semibold", children: "Edit Content" }),
48369
+ /* @__PURE__ */ jsx(
48370
+ EditCampaignContent,
48371
+ {
48372
+ automation: automation2,
48373
+ updateAutomation: updateAutomation2,
48374
+ communicationGroup,
48375
+ updateCommunicationGroup: updateCommunicationGroup2,
48376
+ iconDefinitions,
48377
+ getExtraMergeFields
48378
+ }
48379
+ )
48380
+ ]
48381
+ },
48382
+ "content"
48383
+ ),
48359
48384
  footerConfig: {
48360
48385
  backText: "Back",
48361
48386
  nextText: "Next",
@@ -48389,7 +48414,8 @@ const useAutomationSteps = ({
48389
48414
  communicationGroup
48390
48415
  }
48391
48416
  )
48392
- }
48417
+ },
48418
+ "send"
48393
48419
  ),
48394
48420
  footerConfig: {
48395
48421
  backText: "Back",