@embedreach/components 0.2.13 → 0.2.14

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.
@@ -6,6 +6,7 @@ import ReactDOM__default from "react-dom";
6
6
  const BUSINESS_PATH = "/businesses/me";
7
7
  const BUSINESS_SEGMENT_PATH = "/segments";
8
8
  const BUSINESS_AUTOMATION_PATH = "/automations";
9
+ const BUSINESS_AUTOMATION_INTERNAL_PATH = "/automations/internal";
9
10
  const WEB_PRESENCE_PATH = "/web-presence";
10
11
  const WEBSITE_BRAND_SETTINGS_PATH = `${WEB_PRESENCE_PATH}/brand-settings`;
11
12
  const CHANNEL_SENDER_PATH = "/channel/senders";
@@ -2621,7 +2622,14 @@ const createQueryClient = () => new QueryClient({
2621
2622
  const automationKeys = {
2622
2623
  all: ["automations"],
2623
2624
  single: (id2) => [...automationKeys.all, id2],
2624
- recipients: (id2) => [...automationKeys.all, id2, "recipients"],
2625
+ sentCommunications: (args) => [
2626
+ ...automationKeys.all,
2627
+ args.automationId,
2628
+ "sentCommunications",
2629
+ ...args.cursor ? [args.cursor] : [],
2630
+ ...args.limit ? [args.limit] : [],
2631
+ ...args.search ? [args.search] : []
2632
+ ],
2625
2633
  statistics: (id2) => [...automationKeys.all, id2, "statistics"],
2626
2634
  list: (args) => [
2627
2635
  ...automationKeys.all,
@@ -2649,10 +2657,21 @@ const getAutomation = async (automationId) => {
2649
2657
  );
2650
2658
  return response.data;
2651
2659
  };
2652
- const getAutomationRecipients = async (automationId) => {
2653
- const response = await baseRequest(
2654
- `${BUSINESS_AUTOMATION_PATH}/${automationId}/recipients`
2655
- );
2660
+ const getSentCommunications = async (args) => {
2661
+ const params = new URLSearchParams();
2662
+ if (args.cursor) {
2663
+ params.append("cursor", args.cursor);
2664
+ }
2665
+ if (args.limit) {
2666
+ params.append("limit", args.limit.toString());
2667
+ }
2668
+ if (args.search) {
2669
+ params.append("search", args.search);
2670
+ }
2671
+ const url = `${BUSINESS_AUTOMATION_INTERNAL_PATH}/${args.automationId}/sent${params.toString() ? `?${params.toString()}` : ""}`;
2672
+ const response = await baseRequest(url, {
2673
+ method: "GET"
2674
+ });
2656
2675
  return response.data;
2657
2676
  };
2658
2677
  const updateAutomation = async (id2, params) => {
@@ -2736,18 +2755,30 @@ const useGetBusinessAutomation = (automationId) => {
2736
2755
  })
2737
2756
  };
2738
2757
  };
2739
- const useGetBusinessAutomationRecipients = (automationId) => {
2740
- const getAutomationRecipientsQuery = useQuery({
2741
- queryKey: automationKeys.recipients(automationId),
2742
- queryFn: () => getAutomationRecipients(automationId)
2758
+ const useGetBusinessAutomationSentCommunications = (args) => {
2759
+ const getSentCommunicationsQuery = useQuery({
2760
+ queryKey: automationKeys.sentCommunications(args),
2761
+ queryFn: () => getSentCommunications(args),
2762
+ // placeholderData: keepPreviousData is a powerful feature from TanStack Query.
2763
+ // What it does:
2764
+ // 1. When new data is being fetched for a query (e.g., due to a queryKey change like a new cursor),
2765
+ // TanStack Query will continue to show the data from the previous successful fetch (the "placeholder" data)
2766
+ // until the new data arrives.
2767
+ // 2. While this placeholder data is being shown, `isPlaceholderData` will be true.
2768
+ // 3. `isLoading` will only be true if there's no data at all (initial fetch or hard refresh with no cache).
2769
+ // It will be false if placeholder data is being shown, even though a new fetch is in progress (`isFetching` will be true).
2770
+ // This provides a much smoother UX, as the UI doesn't jump to a loading state on pagination or filter changes
2771
+ // if previous data is available to show in the meantime.
2772
+ placeholderData: keepPreviousData
2743
2773
  });
2744
2774
  return {
2745
- // Get automation recipients query
2746
- recipients: getAutomationRecipientsQuery.data,
2747
- isFetching: getAutomationRecipientsQuery.isFetching,
2748
- isLoading: getAutomationRecipientsQuery.isLoading,
2749
- fetchError: getAutomationRecipientsQuery.error,
2750
- refetchAutomationRecipients: getAutomationRecipientsQuery.refetch
2775
+ // Get automation sent communications query
2776
+ sentCommunications: getSentCommunicationsQuery.data,
2777
+ isFetching: getSentCommunicationsQuery.isFetching,
2778
+ isLoading: getSentCommunicationsQuery.isLoading,
2779
+ isPlaceholderData: getSentCommunicationsQuery.isPlaceholderData,
2780
+ fetchError: getSentCommunicationsQuery.error,
2781
+ refetchSentCommunications: getSentCommunicationsQuery.refetch
2751
2782
  };
2752
2783
  };
2753
2784
  const useCreateBusinessAutomation = () => {
@@ -2852,6 +2883,11 @@ var AutomationStatus = /* @__PURE__ */ ((AutomationStatus2) => {
2852
2883
  AutomationStatus2["DEACTIVATED"] = "deactivated";
2853
2884
  return AutomationStatus2;
2854
2885
  })(AutomationStatus || {});
2886
+ var ChannelIntegrationTypeEnum = /* @__PURE__ */ ((ChannelIntegrationTypeEnum2) => {
2887
+ ChannelIntegrationTypeEnum2["EMAIL"] = "email";
2888
+ ChannelIntegrationTypeEnum2["SMS"] = "sms";
2889
+ return ChannelIntegrationTypeEnum2;
2890
+ })(ChannelIntegrationTypeEnum || {});
2855
2891
  var sharedConfig = {
2856
2892
  context: void 0,
2857
2893
  registry: void 0,
@@ -64546,12 +64582,6 @@ const EditCampaignContent = ({
64546
64582
  }
64547
64583
  });
64548
64584
  } else {
64549
- if (communicationGroup?.id && communicationGroup.extraMergeFields !== null) {
64550
- updateCommunicationGroup2({
64551
- groupId: communicationGroup?.id,
64552
- params: { extraMergeFields: null }
64553
- });
64554
- }
64555
64585
  setMergeFieldsResponse(getMergeFields$1);
64556
64586
  }
64557
64587
  }, [
@@ -81959,13 +81989,13 @@ const useAutomationStatusToggle = (id2) => {
81959
81989
  }, [isUpdateSuccess, updateError, toast2]);
81960
81990
  return { toggleStatus };
81961
81991
  };
81962
- const DEFAULT_PAGE_SIZE$2 = 10;
81992
+ const DEFAULT_PAGE_SIZE$3 = 10;
81963
81993
  function AutomationList() {
81964
81994
  const { toast: toast2 } = useToast();
81965
81995
  const [updatingId, setUpdatingId] = useState(null);
81966
81996
  const { toggleStatus } = useAutomationStatusToggle(updatingId || "");
81967
81997
  const navigate = useNavigate();
81968
- const [pageSizeForQuery, setPageSizeForQuery] = useState(DEFAULT_PAGE_SIZE$2);
81998
+ const [pageSizeForQuery, setPageSizeForQuery] = useState(DEFAULT_PAGE_SIZE$3);
81969
81999
  const [cursorForQuery, setCursorForQuery] = useState(
81970
82000
  void 0
81971
82001
  );
@@ -82055,14 +82085,14 @@ function AutomationList() {
82055
82085
  }
82056
82086
  ) }) });
82057
82087
  }
82058
- const DEFAULT_PAGE_SIZE$1 = 10;
82088
+ const DEFAULT_PAGE_SIZE$2 = 10;
82059
82089
  function BroadcastList() {
82060
82090
  const { toast: toast2 } = useToast();
82061
82091
  const [createDialogOpen, setCreateDialogOpen] = useState(false);
82062
82092
  const [updatingId, setUpdatingId] = useState(null);
82063
82093
  const { toggleStatus } = useAutomationStatusToggle(updatingId || "");
82064
82094
  const navigate = useNavigate();
82065
- const [pageSizeForQuery, setPageSizeForQuery] = useState(DEFAULT_PAGE_SIZE$1);
82095
+ const [pageSizeForQuery, setPageSizeForQuery] = useState(DEFAULT_PAGE_SIZE$2);
82066
82096
  const [cursorForQuery, setCursorForQuery] = useState(
82067
82097
  void 0
82068
82098
  );
@@ -82116,7 +82146,7 @@ function BroadcastList() {
82116
82146
  );
82117
82147
  const resetListPagination = () => {
82118
82148
  setCursorForQuery(void 0);
82119
- setPageSizeForQuery(DEFAULT_PAGE_SIZE$1);
82149
+ setPageSizeForQuery(DEFAULT_PAGE_SIZE$2);
82120
82150
  setSearchQuery("");
82121
82151
  };
82122
82152
  const onDialogClose = (result) => {
@@ -82184,12 +82214,12 @@ function BroadcastList() {
82184
82214
  )
82185
82215
  ] });
82186
82216
  }
82187
- const DEFAULT_PAGE_SIZE = 10;
82217
+ const DEFAULT_PAGE_SIZE$1 = 10;
82188
82218
  function SegmentList() {
82189
82219
  const { toast: toast2 } = useToast();
82190
82220
  const [createDialogOpen, setCreateDialogOpen] = useState(false);
82191
82221
  const [selectedSegment, setSelectedSegment] = useState(null);
82192
- const [pageSizeForQuery, setPageSizeForQuery] = useState(DEFAULT_PAGE_SIZE);
82222
+ const [pageSizeForQuery, setPageSizeForQuery] = useState(DEFAULT_PAGE_SIZE$1);
82193
82223
  const [cursorForQuery, setCursorForQuery] = useState(
82194
82224
  void 0
82195
82225
  );
@@ -82243,7 +82273,7 @@ function SegmentList() {
82243
82273
  );
82244
82274
  const resetListPagination = () => {
82245
82275
  setCursorForQuery(void 0);
82246
- setPageSizeForQuery(DEFAULT_PAGE_SIZE);
82276
+ setPageSizeForQuery(DEFAULT_PAGE_SIZE$1);
82247
82277
  setSearchQuery("");
82248
82278
  };
82249
82279
  const onDialogClose = (result) => {
@@ -82873,14 +82903,59 @@ const AutomationsEditorStatsTab = ({ hideSms, hideSales }) => {
82873
82903
  }
82874
82904
  ) });
82875
82905
  };
82876
- const AutomationsEditorRecipientsTab = () => {
82906
+ const DEFAULT_PAGE_SIZE = 10;
82907
+ const AutomationRecipientsTable = () => {
82877
82908
  const automation2 = useAutomation();
82909
+ const [pageSizeForQuery, setPageSizeForQuery] = useState(DEFAULT_PAGE_SIZE);
82910
+ const [cursorForQuery, setCursorForQuery] = useState(
82911
+ void 0
82912
+ );
82913
+ const [searchQuery, setSearchQuery] = useState("");
82878
82914
  const {
82879
- recipients,
82915
+ sentCommunications,
82880
82916
  isLoading: isLoadingRecipients,
82917
+ isFetching,
82918
+ isPlaceholderData,
82881
82919
  fetchError
82882
- } = useGetBusinessAutomationRecipients(automation2?.id ?? "");
82920
+ } = useGetBusinessAutomationSentCommunications({
82921
+ automationId: automation2?.id ?? "",
82922
+ cursor: cursorForQuery,
82923
+ limit: pageSizeForQuery,
82924
+ search: searchQuery || void 0
82925
+ });
82926
+ const handleQueryParametersChange = useCallback(
82927
+ (params) => {
82928
+ setCursorForQuery(params.cursor);
82929
+ setPageSizeForQuery(params.pageSize);
82930
+ },
82931
+ []
82932
+ );
82883
82933
  const columns = [
82934
+ {
82935
+ accessorKey: "communicationsSent",
82936
+ id: "lastCommunication",
82937
+ header: "Updated At",
82938
+ cell: ({ row }) => {
82939
+ const communications = row.original.communicationsSent || [];
82940
+ if (communications.length === 0) {
82941
+ return /* @__PURE__ */ jsx("span", { className: "text-gray-400", children: "None" });
82942
+ }
82943
+ const latestCommunication = communications.reduce(
82944
+ (latest, current) => {
82945
+ if (!latest || !latest.updatedAt) return current;
82946
+ if (!current.updatedAt) return latest;
82947
+ return new Date(current.updatedAt) > new Date(latest.updatedAt) ? current : latest;
82948
+ }
82949
+ );
82950
+ if (!latestCommunication?.updatedAt) {
82951
+ return /* @__PURE__ */ jsx("span", { className: "text-gray-400", children: "Not available" });
82952
+ }
82953
+ return /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx("span", { className: "text-sm text-gray-600", children: format$1(
82954
+ new Date(latestCommunication.updatedAt),
82955
+ "MMM d, yyyy h:mm a"
82956
+ ) }) });
82957
+ }
82958
+ },
82884
82959
  {
82885
82960
  accessorFn: (row) => `${row.firstName || ""} ${row.lastName || ""}`.trim(),
82886
82961
  id: "name",
@@ -82901,9 +82976,73 @@ const AutomationsEditorRecipientsTab = () => {
82901
82976
  accessorKey: "phone",
82902
82977
  header: "Phone",
82903
82978
  cell: ({ row }) => row.original.phone || /* @__PURE__ */ jsx("span", { className: "text-gray-400", children: "Not provided" })
82979
+ },
82980
+ {
82981
+ accessorKey: "communicationsSent",
82982
+ id: "communicationsSent",
82983
+ header: "Communications Sent",
82984
+ cell: ({ row }) => {
82985
+ const communications = row.original.communicationsSent || [];
82986
+ const emailCommunications = communications.filter(
82987
+ (c2) => c2.type === ChannelIntegrationTypeEnum.EMAIL
82988
+ );
82989
+ const smsCommunications = communications.filter(
82990
+ (c2) => c2.type === ChannelIntegrationTypeEnum.SMS
82991
+ );
82992
+ const hasEmail = emailCommunications.length > 0;
82993
+ const hasSms = smsCommunications.length > 0;
82994
+ const emailDelivered = emailCommunications.some((c2) => c2.delivered);
82995
+ const smsDelivered = smsCommunications.some((c2) => c2.delivered);
82996
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
82997
+ hasEmail && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
82998
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
82999
+ /* @__PURE__ */ jsx(
83000
+ IconDefinitions.EmailIcon,
83001
+ {
83002
+ className: `h-4 w-4 ${emailDelivered ? "text-green-500" : "text-gray-400"}`
83003
+ }
83004
+ ),
83005
+ emailDelivered && /* @__PURE__ */ jsx("div", { className: "absolute -right-1 -top-1 h-2 w-2 rounded-full bg-green-500 ring-1 ring-white" })
83006
+ ] }),
83007
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
83008
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "Email" }),
83009
+ /* @__PURE__ */ jsx(
83010
+ "span",
83011
+ {
83012
+ className: `text-xs ${emailDelivered ? "text-green-600" : "text-gray-500"}`,
83013
+ children: emailDelivered ? "Delivered" : "Pending"
83014
+ }
83015
+ )
83016
+ ] })
83017
+ ] }),
83018
+ hasEmail && hasSms && /* @__PURE__ */ jsx("div", { className: "h-8 w-px bg-gray-200" }),
83019
+ hasSms && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
83020
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
83021
+ /* @__PURE__ */ jsx(
83022
+ IconDefinitions.SmsIcon,
83023
+ {
83024
+ className: `h-4 w-4 ${smsDelivered ? "text-green-500" : "text-gray-400"}`
83025
+ }
83026
+ ),
83027
+ smsDelivered && /* @__PURE__ */ jsx("div", { className: "absolute -right-1 -top-1 h-2 w-2 rounded-full bg-green-500 ring-1 ring-white" })
83028
+ ] }),
83029
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
83030
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "SMS" }),
83031
+ /* @__PURE__ */ jsx(
83032
+ "span",
83033
+ {
83034
+ className: `text-xs ${smsDelivered ? "text-green-600" : "text-gray-500"}`,
83035
+ children: smsDelivered ? "Delivered" : "Pending"
83036
+ }
83037
+ )
83038
+ ] })
83039
+ ] }),
83040
+ !hasEmail && !hasSms && /* @__PURE__ */ jsx("span", { className: "text-sm text-gray-400", children: "None" })
83041
+ ] });
83042
+ }
82904
83043
  }
82905
83044
  ];
82906
- if (!automation2 || isLoadingRecipients || !recipients) {
83045
+ if (!automation2 || isLoadingRecipients || !sentCommunications) {
82907
83046
  return /* @__PURE__ */ jsx(BasicLoader, { text: ["Fetching Recipients", "Finishing up"] });
82908
83047
  }
82909
83048
  if (fetchError) {
@@ -82912,31 +83051,56 @@ const AutomationsEditorRecipientsTab = () => {
82912
83051
  fetchError.message
82913
83052
  ] });
82914
83053
  }
82915
- if (!recipients || recipients.recipients.length === 0) {
83054
+ if (!sentCommunications || !searchQuery && sentCommunications.results.length === 0) {
82916
83055
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center p-8 text-center", children: [
82917
83056
  /* @__PURE__ */ jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsx(IconDefinitions.UserIcon, { className: "h-12 w-12 text-gray-400" }) }),
82918
- /* @__PURE__ */ jsx("h3", { className: "mb-2 text-lg font-semibold text-gray-700", children: "No Recipients Found" }),
83057
+ /* @__PURE__ */ jsx("h3", { className: "mb-2 text-lg font-semibold text-gray-700", children: "No Communications Sent Yet" }),
82919
83058
  /* @__PURE__ */ jsxs("p", { className: "text-gray-500", children: [
82920
- "This ",
82921
- t$1("engage:automation"),
82922
- " currently has no assigned recipients. Please update the include or exclude",
83059
+ "This",
83060
+ " ",
83061
+ automation2.triggerType === AutomationTriggerType.ONE_TIME ? t$1("engage:one_time") : t$1("engage:automation"),
82923
83062
  " ",
82924
- t$1("engage:segment", { count: 2 }),
82925
- " to add recipients."
83063
+ "hasn't sent any communications yet. Please check back later to see recipient details once communications have been sent."
82926
83064
  ] })
82927
83065
  ] });
82928
83066
  }
82929
83067
  return /* @__PURE__ */ jsx("div", { className: "h-full p-4", children: /* @__PURE__ */ jsx(
82930
83068
  TanstackTable,
82931
83069
  {
82932
- data: recipients.recipients,
83070
+ data: sentCommunications.results,
82933
83071
  columns,
82934
- paginationMode: "standard",
82935
- initialPageSize: 10,
82936
- isLoading: isLoadingRecipients
83072
+ paginationMode: "cursor",
83073
+ initialPageSize: pageSizeForQuery,
83074
+ isLoading: isLoadingRecipients && !isPlaceholderData,
83075
+ cursorPaginationQueryResult: {
83076
+ nextCursor: sentCommunications.pagination.cursor,
83077
+ isLoading: isLoadingRecipients,
83078
+ isFetching,
83079
+ isPlaceholderData
83080
+ },
83081
+ onQueryParametersChange: handleQueryParametersChange,
83082
+ searchValue: searchQuery,
83083
+ onSearchChange: setSearchQuery
82937
83084
  }
82938
83085
  ) });
82939
83086
  };
83087
+ const AutomationsEditorRecipientsTab = () => {
83088
+ const automation2 = useAutomation();
83089
+ if (automation2?.triggerType === AutomationTriggerType.ONE_TIME && automation2?.status === AutomationStatus.DRAFT) {
83090
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center p-8 text-center", children: [
83091
+ /* @__PURE__ */ jsx("div", { className: "mb-4", children: /* @__PURE__ */ jsx(IconDefinitions.UserIcon, { className: "h-12 w-12 text-gray-400" }) }),
83092
+ /* @__PURE__ */ jsx("h3", { className: "mb-2 text-lg font-semibold text-gray-700", children: "No Recipients Available Yet" }),
83093
+ /* @__PURE__ */ jsxs("p", { className: "text-gray-500", children: [
83094
+ "Recipients will be available once this",
83095
+ " ",
83096
+ automation2.triggerType === AutomationTriggerType.ONE_TIME ? t$1("engage:one_time") : t$1("engage:automation"),
83097
+ " ",
83098
+ "has completed running. Please check back after the automation has finished."
83099
+ ] })
83100
+ ] });
83101
+ }
83102
+ return /* @__PURE__ */ jsx(AutomationRecipientsTable, {});
83103
+ };
82940
83104
  const PanelGroupContext = createContext$1(null);
82941
83105
  PanelGroupContext.displayName = "PanelGroupContext";
82942
83106
  const DATA_ATTRIBUTES = {