@embedreach/components 0.1.88 → 0.1.89

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.
@@ -45317,14 +45317,16 @@ const BasicLoader = ({
45317
45317
  ] });
45318
45318
  };
45319
45319
  const BlurDiv = ({ children: children2, className: className2 }) => {
45320
- return (
45321
- // <motion.div
45322
- // initial={{ opacity: 0, filter: 'blur(8px)' }}
45323
- // animate={{ opacity: 1, filter: 'blur(0px)' }}
45324
- // exit={{ opacity: 0, filter: 'blur(8px)' }}
45325
- // transition={{ duration: 0.3, ease: 'easeInOut' }}
45326
- // className={className}>
45327
- /* @__PURE__ */ jsx("div", { className: className2, children: children2 })
45320
+ return /* @__PURE__ */ jsx(
45321
+ motion.div,
45322
+ {
45323
+ initial: { opacity: 0, filter: "blur(8px)" },
45324
+ animate: { opacity: 1, filter: "blur(0px)" },
45325
+ exit: { opacity: 0, filter: "blur(8px)" },
45326
+ transition: { duration: 0.3, ease: "easeInOut" },
45327
+ className: className2,
45328
+ children: children2
45329
+ }
45328
45330
  );
45329
45331
  };
45330
45332
  const IconDefinitions = {
@@ -62826,87 +62828,6 @@ const useSendTestCommunication = () => {
62826
62828
  isSendSuccess: sendTestCommunicationMutation.isSuccess
62827
62829
  };
62828
62830
  };
62829
- var AutomationSteps = /* @__PURE__ */ ((AutomationSteps2) => {
62830
- AutomationSteps2[AutomationSteps2["SelectTrigger"] = 0] = "SelectTrigger";
62831
- AutomationSteps2[AutomationSteps2["SelectAudience"] = 1] = "SelectAudience";
62832
- AutomationSteps2[AutomationSteps2["SelectCommunication"] = 2] = "SelectCommunication";
62833
- AutomationSteps2[AutomationSteps2["PreviewAndSchedule"] = 3] = "PreviewAndSchedule";
62834
- return AutomationSteps2;
62835
- })(AutomationSteps || {});
62836
- const validateAutomationStep = async (args) => {
62837
- const { currentStep, automation: automation2, communicationGroup } = args;
62838
- if (currentStep === 0) {
62839
- return {
62840
- canMove: true,
62841
- errorMessage: null
62842
- };
62843
- }
62844
- if (currentStep === 1) {
62845
- return {
62846
- canMove: automation2.includeSegmentIds.length > 0,
62847
- errorMessage: "Please ensure you have selected at least one segment"
62848
- };
62849
- }
62850
- if (currentStep === 2) {
62851
- const actionDataCommunication = automation2.action_data?.find(
62852
- (action) => action.action_type === "send_communication"
62853
- );
62854
- if (!actionDataCommunication) {
62855
- return {
62856
- canMove: false,
62857
- errorMessage: "Please ensure you have selected either a email communication or text communication"
62858
- };
62859
- }
62860
- if (!communicationGroup || !communicationGroup.sms_channel_sender_id && !communicationGroup.email_channel_sender_id) {
62861
- return {
62862
- canMove: false,
62863
- errorMessage: "Please ensure you have selected either a email communication or text communication"
62864
- };
62865
- }
62866
- if (communicationGroup.email_channel_sender_id) {
62867
- if (!communicationGroup.email_html_body || !communicationGroup.email_subject) {
62868
- return {
62869
- canMove: false,
62870
- errorMessage: "Please ensure you have a email body and subject"
62871
- };
62872
- }
62873
- }
62874
- if (communicationGroup.sms_channel_sender_id) {
62875
- if (!communicationGroup.sms_message_body) {
62876
- return {
62877
- canMove: false,
62878
- errorMessage: "Please ensure you have a sms message body"
62879
- };
62880
- }
62881
- }
62882
- }
62883
- if (currentStep === 3) {
62884
- const isOneTime = isOneTimeTriggerMetadata(automation2.trigger_metadata);
62885
- if (isOneTime) {
62886
- const oneTimeMetadata = automation2.trigger_metadata;
62887
- return {
62888
- canMove: Boolean(
62889
- oneTimeMetadata.scheduled_at && new Date(oneTimeMetadata.scheduled_at) > /* @__PURE__ */ new Date() && automation2.action_data?.some(
62890
- (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
62891
- )
62892
- ),
62893
- errorMessage: "Please ensure you have set a valid future date for your one-time automation"
62894
- };
62895
- }
62896
- return {
62897
- canMove: Boolean(
62898
- automation2.action_data?.some(
62899
- (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
62900
- )
62901
- ),
62902
- errorMessage: null
62903
- };
62904
- }
62905
- return {
62906
- canMove: true,
62907
- errorMessage: null
62908
- };
62909
- };
62910
62831
  const useRecipientStats = (automation2) => {
62911
62832
  const { data: estimatedMatches } = useGetCountOfBusinessAutomationRecipients({
62912
62833
  include_segments: automation2?.includeSegmentIds ?? [],
@@ -62927,29 +62848,66 @@ const useRecipientStats = (automation2) => {
62927
62848
  estimatedMatchesStats
62928
62849
  };
62929
62850
  };
62930
- const useAutomation = (automationId, existingAutomation) => {
62851
+ const AutomationContext = createContext$1(
62852
+ null
62853
+ );
62854
+ const CommunicationContext = createContext$1(null);
62855
+ const LoadingContext = createContext$1(null);
62856
+ const ValidationContext = createContext$1(
62857
+ null
62858
+ );
62859
+ const useAutomation = () => {
62860
+ const context2 = useContext$1(AutomationContext);
62861
+ if (!context2) {
62862
+ throw new Error(
62863
+ "useAutomation must be used within a ViewAutomationProvider"
62864
+ );
62865
+ }
62866
+ return context2;
62867
+ };
62868
+ const useCommunication = () => {
62869
+ const context2 = useContext$1(CommunicationContext);
62870
+ if (!context2) {
62871
+ throw new Error(
62872
+ "useCommunication must be used within a ViewAutomationProvider"
62873
+ );
62874
+ }
62875
+ return context2;
62876
+ };
62877
+ const useLoading = () => {
62878
+ const context2 = useContext$1(LoadingContext);
62879
+ if (!context2) {
62880
+ throw new Error("useLoading must be used within a ViewAutomationProvider");
62881
+ }
62882
+ return context2;
62883
+ };
62884
+ const useValidation = () => {
62885
+ const context2 = useContext$1(ValidationContext);
62886
+ if (!context2) {
62887
+ throw new Error(
62888
+ "useValidation must be used within a ViewAutomationProvider"
62889
+ );
62890
+ }
62891
+ return context2;
62892
+ };
62893
+ const ViewAutomationProvider = ({
62894
+ automationId,
62895
+ existingAutomation,
62896
+ children: children2
62897
+ }) => {
62931
62898
  const mountedRef = useRef(true);
62932
- const [manualLoading, setManualLoading] = useState(false);
62933
- const {
62934
- automation: fetchedAutomation,
62935
- isLoading: isFetchLoading,
62936
- invalidateAutomation: originalInvalidateAutomation
62937
- } = useGetBusinessAutomation(automationId);
62938
- const automation2 = fetchedAutomation;
62939
- const { updateAutomation: updateAutomation2, isUpdating } = useUpdateBusinessAutomation(automationId);
62899
+ const { automation: fetchedAutomation, isLoading: isFetchLoading } = useGetBusinessAutomation(automationId);
62900
+ const automation2 = existingAutomation || fetchedAutomation;
62901
+ const { isUpdating } = useUpdateBusinessAutomation(automationId);
62940
62902
  const communicationGroupId = automation2?.action_data?.find(
62941
62903
  (action) => action.action_type === "send_communication"
62942
62904
  )?.action_metadata.communication_group_id;
62943
62905
  const { communicationGroup, isGetting: isLoadingCommunicationGroup } = useGetCommunicationGroup(communicationGroupId || void 0);
62944
- const { updateCommunicationGroup: updateCommunicationGroup2, isUpdating: isUpdatingCommunicationGroup } = useUpdateCommunicationGroup();
62906
+ const { isUpdating: isUpdatingCommunicationGroup } = useUpdateCommunicationGroup();
62945
62907
  const { estimatedMatchesStats } = useRecipientStats(automation2);
62946
- const [isValidatingStep, setIsValidatingStep] = useState(false);
62947
62908
  const [isLoading, setIsLoading] = useState(false);
62948
- const invalidateAutomation = useCallback(() => {
62949
- originalInvalidateAutomation();
62950
- }, [originalInvalidateAutomation]);
62951
62909
  useEffect(() => {
62952
- const loadingState = (isFetchLoading || isUpdating || isLoadingCommunicationGroup || isValidatingStep || isUpdatingCommunicationGroup || manualLoading) && mountedRef.current;
62910
+ const loadingState = (!existingAutomation && isFetchLoading || isUpdating || isLoadingCommunicationGroup || isUpdatingCommunicationGroup) && mountedRef.current;
62953
62911
  setIsLoading(loadingState);
62954
62912
  }, [
62955
62913
  existingAutomation,
@@ -62957,54 +62915,46 @@ const useAutomation = (automationId, existingAutomation) => {
62957
62915
  isFetchLoading,
62958
62916
  isUpdating,
62959
62917
  isLoadingCommunicationGroup,
62960
- isValidatingStep,
62961
- isUpdatingCommunicationGroup,
62962
- manualLoading
62918
+ isUpdatingCommunicationGroup
62963
62919
  ]);
62964
62920
  useEffect(() => {
62965
62921
  return () => {
62966
62922
  mountedRef.current = false;
62967
62923
  };
62968
62924
  }, []);
62969
- const validateStep = useCallback(
62970
- async (currentStep) => {
62971
- if (!automation2) {
62972
- return {
62973
- canMove: false,
62974
- errorMessage: "Automation not loaded"
62975
- };
62976
- }
62977
- try {
62978
- setIsValidatingStep(true);
62979
- return await validateAutomationStep({
62980
- currentStep,
62981
- automation: automation2,
62982
- communicationGroup
62983
- });
62984
- } finally {
62985
- if (mountedRef.current) {
62986
- setIsValidatingStep(false);
62925
+ return /* @__PURE__ */ jsx(
62926
+ AutomationContext.Provider,
62927
+ {
62928
+ value: {
62929
+ automation: automation2
62930
+ },
62931
+ children: /* @__PURE__ */ jsx(
62932
+ CommunicationContext.Provider,
62933
+ {
62934
+ value: {
62935
+ communicationGroup
62936
+ },
62937
+ children: /* @__PURE__ */ jsx(
62938
+ LoadingContext.Provider,
62939
+ {
62940
+ value: {
62941
+ isLoading
62942
+ },
62943
+ children: /* @__PURE__ */ jsx(
62944
+ ValidationContext.Provider,
62945
+ {
62946
+ value: {
62947
+ estimatedMatchesStats
62948
+ },
62949
+ children: children2
62950
+ }
62951
+ )
62952
+ }
62953
+ )
62987
62954
  }
62988
- }
62989
- },
62990
- [automation2, communicationGroup]
62991
- );
62992
- const setIsLoadingSafe = useCallback((loading2) => {
62993
- if (mountedRef.current) {
62994
- setManualLoading(loading2);
62955
+ )
62995
62956
  }
62996
- }, []);
62997
- return {
62998
- automation: automation2,
62999
- updateAutomation: updateAutomation2,
63000
- communicationGroup,
63001
- updateCommunicationGroup: updateCommunicationGroup2,
63002
- isLoading,
63003
- setIsLoading: setIsLoadingSafe,
63004
- invalidateAutomation,
63005
- validateStep,
63006
- estimatedMatchesStats
63007
- };
62957
+ );
63008
62958
  };
63009
62959
  const getChannelSenders = async () => {
63010
62960
  const response = await baseRequest(
@@ -63289,13 +63239,13 @@ ${smsPreview.body}` : smsPreview.body
63289
63239
  };
63290
63240
  const AutomationContent = ({
63291
63241
  iconDefinitions,
63292
- isLoading: isLoadingCommunicationGroup,
63293
- communicationGroup
63242
+ isLoading: isLoadingCommunicationGroup
63294
63243
  }) => {
63295
63244
  const { channelSenders } = useChannelSender();
63296
63245
  const [emailData, setEmailData] = useState(null);
63297
63246
  const [smsData, setSmsData] = useState(null);
63298
63247
  const [loading2, setLoading2] = useState(false);
63248
+ const { communicationGroup } = useCommunication();
63299
63249
  useEffect(() => {
63300
63250
  if (!communicationGroup || !channelSenders) {
63301
63251
  setLoading2(false);
@@ -65088,6 +65038,87 @@ const StepIndicator = ({
65088
65038
  )
65089
65039
  ] });
65090
65040
  };
65041
+ var AutomationSteps = /* @__PURE__ */ ((AutomationSteps2) => {
65042
+ AutomationSteps2[AutomationSteps2["SelectTrigger"] = 0] = "SelectTrigger";
65043
+ AutomationSteps2[AutomationSteps2["SelectAudience"] = 1] = "SelectAudience";
65044
+ AutomationSteps2[AutomationSteps2["SelectCommunication"] = 2] = "SelectCommunication";
65045
+ AutomationSteps2[AutomationSteps2["PreviewAndSchedule"] = 3] = "PreviewAndSchedule";
65046
+ return AutomationSteps2;
65047
+ })(AutomationSteps || {});
65048
+ const validateAutomationStep = async (args) => {
65049
+ const { currentStep, automation: automation2, communicationGroup } = args;
65050
+ if (currentStep === 0) {
65051
+ return {
65052
+ canMove: true,
65053
+ errorMessage: null
65054
+ };
65055
+ }
65056
+ if (currentStep === 1) {
65057
+ return {
65058
+ canMove: automation2.includeSegmentIds.length > 0,
65059
+ errorMessage: "Please ensure you have selected at least one segment"
65060
+ };
65061
+ }
65062
+ if (currentStep === 2) {
65063
+ const actionDataCommunication = automation2.action_data?.find(
65064
+ (action) => action.action_type === "send_communication"
65065
+ );
65066
+ if (!actionDataCommunication) {
65067
+ return {
65068
+ canMove: false,
65069
+ errorMessage: "Please ensure you have selected either a email communication or text communication"
65070
+ };
65071
+ }
65072
+ if (!communicationGroup || !communicationGroup.sms_channel_sender_id && !communicationGroup.email_channel_sender_id) {
65073
+ return {
65074
+ canMove: false,
65075
+ errorMessage: "Please ensure you have selected either a email communication or text communication"
65076
+ };
65077
+ }
65078
+ if (communicationGroup.email_channel_sender_id) {
65079
+ if (!communicationGroup.email_html_body || !communicationGroup.email_subject) {
65080
+ return {
65081
+ canMove: false,
65082
+ errorMessage: "Please ensure you have a email body and subject"
65083
+ };
65084
+ }
65085
+ }
65086
+ if (communicationGroup.sms_channel_sender_id) {
65087
+ if (!communicationGroup.sms_message_body) {
65088
+ return {
65089
+ canMove: false,
65090
+ errorMessage: "Please ensure you have a sms message body"
65091
+ };
65092
+ }
65093
+ }
65094
+ }
65095
+ if (currentStep === 3) {
65096
+ const isOneTime = isOneTimeTriggerMetadata(automation2.trigger_metadata);
65097
+ if (isOneTime) {
65098
+ const oneTimeMetadata = automation2.trigger_metadata;
65099
+ return {
65100
+ canMove: Boolean(
65101
+ oneTimeMetadata.scheduled_at && new Date(oneTimeMetadata.scheduled_at) > /* @__PURE__ */ new Date() && automation2.action_data?.some(
65102
+ (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
65103
+ )
65104
+ ),
65105
+ errorMessage: "Please ensure you have set a valid future date for your one-time automation"
65106
+ };
65107
+ }
65108
+ return {
65109
+ canMove: Boolean(
65110
+ automation2.action_data?.some(
65111
+ (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
65112
+ )
65113
+ ),
65114
+ errorMessage: null
65115
+ };
65116
+ }
65117
+ return {
65118
+ canMove: true,
65119
+ errorMessage: null
65120
+ };
65121
+ };
65091
65122
  const mergeFieldTemplateCreator = (args) => {
65092
65123
  const { mergeFieldName } = args;
65093
65124
  return `{{${mergeFieldName}}}`;
@@ -65383,24 +65414,22 @@ const StripoWrapper = ({
65383
65414
  }
65384
65415
  ) });
65385
65416
  };
65386
- const EmailPreview = ({
65387
- automation: automation2,
65388
- mergeFieldsResponse,
65389
- communicationGroup,
65390
- updateCommunicationGroup: updateCommunicationGroup2
65391
- }) => {
65417
+ const EmailPreview = ({ mergeFieldsResponse }) => {
65418
+ const { communicationGroup } = useCommunication();
65419
+ const { automation: automation2 } = useAutomation();
65420
+ const { updateCommunicationGroup: updateCommunicationGroup2 } = useUpdateCommunicationGroup();
65392
65421
  const [isUpdating, setIsUpdating] = useState(false);
65393
65422
  const [fromEmail, setFromEmail] = useState(
65394
- communicationGroup.email_channel_sender_id || null
65423
+ communicationGroup?.email_channel_sender_id || null
65395
65424
  );
65396
65425
  const [subject, setSubject] = useState(
65397
- communicationGroup.email_subject || null
65426
+ communicationGroup?.email_subject || null
65398
65427
  );
65399
65428
  const [previewText, setPreviewText] = useState(
65400
- communicationGroup.email_preview_text || null
65429
+ communicationGroup?.email_preview_text || null
65401
65430
  );
65402
65431
  const [body, setBody] = useState(
65403
- communicationGroup.email_html_body || null
65432
+ communicationGroup?.email_html_body || null
65404
65433
  );
65405
65434
  const [showStripoEditor, setShowStripoEditor] = useState(false);
65406
65435
  const [saveClicked, setSaveClicked] = useState(false);
@@ -65410,7 +65439,7 @@ const EmailPreview = ({
65410
65439
  null
65411
65440
  );
65412
65441
  const { refetchAutomation: refreshAutomation } = useGetBusinessAutomation(
65413
- automation2.id
65442
+ automation2?.id || ""
65414
65443
  );
65415
65444
  const [showHelpDialog, setShowHelpDialog] = useState(false);
65416
65445
  const initialRenderRef = useRef(true);
@@ -65460,10 +65489,10 @@ const EmailPreview = ({
65460
65489
  return () => clearTimeout(timer);
65461
65490
  }, []);
65462
65491
  useEffect(() => {
65463
- if (communicationGroup.email_html_body) {
65492
+ if (communicationGroup?.email_html_body) {
65464
65493
  setBody(communicationGroup.email_html_body);
65465
65494
  }
65466
- }, [communicationGroup.email_html_body, refreshAutomation]);
65495
+ }, [communicationGroup?.email_html_body, refreshAutomation]);
65467
65496
  useEffect(() => {
65468
65497
  if (isUpdating) {
65469
65498
  const timer = setTimeout(() => {
@@ -65486,7 +65515,7 @@ const EmailPreview = ({
65486
65515
  };
65487
65516
  }, []);
65488
65517
  useEffect(() => {
65489
- if (!initialRenderRef.current && fromEmail && debouncedSubject && body && communicationGroup.id) {
65518
+ if (!initialRenderRef.current && fromEmail && debouncedSubject && body && communicationGroup?.id) {
65490
65519
  setIsUpdating(true);
65491
65520
  const updateGroup = async () => {
65492
65521
  try {
@@ -65514,7 +65543,7 @@ const EmailPreview = ({
65514
65543
  debouncedSubject,
65515
65544
  debouncedPreviewText,
65516
65545
  body,
65517
- communicationGroup.id,
65546
+ communicationGroup?.id,
65518
65547
  updateCommunicationGroup2
65519
65548
  ]);
65520
65549
  useEffect(() => {
@@ -65540,7 +65569,7 @@ const EmailPreview = ({
65540
65569
  const channelSender = allEmailSenders[0];
65541
65570
  setFromEmail(channelSender.id);
65542
65571
  updateCommunicationGroup2({
65543
- groupId: communicationGroup.id,
65572
+ groupId: communicationGroup?.id || "",
65544
65573
  params: {
65545
65574
  email_channel_sender_id: channelSender.id
65546
65575
  }
@@ -65550,7 +65579,7 @@ const EmailPreview = ({
65550
65579
  }, [
65551
65580
  channelSenders?.results,
65552
65581
  fromEmail,
65553
- communicationGroup.id,
65582
+ communicationGroup?.id,
65554
65583
  updateCommunicationGroup2
65555
65584
  ]);
65556
65585
  useEffect(() => {
@@ -65632,10 +65661,10 @@ const EmailPreview = ({
65632
65661
  replyToEmailError
65633
65662
  ]);
65634
65663
  useEffect(() => {
65635
- if (showStripoEditor === false && communicationGroup.id) {
65664
+ if (showStripoEditor === false && communicationGroup?.id) {
65636
65665
  refreshAutomation();
65637
65666
  }
65638
- }, [showStripoEditor, communicationGroup.id, refreshAutomation]);
65667
+ }, [showStripoEditor, communicationGroup?.id, refreshAutomation]);
65639
65668
  if (!channelAccounts || !channelSenders) {
65640
65669
  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(BasicLoader, { text: ["Fetching Email Preview..."] }) });
65641
65670
  }
@@ -65673,7 +65702,7 @@ const EmailPreview = ({
65673
65702
  }
65674
65703
  )
65675
65704
  ] }),
65676
- /* @__PURE__ */ jsx("div", { className: " w-full", children: /* @__PURE__ */ jsx(
65705
+ /* @__PURE__ */ jsx("div", { className: " w-full", children: automation2 && /* @__PURE__ */ jsx(
65677
65706
  StripoWrapper,
65678
65707
  {
65679
65708
  showStripoEditor,
@@ -66063,14 +66092,15 @@ const useMe = () => {
66063
66092
  });
66064
66093
  return query;
66065
66094
  };
66066
- const SMSPreview = ({ automation: automation2, iconDefinitions, mergeFieldsResponse }) => {
66095
+ const SMSPreview = ({ iconDefinitions, mergeFieldsResponse }) => {
66096
+ const { automation: automation2 } = useAutomation();
66067
66097
  const [isUpdating, setIsUpdating] = useState(false);
66068
66098
  const _getCommunicationGroupFromAutomation = useCallback(() => {
66069
- const actionGroup = automation2.action_data?.find(
66099
+ const actionGroup = automation2?.action_data?.find(
66070
66100
  (action) => action.action_type === "send_communication"
66071
66101
  );
66072
66102
  return actionGroup?.action_metadata.communication_group_id;
66073
- }, [automation2.action_data]);
66103
+ }, [automation2?.action_data]);
66074
66104
  const [mergeFieldValue, setMergeFieldValue] = useState("");
66075
66105
  const [fromNumber, setFromNumber] = useState(null);
66076
66106
  const [initCompanyName, setInitCompanyName] = useState(false);
@@ -66294,16 +66324,15 @@ ${message2}` : message2
66294
66324
  ] });
66295
66325
  };
66296
66326
  const EditCampaignContent = ({
66297
- automation: automation2,
66298
66327
  iconDefinitions,
66299
- getExtraMergeFields,
66300
- communicationGroup,
66301
- updateAutomation: updateAutomation2,
66302
- updateCommunicationGroup: updateCommunicationGroup2
66328
+ getExtraMergeFields
66303
66329
  }) => {
66304
66330
  const [selectedChannels, setSelectedChannels] = useState(null);
66305
66331
  const emailContainerRef = useRef(null);
66306
66332
  const { toast: toast2 } = useToast();
66333
+ const { communicationGroup } = useCommunication();
66334
+ const { updateCommunicationGroup: updateCommunicationGroup2 } = useUpdateCommunicationGroup();
66335
+ const { automation: automation2 } = useAutomation();
66307
66336
  const { getMergeFields: getMergeFields2, isGetting: isGetMergeFieldsLoading } = useGetMergeFields(communicationGroup?.id ?? void 0);
66308
66337
  const [mergeFieldsResponse, setMergeFieldsResponse] = useState(void 0);
66309
66338
  useEffect(() => {
@@ -66506,11 +66535,7 @@ const EditCampaignContent = ({
66506
66535
  /* @__PURE__ */ jsx(
66507
66536
  EmailPreview,
66508
66537
  {
66509
- automation: automation2,
66510
66538
  iconDefinitions,
66511
- updateAutomation: updateAutomation2,
66512
- communicationGroup,
66513
- updateCommunicationGroup: updateCommunicationGroup2,
66514
66539
  mergeFieldsResponse
66515
66540
  }
66516
66541
  )
@@ -66522,7 +66547,6 @@ const EditCampaignContent = ({
66522
66547
  /* @__PURE__ */ jsx(
66523
66548
  SMSPreview,
66524
66549
  {
66525
- automation: automation2,
66526
66550
  iconDefinitions,
66527
66551
  mergeFieldsResponse
66528
66552
  }
@@ -67031,13 +67055,12 @@ const SelectTime = ({ iconDefinitions, automation: automation2, updateAutomation
67031
67055
  ) });
67032
67056
  };
67033
67057
  const PreviewAndSchedule = ({
67034
- automation: automation2,
67035
67058
  iconDefinitions,
67036
- isLoading,
67037
- communicationGroup,
67038
67059
  updateAutomation: externalUpdateAutomation
67039
67060
  }) => {
67040
- const { updateAutomation: businessUpdateAutomation } = useUpdateBusinessAutomation(automation2.id);
67061
+ const { automation: automation2 } = useAutomation();
67062
+ const { communicationGroup } = useCommunication();
67063
+ const { updateAutomation: businessUpdateAutomation } = useUpdateBusinessAutomation(automation2?.id || "");
67041
67064
  const updateAutomation2 = externalUpdateAutomation || ((params) => businessUpdateAutomation(params));
67042
67065
  const { channelSenders } = useChannelSender();
67043
67066
  const { channelAccounts } = useChannelAccount();
@@ -67102,7 +67125,7 @@ const PreviewAndSchedule = ({
67102
67125
  }
67103
67126
  }
67104
67127
  }, [communicationGroup, channelSenderData, channelAccountsData]);
67105
- if (isLoading) {
67128
+ if (!automation2) {
67106
67129
  return /* @__PURE__ */ jsx(BasicLoader, { text: ["Loading..."] });
67107
67130
  }
67108
67131
  if (!emailPreview && !smsPreview) {
@@ -67123,8 +67146,8 @@ const PreviewAndSchedule = ({
67123
67146
  {
67124
67147
  subtitle: "Estimated recipient count may vary at time of delivery",
67125
67148
  iconDefinitions,
67126
- includeSegments: automation2.includeSegmentIds,
67127
- excludeSegments: automation2.excludeSegmentIds
67149
+ includeSegments: automation2.includeSegmentIds || [],
67150
+ excludeSegments: automation2.excludeSegmentIds || []
67128
67151
  }
67129
67152
  )
67130
67153
  ] }),
@@ -67558,15 +67581,12 @@ const TriggerEditAutomation = ({ automation: automation2 }) => {
67558
67581
  }
67559
67582
  ) });
67560
67583
  };
67561
- const useAutomationSteps = ({
67584
+ const getAutomationSteps = ({
67562
67585
  automation: automation2,
67563
- updateAutomation: updateAutomation2,
67564
67586
  communicationGroup,
67565
- updateCommunicationGroup: updateCommunicationGroup2,
67566
67587
  iconDefinitions,
67567
67588
  getExtraMergeFields,
67568
- handleSaveAsDraft,
67569
- isLoading
67589
+ handleSaveAsDraft
67570
67590
  }) => {
67571
67591
  if (!automation2) return [];
67572
67592
  return [
@@ -67662,10 +67682,6 @@ const useAutomationSteps = ({
67662
67682
  /* @__PURE__ */ jsx(
67663
67683
  EditCampaignContent,
67664
67684
  {
67665
- automation: automation2,
67666
- updateAutomation: updateAutomation2,
67667
- communicationGroup,
67668
- updateCommunicationGroup: updateCommunicationGroup2,
67669
67685
  iconDefinitions,
67670
67686
  getExtraMergeFields
67671
67687
  }
@@ -67698,15 +67714,7 @@ const useAutomationSteps = ({
67698
67714
  {
67699
67715
  className: "flex-1",
67700
67716
  title: "Preview and Schedule",
67701
- content: /* @__PURE__ */ jsx(
67702
- PreviewAndSchedule,
67703
- {
67704
- automation: automation2,
67705
- iconDefinitions,
67706
- isLoading,
67707
- communicationGroup
67708
- }
67709
- )
67717
+ content: /* @__PURE__ */ jsx(PreviewAndSchedule, { iconDefinitions })
67710
67718
  },
67711
67719
  "send"
67712
67720
  ),
@@ -67741,6 +67749,29 @@ const useAutomationSteps = ({
67741
67749
  }
67742
67750
  ];
67743
67751
  };
67752
+ const useAutomationActions = () => {
67753
+ const { automation: automation2 } = useAutomation();
67754
+ const { communicationGroup } = useCommunication();
67755
+ const validateStep = useCallback(
67756
+ async (currentStep) => {
67757
+ if (!automation2) {
67758
+ return {
67759
+ canMove: false,
67760
+ errorMessage: "Automation not loaded"
67761
+ };
67762
+ }
67763
+ return await validateAutomationStep({
67764
+ currentStep,
67765
+ automation: automation2,
67766
+ communicationGroup
67767
+ });
67768
+ },
67769
+ [automation2, communicationGroup]
67770
+ );
67771
+ return {
67772
+ validateStep
67773
+ };
67774
+ };
67744
67775
  const BackNextButtonGroup = ({
67745
67776
  iconDefinitions,
67746
67777
  handleBack,
@@ -67797,30 +67828,38 @@ const BackNextButtonGroup = ({
67797
67828
  ] });
67798
67829
  };
67799
67830
  const EditAutomation = ({
67800
- automation: automation2,
67801
- updateAutomation: updateAutomation2,
67802
- communicationGroup,
67803
- updateCommunicationGroup: updateCommunicationGroup2,
67804
67831
  iconDefinitions,
67805
67832
  setOpenEditAutomationPopup,
67806
67833
  logoUrl,
67807
67834
  getExtraMergeFields,
67808
- onBeforeSchedule,
67809
- estimatedMatchesStats,
67810
- isLoading,
67811
- validateCanGoToNextStep,
67812
- setIsLoading
67835
+ onBeforeSchedule
67813
67836
  }) => {
67814
67837
  const { toast: toast2 } = useToast();
67838
+ const { automation: automation2 } = useAutomation();
67839
+ const { communicationGroup } = useCommunication();
67840
+ const { estimatedMatchesStats } = useValidation();
67815
67841
  const [currentStep, setCurrentStep] = useState(
67816
- /**
67817
- * We dont show the trigger step for trigger based automations
67818
- */
67819
- automation2.trigger_type === AutomationTriggerType.TRIGGER_BASED ? AutomationSteps.SelectTrigger : AutomationSteps.SelectAudience
67842
+ void 0
67820
67843
  );
67821
67844
  const [isValidatingStep, setIsValidatingStep] = useState(false);
67845
+ const { updateAutomation: updateAutomation2 } = useUpdateBusinessAutomation(
67846
+ automation2?.id || ""
67847
+ );
67848
+ const { validateStep } = useAutomationActions();
67849
+ useEffect(() => {
67850
+ if (automation2) {
67851
+ setCurrentStep(
67852
+ automation2.trigger_type === AutomationTriggerType.TRIGGER_BASED ? AutomationSteps.SelectTrigger : AutomationSteps.SelectAudience
67853
+ );
67854
+ }
67855
+ }, [automation2]);
67856
+ if (!automation2 || !currentStep || !communicationGroup) {
67857
+ return /* @__PURE__ */ jsx("div", { className: "flex-1 flex flex-col @container justify-center items-center h-[500px]", children: /* @__PURE__ */ jsx(BasicLoader, { text: ["Fetching Automation data", "Finishing up"] }) });
67858
+ }
67822
67859
  const handleSaveAsDraft = () => {
67823
- setIsLoading(true);
67860
+ if (!automation2) {
67861
+ return;
67862
+ }
67824
67863
  updateAutomation2({
67825
67864
  status: AutomationStatus.DRAFT
67826
67865
  });
@@ -67829,21 +67868,14 @@ const EditAutomation = ({
67829
67868
  title: "Automation saved as draft",
67830
67869
  description: "You can continue editing it later"
67831
67870
  });
67832
- setIsLoading(false);
67833
67871
  };
67834
- const STEPS = useAutomationSteps({
67872
+ const STEPS = getAutomationSteps({
67835
67873
  automation: automation2,
67874
+ communicationGroup,
67836
67875
  iconDefinitions,
67837
67876
  getExtraMergeFields,
67838
- handleSaveAsDraft,
67839
- isLoading,
67840
- communicationGroup,
67841
- updateAutomation: updateAutomation2,
67842
- updateCommunicationGroup: updateCommunicationGroup2
67877
+ handleSaveAsDraft
67843
67878
  });
67844
- if (isLoading) {
67845
- return /* @__PURE__ */ jsx("div", { className: "flex-1 flex flex-col @container justify-center items-center h-[500px]", children: /* @__PURE__ */ jsx(BasicLoader, { text: ["Fetching Automation data", "Finishing up"] }) });
67846
- }
67847
67879
  const handleScheduleAutomation = async () => {
67848
67880
  if (onBeforeSchedule) {
67849
67881
  try {
@@ -67852,7 +67884,6 @@ const EditAutomation = ({
67852
67884
  estimatedSmsRecipients: estimatedMatchesStats.phones
67853
67885
  });
67854
67886
  if (result === true) {
67855
- setIsLoading(true);
67856
67887
  updateAutomation2({
67857
67888
  status: AutomationStatus.ACTIVE
67858
67889
  });
@@ -67860,7 +67891,6 @@ const EditAutomation = ({
67860
67891
  toast2({
67861
67892
  title: "Automation scheduled!"
67862
67893
  });
67863
- setIsLoading(false);
67864
67894
  } else {
67865
67895
  toast2({
67866
67896
  title: "Oops!",
@@ -67876,21 +67906,15 @@ const EditAutomation = ({
67876
67906
  });
67877
67907
  }
67878
67908
  } else {
67879
- setIsLoading(true);
67880
67909
  updateAutomation2({ status: AutomationStatus.ACTIVE });
67881
67910
  setOpenEditAutomationPopup(false);
67882
67911
  toast2({
67883
67912
  title: "Automation scheduled!"
67884
67913
  });
67885
- setIsLoading(false);
67886
67914
  }
67887
67915
  };
67888
67916
  const handleNextStep = async () => {
67889
- const { canMove, errorMessage } = await validateCanGoToNextStep({
67890
- currentStep,
67891
- automation: automation2,
67892
- communicationGroup
67893
- });
67917
+ const { canMove, errorMessage } = await validateStep(currentStep);
67894
67918
  if (!canMove) {
67895
67919
  toast2({
67896
67920
  title: "Oops!",
@@ -67917,11 +67941,7 @@ const EditAutomation = ({
67917
67941
  setIsValidatingStep(true);
67918
67942
  try {
67919
67943
  for (let step = currentStep; step < targetStep; step++) {
67920
- const { canMove, errorMessage } = await validateCanGoToNextStep({
67921
- currentStep: step,
67922
- automation: automation2,
67923
- communicationGroup
67924
- });
67944
+ const { canMove, errorMessage } = await validateStep(step);
67925
67945
  if (!canMove) {
67926
67946
  return { canMove, errorMessage };
67927
67947
  }
@@ -68181,21 +68201,12 @@ const SendPreviewPopup = ({ automation: automation2, type, setOpenSendPreviewPop
68181
68201
  ] });
68182
68202
  };
68183
68203
  const ViewAutomationHeaderContainer = ({
68184
- automation: automation2,
68185
- updateAutomation: updateAutomation2,
68186
- communicationGroup,
68187
- updateCommunicationGroup: updateCommunicationGroup2,
68188
- isLoading,
68189
- setIsLoading,
68190
68204
  iconDefinitions,
68191
68205
  autoOpenEditPopup,
68192
68206
  logoUrl,
68193
68207
  getExtraMergeFields,
68194
68208
  onDuplicationCreated,
68195
68209
  onBeforeSchedule,
68196
- invalidateAutomation,
68197
- estimatedMatchesStats,
68198
- validateStep,
68199
68210
  showBackButton = false
68200
68211
  }) => {
68201
68212
  const [openEditAutomationPopup, setOpenEditAutomationPopup] = useState(false);
@@ -68205,6 +68216,13 @@ const ViewAutomationHeaderContainer = ({
68205
68216
  setCancelAutomationConfirmationPopup
68206
68217
  ] = useState(false);
68207
68218
  const [openSendPreviewEmailPopup, setOpenSendPreviewEmailPopup] = useState(false);
68219
+ const { automation: automation2 } = useAutomation();
68220
+ const { updateAutomation: updateAutomation2 } = useUpdateBusinessAutomation(
68221
+ automation2?.id || ""
68222
+ );
68223
+ const { invalidateAutomation } = useGetBusinessAutomation(
68224
+ automation2?.id || ""
68225
+ );
68208
68226
  const mergedIconDefinitions = mergeIconDefinitions(iconDefinitions);
68209
68227
  const navigate = useNavigate();
68210
68228
  const { toast: toast2 } = useToast();
@@ -68231,6 +68249,13 @@ const ViewAutomationHeaderContainer = ({
68231
68249
  updateAutomation2({ status: AutomationStatus.DRAFT });
68232
68250
  };
68233
68251
  const handleDuplicateAutomation = async () => {
68252
+ if (!automation2) {
68253
+ toast2({
68254
+ title: "Error duplicating automation",
68255
+ description: "Please try again"
68256
+ });
68257
+ return;
68258
+ }
68234
68259
  const { id: duplicatedId } = await duplicateBusinessAutomation(
68235
68260
  automation2.id
68236
68261
  );
@@ -68249,9 +68274,9 @@ const ViewAutomationHeaderContainer = ({
68249
68274
  description: "The automation has been duplicated"
68250
68275
  });
68251
68276
  };
68252
- const validateStepAdapter = async (args) => {
68253
- return validateStep(args.currentStep);
68254
- };
68277
+ if (!automation2) {
68278
+ return /* @__PURE__ */ jsx("div", { className: "flex justify-center items-center h-full", children: /* @__PURE__ */ jsx(BasicLoader, { text: ["Fetching Automation data", "Finishing up"] }) });
68279
+ }
68255
68280
  const renderEditAutomationDialog = () => /* @__PURE__ */ jsx(
68256
68281
  Dialog,
68257
68282
  {
@@ -68270,19 +68295,11 @@ const ViewAutomationHeaderContainer = ({
68270
68295
  /* @__PURE__ */ jsx(
68271
68296
  EditAutomation,
68272
68297
  {
68273
- automation: automation2,
68274
- updateAutomation: updateAutomation2,
68275
- communicationGroup,
68276
- updateCommunicationGroup: updateCommunicationGroup2,
68277
- isLoading,
68278
- setIsLoading,
68279
68298
  iconDefinitions: mergedIconDefinitions,
68280
68299
  setOpenEditAutomationPopup,
68281
68300
  logoUrl,
68282
68301
  getExtraMergeFields,
68283
- onBeforeSchedule,
68284
- estimatedMatchesStats,
68285
- validateCanGoToNextStep: validateStepAdapter
68302
+ onBeforeSchedule
68286
68303
  }
68287
68304
  )
68288
68305
  ]
@@ -68443,57 +68460,34 @@ const ViewAutomationHeaderContainer = ({
68443
68460
  ] });
68444
68461
  };
68445
68462
  const ViewAutomationHeader = React__default.memo(ViewAutomationHeaderContainer);
68446
- const ViewAutomationContent = ({
68447
- iconDefinitions,
68463
+ const ViewAutomationWrapper = ({
68448
68464
  autoOpenEditPopup,
68449
- automationId,
68450
68465
  showBackButton = false,
68451
68466
  logoUrl,
68452
68467
  getExtraMergeFields,
68453
68468
  onDuplicationCreated,
68454
- onBeforeSchedule
68469
+ onBeforeSchedule,
68470
+ iconDefinitions
68455
68471
  }) => {
68456
- const params = useParams();
68457
- const [searchParams] = useSearchParams();
68472
+ const { automation: automation2 } = useAutomation();
68473
+ const { communicationGroup } = useCommunication();
68474
+ const { isLoading } = useLoading();
68458
68475
  const finalIconDefinitions = mergeIconDefinitions(iconDefinitions);
68459
68476
  const [activeTab, setActiveTab] = React__default.useState("content");
68460
- const effectiveAutomationId = automationId || params?.automationId || searchParams.get("automationId") || "";
68461
- const shouldAutoOpenEditPopup = autoOpenEditPopup || searchParams.get("autoOpenEditPopup");
68462
- const shouldShowBackButton = searchParams.get("showBackButton") === "true" || showBackButton;
68463
- const {
68464
- automation: automation2,
68465
- updateAutomation: updateAutomation2,
68466
- communicationGroup,
68467
- updateCommunicationGroup: updateCommunicationGroup2,
68468
- isLoading,
68469
- setIsLoading,
68470
- invalidateAutomation,
68471
- validateStep,
68472
- estimatedMatchesStats
68473
- } = useAutomation(effectiveAutomationId);
68474
68477
  if (!automation2 || !communicationGroup) {
68475
68478
  return /* @__PURE__ */ jsx("div", { className: "flex h-screen items-center justify-center", children: /* @__PURE__ */ jsx(BasicLoader, { text: ["Fetching Automation data", "Finishing up"] }) });
68476
68479
  }
68477
- return /* @__PURE__ */ jsxs("div", { className: "bg-background", children: [
68480
+ return /* @__PURE__ */ jsxs("div", { children: [
68478
68481
  /* @__PURE__ */ jsx(
68479
68482
  ViewAutomationHeader,
68480
68483
  {
68481
- automation: automation2,
68482
- updateAutomation: updateAutomation2,
68483
- communicationGroup,
68484
- updateCommunicationGroup: updateCommunicationGroup2,
68485
- isLoading,
68486
- setIsLoading,
68487
68484
  iconDefinitions: finalIconDefinitions,
68488
- autoOpenEditPopup: shouldAutoOpenEditPopup,
68489
- showBackButton: shouldShowBackButton,
68485
+ autoOpenEditPopup,
68486
+ showBackButton,
68490
68487
  logoUrl,
68491
68488
  getExtraMergeFields,
68492
68489
  onDuplicationCreated,
68493
- onBeforeSchedule,
68494
- invalidateAutomation,
68495
- estimatedMatchesStats,
68496
- validateStep
68490
+ onBeforeSchedule
68497
68491
  }
68498
68492
  ),
68499
68493
  /* @__PURE__ */ jsx(
@@ -68507,8 +68501,7 @@ const ViewAutomationContent = ({
68507
68501
  AutomationContent,
68508
68502
  {
68509
68503
  iconDefinitions: finalIconDefinitions,
68510
- isLoading,
68511
- communicationGroup
68504
+ isLoading
68512
68505
  }
68513
68506
  )
68514
68507
  },
@@ -68533,6 +68526,21 @@ const ViewAutomationContent = ({
68533
68526
  )
68534
68527
  ] });
68535
68528
  };
68529
+ const ViewAutomationContent = ({ ...props }) => {
68530
+ const params = useParams();
68531
+ const [searchParams] = useSearchParams();
68532
+ const effectiveAutomationId = props.automationId || params?.automationId || searchParams.get("automationId") || "";
68533
+ const shouldAutoOpenEditPopup = props.autoOpenEditPopup || searchParams.get("autoOpenEditPopup");
68534
+ const shouldShowBackButton = searchParams.get("showBackButton") === "true" || props.showBackButton;
68535
+ return /* @__PURE__ */ jsx(ViewAutomationProvider, { automationId: effectiveAutomationId, children: /* @__PURE__ */ jsx("div", { className: "bg-background", children: /* @__PURE__ */ jsx(
68536
+ ViewAutomationWrapper,
68537
+ {
68538
+ ...props,
68539
+ autoOpenEditPopup: shouldAutoOpenEditPopup,
68540
+ showBackButton: shouldShowBackButton
68541
+ }
68542
+ ) }) });
68543
+ };
68536
68544
  const ViewAutomation = ({ inRouter = false, ...props }) => inRouter ? /* @__PURE__ */ jsx(ViewAutomationContent, { ...props }) : /* @__PURE__ */ jsx(MemoryRouter, { children: /* @__PURE__ */ jsx(ViewAutomationContent, { ...props }) });
68537
68545
  Object.values(
68538
68546
  /* @__PURE__ */ Object.assign({})