@embedreach/components 0.1.47 → 0.1.48

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 }) => {
@@ -41075,8 +41110,8 @@ const EmailPreview = ({ automation }) => {
41075
41110
  if (emailPreviewDiv.current) {
41076
41111
  requestAnimationFrame(() => {
41077
41112
  setEmailPreviewDimensions({
41078
- width: emailPreviewDiv.current?.offsetWidth || 0,
41079
- height: emailPreviewDiv.current?.offsetHeight || 0
41113
+ width: emailPreviewDiv.current ? emailPreviewDiv.current.offsetWidth - 100 : 0,
41114
+ height: emailPreviewDiv.current ? emailPreviewDiv.current.offsetHeight - 100 : 0
41080
41115
  });
41081
41116
  });
41082
41117
  }
@@ -45958,7 +45993,7 @@ const SegmentSection = ({
45958
45993
  allSegments,
45959
45994
  onAddSegment,
45960
45995
  onRemoveSegment,
45961
- onCreateSegment,
45996
+ setOpenCreateSegmentDialog,
45962
45997
  iconDefinitions
45963
45998
  }) => {
45964
45999
  const handleValueChange = (newValues) => {
@@ -45967,54 +46002,43 @@ const SegmentSection = ({
45967
46002
  segmentsToAdd.forEach(onAddSegment);
45968
46003
  segmentsToRemove.forEach(onRemoveSegment);
45969
46004
  };
45970
- const [openSegmentBuilder, setOpenSegmentBuilder] = useState(false);
45971
46005
  const [segmentSelectedIds, setSegmentSelectedIds] = useState([]);
45972
46006
  const options = allSegments.map((segment) => ({
45973
46007
  label: segment.name,
45974
46008
  value: segment.id
45975
46009
  }));
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(
46010
+ useEffect(() => {
46011
+ setSegmentSelectedIds(segments);
46012
+ }, [segments]);
46013
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
46014
+ MultiSelect,
46015
+ {
46016
+ selectedValues: segmentSelectedIds,
46017
+ setSelectedValues: setSegmentSelectedIds,
46018
+ options,
46019
+ defaultValue: segments,
46020
+ onValueChange: handleValueChange,
46021
+ placeholder: "Select segments",
46022
+ maxCount: 5,
46023
+ extraCommandItems: [
46024
+ (closePopup) => /* @__PURE__ */ jsxs(
46005
46025
  CommandItem,
46006
46026
  {
46007
- onSelect: () => setOpenSegmentBuilder(true),
46027
+ onSelect: () => {
46028
+ closePopup(false);
46029
+ setOpenCreateSegmentDialog(true);
46030
+ },
46008
46031
  className: "cursor-pointer",
46009
46032
  children: [
46010
46033
  /* @__PURE__ */ jsx(iconDefinitions.PlusIcon, { className: "w-4 h-4" }),
46011
46034
  "New"
46012
46035
  ]
46013
- }
46036
+ },
46037
+ "new-segment"
46014
46038
  )
46015
- }
46016
- )
46017
- ] });
46039
+ ]
46040
+ }
46041
+ ) });
46018
46042
  };
46019
46043
  const SelectSegments = ({
46020
46044
  iconDefinitions,
@@ -46022,7 +46046,7 @@ const SelectSegments = ({
46022
46046
  excludedSegments,
46023
46047
  handleAddSegment,
46024
46048
  handleRemoveSegment,
46025
- handleCreateSegment,
46049
+ setOpenCreateSegmentDialog,
46026
46050
  segments,
46027
46051
  defaultIsExcludeOpen = false
46028
46052
  }) => {
@@ -46035,7 +46059,7 @@ const SelectSegments = ({
46035
46059
  allSegments: segments?.segments || [],
46036
46060
  onAddSegment: (id2) => handleAddSegment(id2, "include"),
46037
46061
  onRemoveSegment: (id2) => handleRemoveSegment(id2, "include"),
46038
- onCreateSegment: handleCreateSegment,
46062
+ setOpenCreateSegmentDialog,
46039
46063
  iconDefinitions
46040
46064
  }
46041
46065
  ),
@@ -46075,7 +46099,7 @@ const SelectSegments = ({
46075
46099
  allSegments: segments?.segments || [],
46076
46100
  onAddSegment: (id2) => handleAddSegment(id2, "exclude"),
46077
46101
  onRemoveSegment: (id2) => handleRemoveSegment(id2, "exclude"),
46078
- onCreateSegment: handleCreateSegment,
46102
+ setOpenCreateSegmentDialog,
46079
46103
  iconDefinitions
46080
46104
  }
46081
46105
  )
@@ -46085,6 +46109,7 @@ const SelectSegments = ({
46085
46109
  ] });
46086
46110
  };
46087
46111
  const SelectAudience = ({ iconDefinitions, automation }) => {
46112
+ const { toast: toast2 } = useToast();
46088
46113
  const [openCreateSegmentDialog, setOpenCreateSegmentDialog] = React__default.useState(false);
46089
46114
  const [initialStateSet, setInitialStateSet] = React__default.useState(false);
46090
46115
  const { segments, isLoading, refetchSegments } = useListSegments();
@@ -46118,8 +46143,9 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46118
46143
  setExcludedSegments((prev) => prev.filter((id2) => id2 !== segmentId));
46119
46144
  }
46120
46145
  };
46121
- const handleCreateSegment = () => {
46122
- setOpenCreateSegmentDialog(true);
46146
+ const handleCreateSegment = (segmentId) => {
46147
+ refetchSegments();
46148
+ setIncludedSegments((prev) => [...prev, segmentId]);
46123
46149
  };
46124
46150
  useEffect(() => {
46125
46151
  const hasSegmentsChanged = JSON.stringify(automation.includeSegmentIds) !== JSON.stringify(includedSegments) || JSON.stringify(automation.excludeSegmentIds) !== JSON.stringify(excludedSegments);
@@ -46169,6 +46195,8 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46169
46195
  setInitialStateSet(true);
46170
46196
  return;
46171
46197
  }
46198
+ console.log("automation.includeSegmentIds", automation.includeSegmentIds);
46199
+ console.log("automation.excludeSegmentIds", automation.excludeSegmentIds);
46172
46200
  if (allUsersSelected) {
46173
46201
  setSelectedAudience("all");
46174
46202
  } else {
@@ -46184,8 +46212,8 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46184
46212
  allUsersSelected,
46185
46213
  getAllUsersSegment,
46186
46214
  updateAutomation2,
46187
- automation.includeSegmentIds.length,
46188
- automation.excludeSegmentIds.length
46215
+ automation.includeSegmentIds,
46216
+ automation.excludeSegmentIds
46189
46217
  ]);
46190
46218
  if (isLoading || !segments || !initialStateSet) {
46191
46219
  return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(SpinLoader, { text: ["Fetching segments", "Finishing up"] }) });
@@ -46195,19 +46223,35 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46195
46223
  Dialog,
46196
46224
  {
46197
46225
  open: openCreateSegmentDialog,
46226
+ modal: true,
46198
46227
  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();
46228
+ children: /* @__PURE__ */ jsxs(DialogContent, { hideCloseButton: true, children: [
46229
+ /* @__PURE__ */ jsxs(VisuallyHidden, { children: [
46230
+ /* @__PURE__ */ jsx(DialogTitle, { children: "Create Segment" }),
46231
+ /* @__PURE__ */ jsx(DialogDescription, { children: "Create a new segment to use in your automation." })
46232
+ ] }),
46233
+ /* @__PURE__ */ jsx(
46234
+ SegmentBuilder,
46235
+ {
46236
+ iconDefinitions,
46237
+ onClose: (createdSegment) => {
46238
+ if (createdSegment === "error") {
46239
+ toast2({
46240
+ title: "Error creating segment",
46241
+ description: "Please try again",
46242
+ variant: "destructive"
46243
+ });
46244
+ setOpenCreateSegmentDialog(false);
46245
+ } else if (createdSegment === false) {
46246
+ setOpenCreateSegmentDialog(false);
46247
+ } else if (createdSegment) {
46248
+ handleCreateSegment(createdSegment);
46249
+ setOpenCreateSegmentDialog(false);
46250
+ }
46206
46251
  }
46207
- setOpenCreateSegmentDialog(false);
46208
46252
  }
46209
- }
46210
- ) })
46253
+ )
46254
+ ] })
46211
46255
  }
46212
46256
  ),
46213
46257
  /* @__PURE__ */ jsx("div", { className: " w-full", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-8", children: [
@@ -46244,7 +46288,7 @@ const SelectAudience = ({ iconDefinitions, automation }) => {
46244
46288
  excludedSegments,
46245
46289
  handleAddSegment,
46246
46290
  handleRemoveSegment,
46247
- handleCreateSegment,
46291
+ setOpenCreateSegmentDialog,
46248
46292
  segments,
46249
46293
  defaultIsExcludeOpen: automation.excludeSegmentIds?.length > 0
46250
46294
  }
@@ -46844,7 +46888,7 @@ const ViewAutomationHeader = ({
46844
46888
  /* @__PURE__ */ jsx(iconDefinitions.DropdownMenuTrigger, { className: "ml-2 h-4 w-4" })
46845
46889
  ] }) }),
46846
46890
  /* @__PURE__ */ jsxs(DropdownMenuContent, { children: [
46847
- (automation.status === AutomationStatus.DRAFT || automation.status === AutomationStatus.ACTIVE) && /* @__PURE__ */ jsx(
46891
+ automation.status === AutomationStatus.DRAFT && /* @__PURE__ */ jsx(
46848
46892
  DropdownMenuItem,
46849
46893
  {
46850
46894
  onClick: () => setOpenEditAutomationPopup(true),
@@ -46909,12 +46953,13 @@ const ViewAutomationHeader = ({
46909
46953
  ] });
46910
46954
  };
46911
46955
  const ViewAutomationModalContent = ({
46912
- iconDefinitions,
46956
+ iconDefinitions: passedInIconDefinitions,
46913
46957
  autoOpenEditPopup,
46914
46958
  automationId,
46915
46959
  showBackButton = false,
46916
46960
  logoUrl
46917
46961
  }) => {
46962
+ const iconDefinitions = mergeIconDefinitions(passedInIconDefinitions);
46918
46963
  const params = useParams();
46919
46964
  const [searchParams] = useSearchParams();
46920
46965
  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
  /**