@embedreach/components 0.1.47 → 0.1.49

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.
@@ -33498,7 +33498,7 @@ const MultiSelect = React.forwardRef(
33498
33498
  children: "Close"
33499
33499
  }
33500
33500
  ),
33501
- extraCommandItems && extraCommandItems
33501
+ extraCommandItems && extraCommandItems.map((item) => item(setIsPopoverOpen))
33502
33502
  ] }) })
33503
33503
  ] })
33504
33504
  ] })
@@ -35043,9 +35043,10 @@ const styles$3 = {
35043
35043
  };
35044
35044
  const SegmentBuilder = ({
35045
35045
  onClose,
35046
- iconDefinitions,
35046
+ iconDefinitions: passedInIconDefinitions,
35047
35047
  segmentId
35048
35048
  }) => {
35049
+ const iconDefinitions = mergeIconDefinitions(passedInIconDefinitions);
35049
35050
  const SEGMENT_ID = segmentId || void 0;
35050
35051
  const { toast: toast2 } = useToast();
35051
35052
  const { segment: existingSegment } = useGetSegment(SEGMENT_ID);
@@ -35060,7 +35061,7 @@ const SegmentBuilder = ({
35060
35061
  });
35061
35062
  const [conditionNameToMetadata, setConditionNameToMetadata] = useState({});
35062
35063
  const isReadyToCreate = nameAndDescriptionState.name && nameAndDescriptionState.description && conditionState.some(
35063
- (condition) => condition.field && condition.operator && condition.value.length > 0
35064
+ (condition) => condition.field && condition.operator && (condition.operator === "exists" || condition.value.length > 0)
35064
35065
  );
35065
35066
  useEffect(() => {
35066
35067
  if (!segmentsConditions) return;
@@ -38827,7 +38828,7 @@ const MissingDataForPreview = ({
38827
38828
  ] });
38828
38829
  };
38829
38830
  const EmailPreviewHtmlRenderer = ({ html, height, width }) => {
38830
- return /* @__PURE__ */ jsx("div", { className: "w-full h-full min-h-[300px] bg-white rounded-lg border-0 overflow-hidden transition-all duration-300 ease-in-out", children: html ? /* @__PURE__ */ jsx(
38831
+ return /* @__PURE__ */ jsx("div", { className: "w-full h-full min-h-[300px] bg-white rounded-lg border-0 overflow-hidden transition-all duration-300 ease-in-out flex items-center justify-center", children: html ? /* @__PURE__ */ jsx(
38831
38832
  "iframe",
38832
38833
  {
38833
38834
  title: "Email Preview",
@@ -38849,7 +38850,27 @@ const EmailPreview$1 = ({
38849
38850
  emailBody,
38850
38851
  emailBaseDomain
38851
38852
  }) => {
38852
- return /* @__PURE__ */ jsxs("div", { className: "space-y-6 ", children: [
38853
+ const [emailPreviewDimensions, setEmailPreviewDimensions] = useState({
38854
+ width: 0,
38855
+ height: 0
38856
+ });
38857
+ const emailPreviewDiv = useRef(null);
38858
+ useEffect(() => {
38859
+ const updateHeight = () => {
38860
+ if (emailPreviewDiv.current) {
38861
+ requestAnimationFrame(() => {
38862
+ setEmailPreviewDimensions({
38863
+ width: emailPreviewDiv.current ? emailPreviewDiv.current.offsetWidth - 100 : 0,
38864
+ height: emailPreviewDiv.current ? emailPreviewDiv.current.offsetHeight - 100 : 0
38865
+ });
38866
+ });
38867
+ }
38868
+ };
38869
+ updateHeight();
38870
+ window.addEventListener("resize", updateHeight);
38871
+ return () => window.removeEventListener("resize", updateHeight);
38872
+ }, [emailPreviewDiv]);
38873
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-6 h-full", children: [
38853
38874
  /* @__PURE__ */ jsxs("div", { className: "bg-gray-50 p-5 rounded-lg space-y-4 border border-gray-100", children: [
38854
38875
  /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
38855
38876
  /* @__PURE__ */ jsx("span", { className: "font-medium text-gray-700 w-24", children: "From:" }),
@@ -38864,7 +38885,21 @@ const EmailPreview$1 = ({
38864
38885
  /* @__PURE__ */ jsx("span", { className: "text-gray-600 italic", children: emailPreviewText })
38865
38886
  ] })
38866
38887
  ] }),
38867
- /* @__PURE__ */ jsx("div", { className: "border rounded-lg p-6 min-h-[300px] bg-white shadow-inner flex", children: /* @__PURE__ */ jsx(EmailPreviewHtmlRenderer, { html: emailBody, height: 500, width: 500 }) })
38888
+ /* @__PURE__ */ jsx(
38889
+ "div",
38890
+ {
38891
+ className: "border rounded-lg p-6 bg-white shadow-inner flex-1 h-full w-full items-center justify-center",
38892
+ ref: emailPreviewDiv,
38893
+ children: /* @__PURE__ */ jsx(
38894
+ EmailPreviewHtmlRenderer,
38895
+ {
38896
+ html: emailBody,
38897
+ height: emailPreviewDimensions.height,
38898
+ width: emailPreviewDimensions.width
38899
+ }
38900
+ )
38901
+ }
38902
+ )
38868
38903
  ] });
38869
38904
  };
38870
38905
  const SMSPreview$1 = ({ fromPhone, body }) => {
@@ -38878,6 +38913,8 @@ const SMSPreview$1 = ({ fromPhone, body }) => {
38878
38913
  };
38879
38914
  const PreviewPanel = ({ emailPreview, smsPreview, iconDefinitions }) => {
38880
38915
  const [selectedTab, setSelectedTab] = useState("email");
38916
+ console.log(emailPreview);
38917
+ console.log(smsPreview);
38881
38918
  useEffect(() => {
38882
38919
  if (emailPreview) {
38883
38920
  setSelectedTab("email");
@@ -41075,8 +41112,8 @@ const EmailPreview = ({ automation }) => {
41075
41112
  if (emailPreviewDiv.current) {
41076
41113
  requestAnimationFrame(() => {
41077
41114
  setEmailPreviewDimensions({
41078
- width: emailPreviewDiv.current?.offsetWidth || 0,
41079
- height: emailPreviewDiv.current?.offsetHeight || 0
41115
+ width: emailPreviewDiv.current ? emailPreviewDiv.current.offsetWidth - 100 : 0,
41116
+ height: emailPreviewDiv.current ? emailPreviewDiv.current.offsetHeight - 100 : 0
41080
41117
  });
41081
41118
  });
41082
41119
  }
@@ -45958,7 +45995,7 @@ const SegmentSection = ({
45958
45995
  allSegments,
45959
45996
  onAddSegment,
45960
45997
  onRemoveSegment,
45961
- onCreateSegment,
45998
+ setOpenCreateSegmentDialog,
45962
45999
  iconDefinitions
45963
46000
  }) => {
45964
46001
  const handleValueChange = (newValues) => {
@@ -45967,54 +46004,43 @@ const SegmentSection = ({
45967
46004
  segmentsToAdd.forEach(onAddSegment);
45968
46005
  segmentsToRemove.forEach(onRemoveSegment);
45969
46006
  };
45970
- const [openSegmentBuilder, setOpenSegmentBuilder] = useState(false);
45971
46007
  const [segmentSelectedIds, setSegmentSelectedIds] = useState([]);
45972
46008
  const options = allSegments.map((segment) => ({
45973
46009
  label: segment.name,
45974
46010
  value: segment.id
45975
46011
  }));
45976
- return /* @__PURE__ */ jsxs("div", { children: [
45977
- /* @__PURE__ */ jsx(Dialog, { open: openSegmentBuilder, onOpenChange: setOpenSegmentBuilder, children: /* @__PURE__ */ jsx(DialogContent, { hideCloseButton: true, children: /* @__PURE__ */ jsx(
45978
- SegmentBuilder,
45979
- {
45980
- iconDefinitions,
45981
- onClose: (createdSegment) => {
45982
- if (createdSegment === "error") {
45983
- console.error("Error creating segment");
45984
- setOpenSegmentBuilder(false);
45985
- } else if (createdSegment === false) {
45986
- setOpenSegmentBuilder(false);
45987
- } else if (createdSegment) {
45988
- onCreateSegment();
45989
- setOpenSegmentBuilder(false);
45990
- }
45991
- }
45992
- }
45993
- ) }) }),
45994
- /* @__PURE__ */ jsx(
45995
- MultiSelect,
45996
- {
45997
- selectedValues: segmentSelectedIds,
45998
- setSelectedValues: setSegmentSelectedIds,
45999
- options,
46000
- defaultValue: segments,
46001
- onValueChange: handleValueChange,
46002
- placeholder: "Select segments",
46003
- maxCount: 5,
46004
- extraCommandItems: /* @__PURE__ */ jsxs(
46012
+ useEffect(() => {
46013
+ setSegmentSelectedIds(segments);
46014
+ }, [segments]);
46015
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
46016
+ MultiSelect,
46017
+ {
46018
+ selectedValues: segmentSelectedIds,
46019
+ setSelectedValues: setSegmentSelectedIds,
46020
+ options,
46021
+ defaultValue: segments,
46022
+ onValueChange: handleValueChange,
46023
+ placeholder: "Select segments",
46024
+ maxCount: 5,
46025
+ extraCommandItems: [
46026
+ (closePopup) => /* @__PURE__ */ jsxs(
46005
46027
  CommandItem,
46006
46028
  {
46007
- onSelect: () => setOpenSegmentBuilder(true),
46029
+ onSelect: () => {
46030
+ closePopup(false);
46031
+ setOpenCreateSegmentDialog(true);
46032
+ },
46008
46033
  className: "cursor-pointer",
46009
46034
  children: [
46010
46035
  /* @__PURE__ */ jsx(iconDefinitions.PlusIcon, { className: "w-4 h-4" }),
46011
46036
  "New"
46012
46037
  ]
46013
- }
46038
+ },
46039
+ "new-segment"
46014
46040
  )
46015
- }
46016
- )
46017
- ] });
46041
+ ]
46042
+ }
46043
+ ) });
46018
46044
  };
46019
46045
  const SelectSegments = ({
46020
46046
  iconDefinitions,
@@ -46022,7 +46048,7 @@ const SelectSegments = ({
46022
46048
  excludedSegments,
46023
46049
  handleAddSegment,
46024
46050
  handleRemoveSegment,
46025
- handleCreateSegment,
46051
+ setOpenCreateSegmentDialog,
46026
46052
  segments,
46027
46053
  defaultIsExcludeOpen = false
46028
46054
  }) => {
@@ -46035,7 +46061,7 @@ const SelectSegments = ({
46035
46061
  allSegments: segments?.segments || [],
46036
46062
  onAddSegment: (id2) => handleAddSegment(id2, "include"),
46037
46063
  onRemoveSegment: (id2) => handleRemoveSegment(id2, "include"),
46038
- onCreateSegment: handleCreateSegment,
46064
+ setOpenCreateSegmentDialog,
46039
46065
  iconDefinitions
46040
46066
  }
46041
46067
  ),
@@ -46075,7 +46101,7 @@ const SelectSegments = ({
46075
46101
  allSegments: segments?.segments || [],
46076
46102
  onAddSegment: (id2) => handleAddSegment(id2, "exclude"),
46077
46103
  onRemoveSegment: (id2) => handleRemoveSegment(id2, "exclude"),
46078
- onCreateSegment: handleCreateSegment,
46104
+ setOpenCreateSegmentDialog,
46079
46105
  iconDefinitions
46080
46106
  }
46081
46107
  )
@@ -46085,6 +46111,7 @@ const SelectSegments = ({
46085
46111
  ] });
46086
46112
  };
46087
46113
  const SelectAudience = ({ iconDefinitions, automation }) => {
46114
+ const { toast: toast2 } = useToast();
46088
46115
  const [openCreateSegmentDialog, setOpenCreateSegmentDialog] = React__default.useState(false);
46089
46116
  const [initialStateSet, setInitialStateSet] = React__default.useState(false);
46090
46117
  const { segments, isLoading, refetchSegments } = useListSegments();
@@ -46118,8 +46145,9 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46118
46145
  setExcludedSegments((prev) => prev.filter((id2) => id2 !== segmentId));
46119
46146
  }
46120
46147
  };
46121
- const handleCreateSegment = () => {
46122
- setOpenCreateSegmentDialog(true);
46148
+ const handleCreateSegment = (segmentId) => {
46149
+ refetchSegments();
46150
+ setIncludedSegments((prev) => [...prev, segmentId]);
46123
46151
  };
46124
46152
  useEffect(() => {
46125
46153
  const hasSegmentsChanged = JSON.stringify(automation.includeSegmentIds) !== JSON.stringify(includedSegments) || JSON.stringify(automation.excludeSegmentIds) !== JSON.stringify(excludedSegments);
@@ -46169,6 +46197,8 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46169
46197
  setInitialStateSet(true);
46170
46198
  return;
46171
46199
  }
46200
+ console.log("automation.includeSegmentIds", automation.includeSegmentIds);
46201
+ console.log("automation.excludeSegmentIds", automation.excludeSegmentIds);
46172
46202
  if (allUsersSelected) {
46173
46203
  setSelectedAudience("all");
46174
46204
  } else {
@@ -46184,8 +46214,8 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46184
46214
  allUsersSelected,
46185
46215
  getAllUsersSegment,
46186
46216
  updateAutomation2,
46187
- automation.includeSegmentIds.length,
46188
- automation.excludeSegmentIds.length
46217
+ automation.includeSegmentIds,
46218
+ automation.excludeSegmentIds
46189
46219
  ]);
46190
46220
  if (isLoading || !segments || !initialStateSet) {
46191
46221
  return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(SpinLoader, { text: ["Fetching segments", "Finishing up"] }) });
@@ -46195,19 +46225,35 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46195
46225
  Dialog,
46196
46226
  {
46197
46227
  open: openCreateSegmentDialog,
46228
+ modal: true,
46198
46229
  onOpenChange: setOpenCreateSegmentDialog,
46199
- children: /* @__PURE__ */ jsx(DialogContent, { className: "max-w-4xl", children: /* @__PURE__ */ jsx(
46200
- SegmentBuilder,
46201
- {
46202
- iconDefinitions,
46203
- onClose: (result) => {
46204
- if (result !== false && result !== "error") {
46205
- refetchSegments();
46230
+ children: /* @__PURE__ */ jsxs(DialogContent, { hideCloseButton: true, children: [
46231
+ /* @__PURE__ */ jsxs(VisuallyHidden, { children: [
46232
+ /* @__PURE__ */ jsx(DialogTitle, { children: "Create Segment" }),
46233
+ /* @__PURE__ */ jsx(DialogDescription, { children: "Create a new segment to use in your automation." })
46234
+ ] }),
46235
+ /* @__PURE__ */ jsx(
46236
+ SegmentBuilder,
46237
+ {
46238
+ iconDefinitions,
46239
+ onClose: (createdSegment) => {
46240
+ if (createdSegment === "error") {
46241
+ toast2({
46242
+ title: "Error creating segment",
46243
+ description: "Please try again",
46244
+ variant: "destructive"
46245
+ });
46246
+ setOpenCreateSegmentDialog(false);
46247
+ } else if (createdSegment === false) {
46248
+ setOpenCreateSegmentDialog(false);
46249
+ } else if (createdSegment) {
46250
+ handleCreateSegment(createdSegment);
46251
+ setOpenCreateSegmentDialog(false);
46252
+ }
46206
46253
  }
46207
- setOpenCreateSegmentDialog(false);
46208
46254
  }
46209
- }
46210
- ) })
46255
+ )
46256
+ ] })
46211
46257
  }
46212
46258
  ),
46213
46259
  /* @__PURE__ */ jsx("div", { className: " w-full", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-8", children: [
@@ -46244,7 +46290,7 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46244
46290
  excludedSegments,
46245
46291
  handleAddSegment,
46246
46292
  handleRemoveSegment,
46247
- handleCreateSegment,
46293
+ setOpenCreateSegmentDialog,
46248
46294
  segments,
46249
46295
  defaultIsExcludeOpen: automation.excludeSegmentIds?.length > 0
46250
46296
  }
@@ -46844,7 +46890,7 @@ const ViewAutomationHeader = ({
46844
46890
  /* @__PURE__ */ jsx(iconDefinitions.DropdownMenuTrigger, { className: "ml-2 h-4 w-4" })
46845
46891
  ] }) }),
46846
46892
  /* @__PURE__ */ jsxs(DropdownMenuContent, { children: [
46847
- (automation.status === AutomationStatus.DRAFT || automation.status === AutomationStatus.ACTIVE) && /* @__PURE__ */ jsx(
46893
+ automation.status === AutomationStatus.DRAFT && /* @__PURE__ */ jsx(
46848
46894
  DropdownMenuItem,
46849
46895
  {
46850
46896
  onClick: () => setOpenEditAutomationPopup(true),
@@ -46909,12 +46955,13 @@ const ViewAutomationHeader = ({
46909
46955
  ] });
46910
46956
  };
46911
46957
  const ViewAutomationModalContent = ({
46912
- iconDefinitions,
46958
+ iconDefinitions: passedInIconDefinitions,
46913
46959
  autoOpenEditPopup,
46914
46960
  automationId,
46915
46961
  showBackButton = false,
46916
46962
  logoUrl
46917
46963
  }) => {
46964
+ const iconDefinitions = mergeIconDefinitions(passedInIconDefinitions);
46918
46965
  const params = useParams();
46919
46966
  const [searchParams] = useSearchParams();
46920
46967
  const FINAL_AUTOMATION_ID = automationId || params?.automationId || searchParams.get("automationId");
package/dist/index.d.ts CHANGED
@@ -14,11 +14,11 @@ declare interface CreateAutomationModalProps {
14
14
  /**
15
15
  * Optional keys to override the default icon definitions
16
16
  */
17
- iconDefinitions?: IconDefinitionsType;
17
+ iconDefinitions?: Partial<IconDefinitionsType>;
18
18
  }
19
19
 
20
20
  export declare const Engage: default_2.FC<{
21
- iconDefinitions: IconDefinitionsType;
21
+ iconDefinitions: Partial<IconDefinitionsType>;
22
22
  }>;
23
23
 
24
24
  /**
@@ -120,7 +120,7 @@ declare interface SegmentBuilderProps {
120
120
  /**
121
121
  * Optional keys to override the default icon definitions
122
122
  */
123
- iconDefinitions?: IconDefinitionsType;
123
+ iconDefinitions?: Partial<IconDefinitionsType>;
124
124
  }
125
125
 
126
126
  /**