@embedreach/components 0.1.87 → 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.
@@ -5887,6 +5887,117 @@ var ReactQueryDevtools2 = process.env.NODE_ENV !== "development" ? function() {
5887
5887
  process.env.NODE_ENV !== "development" ? function() {
5888
5888
  return null;
5889
5889
  } : ReactQueryDevtoolsPanel;
5890
+ class InvalidTokenError extends Error {
5891
+ }
5892
+ InvalidTokenError.prototype.name = "InvalidTokenError";
5893
+ function b64DecodeUnicode(str) {
5894
+ return decodeURIComponent(atob(str).replace(/(.)/g, (m4, p2) => {
5895
+ let code = p2.charCodeAt(0).toString(16).toUpperCase();
5896
+ if (code.length < 2) {
5897
+ code = "0" + code;
5898
+ }
5899
+ return "%" + code;
5900
+ }));
5901
+ }
5902
+ function base64UrlDecode(str) {
5903
+ let output = str.replace(/-/g, "+").replace(/_/g, "/");
5904
+ switch (output.length % 4) {
5905
+ case 0:
5906
+ break;
5907
+ case 2:
5908
+ output += "==";
5909
+ break;
5910
+ case 3:
5911
+ output += "=";
5912
+ break;
5913
+ default:
5914
+ throw new Error("base64 string is not of the correct length");
5915
+ }
5916
+ try {
5917
+ return b64DecodeUnicode(output);
5918
+ } catch (err) {
5919
+ return atob(output);
5920
+ }
5921
+ }
5922
+ function jwtDecode(token, options) {
5923
+ if (typeof token !== "string") {
5924
+ throw new InvalidTokenError("Invalid token specified: must be a string");
5925
+ }
5926
+ options || (options = {});
5927
+ const pos = options.header === true ? 0 : 1;
5928
+ const part = token.split(".")[pos];
5929
+ if (typeof part !== "string") {
5930
+ throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
5931
+ }
5932
+ let decoded;
5933
+ try {
5934
+ decoded = base64UrlDecode(part);
5935
+ } catch (e4) {
5936
+ throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e4.message})`);
5937
+ }
5938
+ try {
5939
+ return JSON.parse(decoded);
5940
+ } catch (e4) {
5941
+ throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e4.message})`);
5942
+ }
5943
+ }
5944
+ const ErrorFallback = ({ error: error2 }) => /* @__PURE__ */ jsxs("div", { className: "p-6 max-w-lg mx-auto mt-10 bg-white rounded-lg shadow-md", children: [
5945
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-start gap-4", children: [
5946
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-12 w-12 rounded-full bg-red-100 text-red-600 mb-4", children: /* @__PURE__ */ jsx(
5947
+ "svg",
5948
+ {
5949
+ xmlns: "http://www.w3.org/2000/svg",
5950
+ className: "h-6 w-6",
5951
+ fill: "none",
5952
+ viewBox: "0 0 24 24",
5953
+ stroke: "currentColor",
5954
+ children: /* @__PURE__ */ jsx(
5955
+ "path",
5956
+ {
5957
+ strokeLinecap: "round",
5958
+ strokeLinejoin: "round",
5959
+ strokeWidth: 2,
5960
+ d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
5961
+ }
5962
+ )
5963
+ }
5964
+ ) }),
5965
+ /* @__PURE__ */ jsx("h2", { className: "text-xl font-semibold text-gray-900 mb-2", children: "Oops! Something went wrong." })
5966
+ ] }),
5967
+ /* @__PURE__ */ jsx("p", { className: "text-gray-600 mb-4", children: "We have encountered a critical error and cannot continue. Please try refreshing the page." }),
5968
+ error2 && /* @__PURE__ */ jsx("div", { className: "mt-4 p-3 bg-gray-50 rounded border border-gray-200", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-700 font-mono", children: error2.toString() }) })
5969
+ ] });
5970
+ class ErrorBoundary extends React__default.Component {
5971
+ constructor(props) {
5972
+ super(props);
5973
+ this.state = { hasError: false, error: null, errorInfo: null };
5974
+ }
5975
+ static getDerivedStateFromError(error2) {
5976
+ return { hasError: true, error: error2 };
5977
+ }
5978
+ componentDidCatch(error2, errorInfo) {
5979
+ console.error("ErrorBoundary caught an error", error2, errorInfo);
5980
+ this.setState({ errorInfo });
5981
+ }
5982
+ render() {
5983
+ const { fallback, children: children2 } = this.props;
5984
+ const { hasError, error: error2, errorInfo } = this.state;
5985
+ if (hasError) {
5986
+ if (fallback) {
5987
+ return typeof fallback === "function" ? fallback(error2, errorInfo) : fallback;
5988
+ }
5989
+ return /* @__PURE__ */ jsxs("div", { className: "p-4 border border-red-300 rounded-md bg-red-50 text-red-800", children: [
5990
+ /* @__PURE__ */ jsx("h2", { className: "text-lg font-semibold mb-2", children: "Something went wrong" }),
5991
+ /* @__PURE__ */ jsxs("details", { className: "whitespace-pre-wrap text-sm", children: [
5992
+ /* @__PURE__ */ jsx("summary", { children: "See error details" }),
5993
+ /* @__PURE__ */ jsx("p", { className: "mt-2", children: error2?.toString() }),
5994
+ /* @__PURE__ */ jsx("p", { className: "mt-2", children: errorInfo?.componentStack })
5995
+ ] })
5996
+ ] });
5997
+ }
5998
+ return children2;
5999
+ }
6000
+ }
5890
6001
  function e(e4) {
5891
6002
  function t3(e5, t4) {
5892
6003
  Error.captureStackTrace && Error.captureStackTrace(this, this.constructor), this.message = e5, this.code = t4;
@@ -8077,6 +8188,36 @@ const oe = (e4) => {
8077
8188
  const { ldClient: t3 } = useContext$1(u$1.reactContext);
8078
8189
  return t3;
8079
8190
  };
8191
+ const LaunchDarklyProvider = ({
8192
+ children: children2,
8193
+ tenantExternalId,
8194
+ partnerId
8195
+ }) => {
8196
+ const key = tenantExternalId && partnerId ? `${tenantExternalId}:${partnerId}` : "anonymous";
8197
+ return /* @__PURE__ */ jsx(
8198
+ D$1,
8199
+ {
8200
+ clientSideID: "67a3c277012e1f09c67de499",
8201
+ context: {
8202
+ kind: "user",
8203
+ key,
8204
+ custom: {
8205
+ tenantExternalId,
8206
+ partnerId
8207
+ }
8208
+ },
8209
+ options: {
8210
+ streaming: false
8211
+ },
8212
+ timeout: 2,
8213
+ reactOptions: {
8214
+ useCamelCaseFlagKeys: false,
8215
+ sendEventsOnFlagRead: true
8216
+ },
8217
+ children: children2
8218
+ }
8219
+ );
8220
+ };
8080
8221
  const TOAST_LIMIT = 1;
8081
8222
  const TOAST_REMOVE_DELAY = 1e6;
8082
8223
  let count$6 = 0;
@@ -35053,6 +35194,7 @@ const configDefaults = {
35053
35194
  };
35054
35195
  const Observability = ({
35055
35196
  tenantExternalId,
35197
+ partnerId,
35056
35198
  debug
35057
35199
  }) => {
35058
35200
  const ldClient = oe();
@@ -35093,7 +35235,8 @@ const Observability = ({
35093
35235
  })
35094
35236
  ],
35095
35237
  resourceAttributes: {
35096
- ["tenant.externalId"]: tenantExternalId
35238
+ ["tenant.externalId"]: tenantExternalId,
35239
+ ["partner.id"]: partnerId
35097
35240
  }
35098
35241
  });
35099
35242
  sdk.start();
@@ -35114,7 +35257,6 @@ const Observability = ({
35114
35257
  };
35115
35258
  const ReachProvider = ({
35116
35259
  authToken: authToken2,
35117
- tenantExternalId,
35118
35260
  language,
35119
35261
  children: children2,
35120
35262
  theme: theme2,
@@ -35126,38 +35268,52 @@ const ReachProvider = ({
35126
35268
  }
35127
35269
  return createQueryClient();
35128
35270
  });
35129
- return /* @__PURE__ */ jsx("div", { "data-reach-root": true, className: "h-full w-full", children: /* @__PURE__ */ jsxs(QueryClientProvider, { client: queryClient, children: [
35271
+ let tenantExternalId;
35272
+ let partnerId;
35273
+ try {
35274
+ const decodedToken = jwtDecode(authToken2);
35275
+ tenantExternalId = decodedToken?.tenantExternalId;
35276
+ partnerId = decodedToken?.partnerId || decodedToken?.platformId;
35277
+ if (!tenantExternalId || !partnerId) {
35278
+ throw new Error("Invalid authentication token");
35279
+ }
35280
+ } catch (error2) {
35281
+ return /* @__PURE__ */ jsxs("div", { className: "p-6 max-w-lg mx-auto mt-10 bg-white rounded-lg shadow-md", children: [
35282
+ /* @__PURE__ */ jsx("h2", { className: "text-xl font-semibold text-red-600 mb-4", children: "Authentication Error" }),
35283
+ /* @__PURE__ */ jsx("p", { className: "text-gray-700", children: "The provided authentication token is invalid. Please ensure you're using a valid token." })
35284
+ ] });
35285
+ }
35286
+ return /* @__PURE__ */ jsx(ErrorBoundary, { fallback: /* @__PURE__ */ jsx(ErrorFallback, {}), children: /* @__PURE__ */ jsx("div", { "data-reach-root": true, className: "h-full w-full", children: /* @__PURE__ */ jsxs(QueryClientProvider, { client: queryClient, children: [
35130
35287
  /* @__PURE__ */ jsxs(
35131
- D$1,
35288
+ LaunchDarklyProvider,
35132
35289
  {
35133
- clientSideID: "67a3c277012e1f09c67de499",
35134
- context: {
35135
- kind: "user",
35136
- key: tenantExternalId || "anonymous",
35137
- custom: {
35138
- businessId: tenantExternalId
35139
- // Add any other custom attributes
35140
- }
35141
- },
35142
- options: {
35143
- streaming: false
35144
- },
35145
- timeout: 2,
35146
- reactOptions: {
35147
- useCamelCaseFlagKeys: false,
35148
- sendEventsOnFlagRead: true
35149
- },
35290
+ tenantExternalId,
35291
+ partnerId,
35150
35292
  children: [
35151
- /* @__PURE__ */ jsx(Observability, { tenantExternalId, debug }),
35152
- /* @__PURE__ */ jsx(I18nProvider, { language, initialLanguage: language?.default, children: /* @__PURE__ */ jsx(Provider$1, { initialTheme: theme2, children: /* @__PURE__ */ jsxs(Provider$2, { children: [
35153
- children2,
35154
- /* @__PURE__ */ jsx(Toaster, {})
35155
- ] }) }) })
35293
+ /* @__PURE__ */ jsx(
35294
+ Observability,
35295
+ {
35296
+ tenantExternalId,
35297
+ partnerId,
35298
+ debug
35299
+ }
35300
+ ),
35301
+ /* @__PURE__ */ jsx(
35302
+ I18nProvider,
35303
+ {
35304
+ language,
35305
+ initialLanguage: language?.default,
35306
+ children: /* @__PURE__ */ jsx(Provider$1, { initialTheme: theme2, children: /* @__PURE__ */ jsxs(Provider$2, { children: [
35307
+ children2,
35308
+ /* @__PURE__ */ jsx(Toaster, {})
35309
+ ] }) })
35310
+ }
35311
+ )
35156
35312
  ]
35157
35313
  }
35158
35314
  ),
35159
35315
  debug && /* @__PURE__ */ jsx(ReactQueryDevtools2, {})
35160
- ] }) });
35316
+ ] }) }) });
35161
35317
  };
35162
35318
  function setRef$3(ref, value) {
35163
35319
  if (typeof ref === "function") {
@@ -62672,87 +62828,6 @@ const useSendTestCommunication = () => {
62672
62828
  isSendSuccess: sendTestCommunicationMutation.isSuccess
62673
62829
  };
62674
62830
  };
62675
- var AutomationSteps = /* @__PURE__ */ ((AutomationSteps2) => {
62676
- AutomationSteps2[AutomationSteps2["SelectTrigger"] = 0] = "SelectTrigger";
62677
- AutomationSteps2[AutomationSteps2["SelectAudience"] = 1] = "SelectAudience";
62678
- AutomationSteps2[AutomationSteps2["SelectCommunication"] = 2] = "SelectCommunication";
62679
- AutomationSteps2[AutomationSteps2["PreviewAndSchedule"] = 3] = "PreviewAndSchedule";
62680
- return AutomationSteps2;
62681
- })(AutomationSteps || {});
62682
- const validateAutomationStep = async (args) => {
62683
- const { currentStep, automation: automation2, communicationGroup } = args;
62684
- if (currentStep === 0) {
62685
- return {
62686
- canMove: true,
62687
- errorMessage: null
62688
- };
62689
- }
62690
- if (currentStep === 1) {
62691
- return {
62692
- canMove: automation2.includeSegmentIds.length > 0,
62693
- errorMessage: "Please ensure you have selected at least one segment"
62694
- };
62695
- }
62696
- if (currentStep === 2) {
62697
- const actionDataCommunication = automation2.action_data?.find(
62698
- (action) => action.action_type === "send_communication"
62699
- );
62700
- if (!actionDataCommunication) {
62701
- return {
62702
- canMove: false,
62703
- errorMessage: "Please ensure you have selected either a email communication or text communication"
62704
- };
62705
- }
62706
- if (!communicationGroup || !communicationGroup.sms_channel_sender_id && !communicationGroup.email_channel_sender_id) {
62707
- return {
62708
- canMove: false,
62709
- errorMessage: "Please ensure you have selected either a email communication or text communication"
62710
- };
62711
- }
62712
- if (communicationGroup.email_channel_sender_id) {
62713
- if (!communicationGroup.email_html_body || !communicationGroup.email_subject) {
62714
- return {
62715
- canMove: false,
62716
- errorMessage: "Please ensure you have a email body and subject"
62717
- };
62718
- }
62719
- }
62720
- if (communicationGroup.sms_channel_sender_id) {
62721
- if (!communicationGroup.sms_message_body) {
62722
- return {
62723
- canMove: false,
62724
- errorMessage: "Please ensure you have a sms message body"
62725
- };
62726
- }
62727
- }
62728
- }
62729
- if (currentStep === 3) {
62730
- const isOneTime = isOneTimeTriggerMetadata(automation2.trigger_metadata);
62731
- if (isOneTime) {
62732
- const oneTimeMetadata = automation2.trigger_metadata;
62733
- return {
62734
- canMove: Boolean(
62735
- oneTimeMetadata.scheduled_at && new Date(oneTimeMetadata.scheduled_at) > /* @__PURE__ */ new Date() && automation2.action_data?.some(
62736
- (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
62737
- )
62738
- ),
62739
- errorMessage: "Please ensure you have set a valid future date for your one-time automation"
62740
- };
62741
- }
62742
- return {
62743
- canMove: Boolean(
62744
- automation2.action_data?.some(
62745
- (action) => action.action_type === "send_communication" && action.action_metadata.communication_group_id
62746
- )
62747
- ),
62748
- errorMessage: null
62749
- };
62750
- }
62751
- return {
62752
- canMove: true,
62753
- errorMessage: null
62754
- };
62755
- };
62756
62831
  const useRecipientStats = (automation2) => {
62757
62832
  const { data: estimatedMatches } = useGetCountOfBusinessAutomationRecipients({
62758
62833
  include_segments: automation2?.includeSegmentIds ?? [],
@@ -62773,29 +62848,66 @@ const useRecipientStats = (automation2) => {
62773
62848
  estimatedMatchesStats
62774
62849
  };
62775
62850
  };
62776
- 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
+ }) => {
62777
62898
  const mountedRef = useRef(true);
62778
- const [manualLoading, setManualLoading] = useState(false);
62779
- const {
62780
- automation: fetchedAutomation,
62781
- isLoading: isFetchLoading,
62782
- invalidateAutomation: originalInvalidateAutomation
62783
- } = useGetBusinessAutomation(automationId);
62784
- const automation2 = fetchedAutomation;
62785
- const { updateAutomation: updateAutomation2, isUpdating } = useUpdateBusinessAutomation(automationId);
62899
+ const { automation: fetchedAutomation, isLoading: isFetchLoading } = useGetBusinessAutomation(automationId);
62900
+ const automation2 = existingAutomation || fetchedAutomation;
62901
+ const { isUpdating } = useUpdateBusinessAutomation(automationId);
62786
62902
  const communicationGroupId = automation2?.action_data?.find(
62787
62903
  (action) => action.action_type === "send_communication"
62788
62904
  )?.action_metadata.communication_group_id;
62789
62905
  const { communicationGroup, isGetting: isLoadingCommunicationGroup } = useGetCommunicationGroup(communicationGroupId || void 0);
62790
- const { updateCommunicationGroup: updateCommunicationGroup2, isUpdating: isUpdatingCommunicationGroup } = useUpdateCommunicationGroup();
62906
+ const { isUpdating: isUpdatingCommunicationGroup } = useUpdateCommunicationGroup();
62791
62907
  const { estimatedMatchesStats } = useRecipientStats(automation2);
62792
- const [isValidatingStep, setIsValidatingStep] = useState(false);
62793
62908
  const [isLoading, setIsLoading] = useState(false);
62794
- const invalidateAutomation = useCallback(() => {
62795
- originalInvalidateAutomation();
62796
- }, [originalInvalidateAutomation]);
62797
62909
  useEffect(() => {
62798
- const loadingState = (isFetchLoading || isUpdating || isLoadingCommunicationGroup || isValidatingStep || isUpdatingCommunicationGroup || manualLoading) && mountedRef.current;
62910
+ const loadingState = (!existingAutomation && isFetchLoading || isUpdating || isLoadingCommunicationGroup || isUpdatingCommunicationGroup) && mountedRef.current;
62799
62911
  setIsLoading(loadingState);
62800
62912
  }, [
62801
62913
  existingAutomation,
@@ -62803,54 +62915,46 @@ const useAutomation = (automationId, existingAutomation) => {
62803
62915
  isFetchLoading,
62804
62916
  isUpdating,
62805
62917
  isLoadingCommunicationGroup,
62806
- isValidatingStep,
62807
- isUpdatingCommunicationGroup,
62808
- manualLoading
62918
+ isUpdatingCommunicationGroup
62809
62919
  ]);
62810
62920
  useEffect(() => {
62811
62921
  return () => {
62812
62922
  mountedRef.current = false;
62813
62923
  };
62814
62924
  }, []);
62815
- const validateStep = useCallback(
62816
- async (currentStep) => {
62817
- if (!automation2) {
62818
- return {
62819
- canMove: false,
62820
- errorMessage: "Automation not loaded"
62821
- };
62822
- }
62823
- try {
62824
- setIsValidatingStep(true);
62825
- return await validateAutomationStep({
62826
- currentStep,
62827
- automation: automation2,
62828
- communicationGroup
62829
- });
62830
- } finally {
62831
- if (mountedRef.current) {
62832
- 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
+ )
62833
62954
  }
62834
- }
62835
- },
62836
- [automation2, communicationGroup]
62837
- );
62838
- const setIsLoadingSafe = useCallback((loading2) => {
62839
- if (mountedRef.current) {
62840
- setManualLoading(loading2);
62955
+ )
62841
62956
  }
62842
- }, []);
62843
- return {
62844
- automation: automation2,
62845
- updateAutomation: updateAutomation2,
62846
- communicationGroup,
62847
- updateCommunicationGroup: updateCommunicationGroup2,
62848
- isLoading,
62849
- setIsLoading: setIsLoadingSafe,
62850
- invalidateAutomation,
62851
- validateStep,
62852
- estimatedMatchesStats
62853
- };
62957
+ );
62854
62958
  };
62855
62959
  const getChannelSenders = async () => {
62856
62960
  const response = await baseRequest(
@@ -63135,13 +63239,13 @@ ${smsPreview.body}` : smsPreview.body
63135
63239
  };
63136
63240
  const AutomationContent = ({
63137
63241
  iconDefinitions,
63138
- isLoading: isLoadingCommunicationGroup,
63139
- communicationGroup
63242
+ isLoading: isLoadingCommunicationGroup
63140
63243
  }) => {
63141
63244
  const { channelSenders } = useChannelSender();
63142
63245
  const [emailData, setEmailData] = useState(null);
63143
63246
  const [smsData, setSmsData] = useState(null);
63144
63247
  const [loading2, setLoading2] = useState(false);
63248
+ const { communicationGroup } = useCommunication();
63145
63249
  useEffect(() => {
63146
63250
  if (!communicationGroup || !channelSenders) {
63147
63251
  setLoading2(false);
@@ -64934,6 +65038,87 @@ const StepIndicator = ({
64934
65038
  )
64935
65039
  ] });
64936
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
+ };
64937
65122
  const mergeFieldTemplateCreator = (args) => {
64938
65123
  const { mergeFieldName } = args;
64939
65124
  return `{{${mergeFieldName}}}`;
@@ -65229,24 +65414,22 @@ const StripoWrapper = ({
65229
65414
  }
65230
65415
  ) });
65231
65416
  };
65232
- const EmailPreview = ({
65233
- automation: automation2,
65234
- mergeFieldsResponse,
65235
- communicationGroup,
65236
- updateCommunicationGroup: updateCommunicationGroup2
65237
- }) => {
65417
+ const EmailPreview = ({ mergeFieldsResponse }) => {
65418
+ const { communicationGroup } = useCommunication();
65419
+ const { automation: automation2 } = useAutomation();
65420
+ const { updateCommunicationGroup: updateCommunicationGroup2 } = useUpdateCommunicationGroup();
65238
65421
  const [isUpdating, setIsUpdating] = useState(false);
65239
65422
  const [fromEmail, setFromEmail] = useState(
65240
- communicationGroup.email_channel_sender_id || null
65423
+ communicationGroup?.email_channel_sender_id || null
65241
65424
  );
65242
65425
  const [subject, setSubject] = useState(
65243
- communicationGroup.email_subject || null
65426
+ communicationGroup?.email_subject || null
65244
65427
  );
65245
65428
  const [previewText, setPreviewText] = useState(
65246
- communicationGroup.email_preview_text || null
65429
+ communicationGroup?.email_preview_text || null
65247
65430
  );
65248
65431
  const [body, setBody] = useState(
65249
- communicationGroup.email_html_body || null
65432
+ communicationGroup?.email_html_body || null
65250
65433
  );
65251
65434
  const [showStripoEditor, setShowStripoEditor] = useState(false);
65252
65435
  const [saveClicked, setSaveClicked] = useState(false);
@@ -65256,7 +65439,7 @@ const EmailPreview = ({
65256
65439
  null
65257
65440
  );
65258
65441
  const { refetchAutomation: refreshAutomation } = useGetBusinessAutomation(
65259
- automation2.id
65442
+ automation2?.id || ""
65260
65443
  );
65261
65444
  const [showHelpDialog, setShowHelpDialog] = useState(false);
65262
65445
  const initialRenderRef = useRef(true);
@@ -65306,10 +65489,10 @@ const EmailPreview = ({
65306
65489
  return () => clearTimeout(timer);
65307
65490
  }, []);
65308
65491
  useEffect(() => {
65309
- if (communicationGroup.email_html_body) {
65492
+ if (communicationGroup?.email_html_body) {
65310
65493
  setBody(communicationGroup.email_html_body);
65311
65494
  }
65312
- }, [communicationGroup.email_html_body, refreshAutomation]);
65495
+ }, [communicationGroup?.email_html_body, refreshAutomation]);
65313
65496
  useEffect(() => {
65314
65497
  if (isUpdating) {
65315
65498
  const timer = setTimeout(() => {
@@ -65332,7 +65515,7 @@ const EmailPreview = ({
65332
65515
  };
65333
65516
  }, []);
65334
65517
  useEffect(() => {
65335
- if (!initialRenderRef.current && fromEmail && debouncedSubject && body && communicationGroup.id) {
65518
+ if (!initialRenderRef.current && fromEmail && debouncedSubject && body && communicationGroup?.id) {
65336
65519
  setIsUpdating(true);
65337
65520
  const updateGroup = async () => {
65338
65521
  try {
@@ -65360,7 +65543,7 @@ const EmailPreview = ({
65360
65543
  debouncedSubject,
65361
65544
  debouncedPreviewText,
65362
65545
  body,
65363
- communicationGroup.id,
65546
+ communicationGroup?.id,
65364
65547
  updateCommunicationGroup2
65365
65548
  ]);
65366
65549
  useEffect(() => {
@@ -65386,7 +65569,7 @@ const EmailPreview = ({
65386
65569
  const channelSender = allEmailSenders[0];
65387
65570
  setFromEmail(channelSender.id);
65388
65571
  updateCommunicationGroup2({
65389
- groupId: communicationGroup.id,
65572
+ groupId: communicationGroup?.id || "",
65390
65573
  params: {
65391
65574
  email_channel_sender_id: channelSender.id
65392
65575
  }
@@ -65396,7 +65579,7 @@ const EmailPreview = ({
65396
65579
  }, [
65397
65580
  channelSenders?.results,
65398
65581
  fromEmail,
65399
- communicationGroup.id,
65582
+ communicationGroup?.id,
65400
65583
  updateCommunicationGroup2
65401
65584
  ]);
65402
65585
  useEffect(() => {
@@ -65478,10 +65661,10 @@ const EmailPreview = ({
65478
65661
  replyToEmailError
65479
65662
  ]);
65480
65663
  useEffect(() => {
65481
- if (showStripoEditor === false && communicationGroup.id) {
65664
+ if (showStripoEditor === false && communicationGroup?.id) {
65482
65665
  refreshAutomation();
65483
65666
  }
65484
- }, [showStripoEditor, communicationGroup.id, refreshAutomation]);
65667
+ }, [showStripoEditor, communicationGroup?.id, refreshAutomation]);
65485
65668
  if (!channelAccounts || !channelSenders) {
65486
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..."] }) });
65487
65670
  }
@@ -65519,7 +65702,7 @@ const EmailPreview = ({
65519
65702
  }
65520
65703
  )
65521
65704
  ] }),
65522
- /* @__PURE__ */ jsx("div", { className: " w-full", children: /* @__PURE__ */ jsx(
65705
+ /* @__PURE__ */ jsx("div", { className: " w-full", children: automation2 && /* @__PURE__ */ jsx(
65523
65706
  StripoWrapper,
65524
65707
  {
65525
65708
  showStripoEditor,
@@ -65909,14 +66092,15 @@ const useMe = () => {
65909
66092
  });
65910
66093
  return query;
65911
66094
  };
65912
- const SMSPreview = ({ automation: automation2, iconDefinitions, mergeFieldsResponse }) => {
66095
+ const SMSPreview = ({ iconDefinitions, mergeFieldsResponse }) => {
66096
+ const { automation: automation2 } = useAutomation();
65913
66097
  const [isUpdating, setIsUpdating] = useState(false);
65914
66098
  const _getCommunicationGroupFromAutomation = useCallback(() => {
65915
- const actionGroup = automation2.action_data?.find(
66099
+ const actionGroup = automation2?.action_data?.find(
65916
66100
  (action) => action.action_type === "send_communication"
65917
66101
  );
65918
66102
  return actionGroup?.action_metadata.communication_group_id;
65919
- }, [automation2.action_data]);
66103
+ }, [automation2?.action_data]);
65920
66104
  const [mergeFieldValue, setMergeFieldValue] = useState("");
65921
66105
  const [fromNumber, setFromNumber] = useState(null);
65922
66106
  const [initCompanyName, setInitCompanyName] = useState(false);
@@ -66140,16 +66324,15 @@ ${message2}` : message2
66140
66324
  ] });
66141
66325
  };
66142
66326
  const EditCampaignContent = ({
66143
- automation: automation2,
66144
66327
  iconDefinitions,
66145
- getExtraMergeFields,
66146
- communicationGroup,
66147
- updateAutomation: updateAutomation2,
66148
- updateCommunicationGroup: updateCommunicationGroup2
66328
+ getExtraMergeFields
66149
66329
  }) => {
66150
66330
  const [selectedChannels, setSelectedChannels] = useState(null);
66151
66331
  const emailContainerRef = useRef(null);
66152
66332
  const { toast: toast2 } = useToast();
66333
+ const { communicationGroup } = useCommunication();
66334
+ const { updateCommunicationGroup: updateCommunicationGroup2 } = useUpdateCommunicationGroup();
66335
+ const { automation: automation2 } = useAutomation();
66153
66336
  const { getMergeFields: getMergeFields2, isGetting: isGetMergeFieldsLoading } = useGetMergeFields(communicationGroup?.id ?? void 0);
66154
66337
  const [mergeFieldsResponse, setMergeFieldsResponse] = useState(void 0);
66155
66338
  useEffect(() => {
@@ -66352,11 +66535,7 @@ const EditCampaignContent = ({
66352
66535
  /* @__PURE__ */ jsx(
66353
66536
  EmailPreview,
66354
66537
  {
66355
- automation: automation2,
66356
66538
  iconDefinitions,
66357
- updateAutomation: updateAutomation2,
66358
- communicationGroup,
66359
- updateCommunicationGroup: updateCommunicationGroup2,
66360
66539
  mergeFieldsResponse
66361
66540
  }
66362
66541
  )
@@ -66368,7 +66547,6 @@ const EditCampaignContent = ({
66368
66547
  /* @__PURE__ */ jsx(
66369
66548
  SMSPreview,
66370
66549
  {
66371
- automation: automation2,
66372
66550
  iconDefinitions,
66373
66551
  mergeFieldsResponse
66374
66552
  }
@@ -66877,13 +67055,12 @@ const SelectTime = ({ iconDefinitions, automation: automation2, updateAutomation
66877
67055
  ) });
66878
67056
  };
66879
67057
  const PreviewAndSchedule = ({
66880
- automation: automation2,
66881
67058
  iconDefinitions,
66882
- isLoading,
66883
- communicationGroup,
66884
67059
  updateAutomation: externalUpdateAutomation
66885
67060
  }) => {
66886
- const { updateAutomation: businessUpdateAutomation } = useUpdateBusinessAutomation(automation2.id);
67061
+ const { automation: automation2 } = useAutomation();
67062
+ const { communicationGroup } = useCommunication();
67063
+ const { updateAutomation: businessUpdateAutomation } = useUpdateBusinessAutomation(automation2?.id || "");
66887
67064
  const updateAutomation2 = externalUpdateAutomation || ((params) => businessUpdateAutomation(params));
66888
67065
  const { channelSenders } = useChannelSender();
66889
67066
  const { channelAccounts } = useChannelAccount();
@@ -66948,7 +67125,7 @@ const PreviewAndSchedule = ({
66948
67125
  }
66949
67126
  }
66950
67127
  }, [communicationGroup, channelSenderData, channelAccountsData]);
66951
- if (isLoading) {
67128
+ if (!automation2) {
66952
67129
  return /* @__PURE__ */ jsx(BasicLoader, { text: ["Loading..."] });
66953
67130
  }
66954
67131
  if (!emailPreview && !smsPreview) {
@@ -66969,8 +67146,8 @@ const PreviewAndSchedule = ({
66969
67146
  {
66970
67147
  subtitle: "Estimated recipient count may vary at time of delivery",
66971
67148
  iconDefinitions,
66972
- includeSegments: automation2.includeSegmentIds,
66973
- excludeSegments: automation2.excludeSegmentIds
67149
+ includeSegments: automation2.includeSegmentIds || [],
67150
+ excludeSegments: automation2.excludeSegmentIds || []
66974
67151
  }
66975
67152
  )
66976
67153
  ] }),
@@ -67404,15 +67581,12 @@ const TriggerEditAutomation = ({ automation: automation2 }) => {
67404
67581
  }
67405
67582
  ) });
67406
67583
  };
67407
- const useAutomationSteps = ({
67584
+ const getAutomationSteps = ({
67408
67585
  automation: automation2,
67409
- updateAutomation: updateAutomation2,
67410
67586
  communicationGroup,
67411
- updateCommunicationGroup: updateCommunicationGroup2,
67412
67587
  iconDefinitions,
67413
67588
  getExtraMergeFields,
67414
- handleSaveAsDraft,
67415
- isLoading
67589
+ handleSaveAsDraft
67416
67590
  }) => {
67417
67591
  if (!automation2) return [];
67418
67592
  return [
@@ -67508,10 +67682,6 @@ const useAutomationSteps = ({
67508
67682
  /* @__PURE__ */ jsx(
67509
67683
  EditCampaignContent,
67510
67684
  {
67511
- automation: automation2,
67512
- updateAutomation: updateAutomation2,
67513
- communicationGroup,
67514
- updateCommunicationGroup: updateCommunicationGroup2,
67515
67685
  iconDefinitions,
67516
67686
  getExtraMergeFields
67517
67687
  }
@@ -67544,15 +67714,7 @@ const useAutomationSteps = ({
67544
67714
  {
67545
67715
  className: "flex-1",
67546
67716
  title: "Preview and Schedule",
67547
- content: /* @__PURE__ */ jsx(
67548
- PreviewAndSchedule,
67549
- {
67550
- automation: automation2,
67551
- iconDefinitions,
67552
- isLoading,
67553
- communicationGroup
67554
- }
67555
- )
67717
+ content: /* @__PURE__ */ jsx(PreviewAndSchedule, { iconDefinitions })
67556
67718
  },
67557
67719
  "send"
67558
67720
  ),
@@ -67587,6 +67749,29 @@ const useAutomationSteps = ({
67587
67749
  }
67588
67750
  ];
67589
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
+ };
67590
67775
  const BackNextButtonGroup = ({
67591
67776
  iconDefinitions,
67592
67777
  handleBack,
@@ -67643,30 +67828,38 @@ const BackNextButtonGroup = ({
67643
67828
  ] });
67644
67829
  };
67645
67830
  const EditAutomation = ({
67646
- automation: automation2,
67647
- updateAutomation: updateAutomation2,
67648
- communicationGroup,
67649
- updateCommunicationGroup: updateCommunicationGroup2,
67650
67831
  iconDefinitions,
67651
67832
  setOpenEditAutomationPopup,
67652
67833
  logoUrl,
67653
67834
  getExtraMergeFields,
67654
- onBeforeSchedule,
67655
- estimatedMatchesStats,
67656
- isLoading,
67657
- validateCanGoToNextStep,
67658
- setIsLoading
67835
+ onBeforeSchedule
67659
67836
  }) => {
67660
67837
  const { toast: toast2 } = useToast();
67838
+ const { automation: automation2 } = useAutomation();
67839
+ const { communicationGroup } = useCommunication();
67840
+ const { estimatedMatchesStats } = useValidation();
67661
67841
  const [currentStep, setCurrentStep] = useState(
67662
- /**
67663
- * We dont show the trigger step for trigger based automations
67664
- */
67665
- automation2.trigger_type === AutomationTriggerType.TRIGGER_BASED ? AutomationSteps.SelectTrigger : AutomationSteps.SelectAudience
67842
+ void 0
67666
67843
  );
67667
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
+ }
67668
67859
  const handleSaveAsDraft = () => {
67669
- setIsLoading(true);
67860
+ if (!automation2) {
67861
+ return;
67862
+ }
67670
67863
  updateAutomation2({
67671
67864
  status: AutomationStatus.DRAFT
67672
67865
  });
@@ -67675,21 +67868,14 @@ const EditAutomation = ({
67675
67868
  title: "Automation saved as draft",
67676
67869
  description: "You can continue editing it later"
67677
67870
  });
67678
- setIsLoading(false);
67679
67871
  };
67680
- const STEPS = useAutomationSteps({
67872
+ const STEPS = getAutomationSteps({
67681
67873
  automation: automation2,
67874
+ communicationGroup,
67682
67875
  iconDefinitions,
67683
67876
  getExtraMergeFields,
67684
- handleSaveAsDraft,
67685
- isLoading,
67686
- communicationGroup,
67687
- updateAutomation: updateAutomation2,
67688
- updateCommunicationGroup: updateCommunicationGroup2
67877
+ handleSaveAsDraft
67689
67878
  });
67690
- if (isLoading) {
67691
- 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"] }) });
67692
- }
67693
67879
  const handleScheduleAutomation = async () => {
67694
67880
  if (onBeforeSchedule) {
67695
67881
  try {
@@ -67698,7 +67884,6 @@ const EditAutomation = ({
67698
67884
  estimatedSmsRecipients: estimatedMatchesStats.phones
67699
67885
  });
67700
67886
  if (result === true) {
67701
- setIsLoading(true);
67702
67887
  updateAutomation2({
67703
67888
  status: AutomationStatus.ACTIVE
67704
67889
  });
@@ -67706,7 +67891,6 @@ const EditAutomation = ({
67706
67891
  toast2({
67707
67892
  title: "Automation scheduled!"
67708
67893
  });
67709
- setIsLoading(false);
67710
67894
  } else {
67711
67895
  toast2({
67712
67896
  title: "Oops!",
@@ -67722,21 +67906,15 @@ const EditAutomation = ({
67722
67906
  });
67723
67907
  }
67724
67908
  } else {
67725
- setIsLoading(true);
67726
67909
  updateAutomation2({ status: AutomationStatus.ACTIVE });
67727
67910
  setOpenEditAutomationPopup(false);
67728
67911
  toast2({
67729
67912
  title: "Automation scheduled!"
67730
67913
  });
67731
- setIsLoading(false);
67732
67914
  }
67733
67915
  };
67734
67916
  const handleNextStep = async () => {
67735
- const { canMove, errorMessage } = await validateCanGoToNextStep({
67736
- currentStep,
67737
- automation: automation2,
67738
- communicationGroup
67739
- });
67917
+ const { canMove, errorMessage } = await validateStep(currentStep);
67740
67918
  if (!canMove) {
67741
67919
  toast2({
67742
67920
  title: "Oops!",
@@ -67763,11 +67941,7 @@ const EditAutomation = ({
67763
67941
  setIsValidatingStep(true);
67764
67942
  try {
67765
67943
  for (let step = currentStep; step < targetStep; step++) {
67766
- const { canMove, errorMessage } = await validateCanGoToNextStep({
67767
- currentStep: step,
67768
- automation: automation2,
67769
- communicationGroup
67770
- });
67944
+ const { canMove, errorMessage } = await validateStep(step);
67771
67945
  if (!canMove) {
67772
67946
  return { canMove, errorMessage };
67773
67947
  }
@@ -68027,21 +68201,12 @@ const SendPreviewPopup = ({ automation: automation2, type, setOpenSendPreviewPop
68027
68201
  ] });
68028
68202
  };
68029
68203
  const ViewAutomationHeaderContainer = ({
68030
- automation: automation2,
68031
- updateAutomation: updateAutomation2,
68032
- communicationGroup,
68033
- updateCommunicationGroup: updateCommunicationGroup2,
68034
- isLoading,
68035
- setIsLoading,
68036
68204
  iconDefinitions,
68037
68205
  autoOpenEditPopup,
68038
68206
  logoUrl,
68039
68207
  getExtraMergeFields,
68040
68208
  onDuplicationCreated,
68041
68209
  onBeforeSchedule,
68042
- invalidateAutomation,
68043
- estimatedMatchesStats,
68044
- validateStep,
68045
68210
  showBackButton = false
68046
68211
  }) => {
68047
68212
  const [openEditAutomationPopup, setOpenEditAutomationPopup] = useState(false);
@@ -68051,6 +68216,13 @@ const ViewAutomationHeaderContainer = ({
68051
68216
  setCancelAutomationConfirmationPopup
68052
68217
  ] = useState(false);
68053
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
+ );
68054
68226
  const mergedIconDefinitions = mergeIconDefinitions(iconDefinitions);
68055
68227
  const navigate = useNavigate();
68056
68228
  const { toast: toast2 } = useToast();
@@ -68077,6 +68249,13 @@ const ViewAutomationHeaderContainer = ({
68077
68249
  updateAutomation2({ status: AutomationStatus.DRAFT });
68078
68250
  };
68079
68251
  const handleDuplicateAutomation = async () => {
68252
+ if (!automation2) {
68253
+ toast2({
68254
+ title: "Error duplicating automation",
68255
+ description: "Please try again"
68256
+ });
68257
+ return;
68258
+ }
68080
68259
  const { id: duplicatedId } = await duplicateBusinessAutomation(
68081
68260
  automation2.id
68082
68261
  );
@@ -68095,9 +68274,9 @@ const ViewAutomationHeaderContainer = ({
68095
68274
  description: "The automation has been duplicated"
68096
68275
  });
68097
68276
  };
68098
- const validateStepAdapter = async (args) => {
68099
- return validateStep(args.currentStep);
68100
- };
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
+ }
68101
68280
  const renderEditAutomationDialog = () => /* @__PURE__ */ jsx(
68102
68281
  Dialog,
68103
68282
  {
@@ -68116,19 +68295,11 @@ const ViewAutomationHeaderContainer = ({
68116
68295
  /* @__PURE__ */ jsx(
68117
68296
  EditAutomation,
68118
68297
  {
68119
- automation: automation2,
68120
- updateAutomation: updateAutomation2,
68121
- communicationGroup,
68122
- updateCommunicationGroup: updateCommunicationGroup2,
68123
- isLoading,
68124
- setIsLoading,
68125
68298
  iconDefinitions: mergedIconDefinitions,
68126
68299
  setOpenEditAutomationPopup,
68127
68300
  logoUrl,
68128
68301
  getExtraMergeFields,
68129
- onBeforeSchedule,
68130
- estimatedMatchesStats,
68131
- validateCanGoToNextStep: validateStepAdapter
68302
+ onBeforeSchedule
68132
68303
  }
68133
68304
  )
68134
68305
  ]
@@ -68289,57 +68460,34 @@ const ViewAutomationHeaderContainer = ({
68289
68460
  ] });
68290
68461
  };
68291
68462
  const ViewAutomationHeader = React__default.memo(ViewAutomationHeaderContainer);
68292
- const ViewAutomationContent = ({
68293
- iconDefinitions,
68463
+ const ViewAutomationWrapper = ({
68294
68464
  autoOpenEditPopup,
68295
- automationId,
68296
68465
  showBackButton = false,
68297
68466
  logoUrl,
68298
68467
  getExtraMergeFields,
68299
68468
  onDuplicationCreated,
68300
- onBeforeSchedule
68469
+ onBeforeSchedule,
68470
+ iconDefinitions
68301
68471
  }) => {
68302
- const params = useParams();
68303
- const [searchParams] = useSearchParams();
68472
+ const { automation: automation2 } = useAutomation();
68473
+ const { communicationGroup } = useCommunication();
68474
+ const { isLoading } = useLoading();
68304
68475
  const finalIconDefinitions = mergeIconDefinitions(iconDefinitions);
68305
68476
  const [activeTab, setActiveTab] = React__default.useState("content");
68306
- const effectiveAutomationId = automationId || params?.automationId || searchParams.get("automationId") || "";
68307
- const shouldAutoOpenEditPopup = autoOpenEditPopup || searchParams.get("autoOpenEditPopup");
68308
- const shouldShowBackButton = searchParams.get("showBackButton") === "true" || showBackButton;
68309
- const {
68310
- automation: automation2,
68311
- updateAutomation: updateAutomation2,
68312
- communicationGroup,
68313
- updateCommunicationGroup: updateCommunicationGroup2,
68314
- isLoading,
68315
- setIsLoading,
68316
- invalidateAutomation,
68317
- validateStep,
68318
- estimatedMatchesStats
68319
- } = useAutomation(effectiveAutomationId);
68320
68477
  if (!automation2 || !communicationGroup) {
68321
68478
  return /* @__PURE__ */ jsx("div", { className: "flex h-screen items-center justify-center", children: /* @__PURE__ */ jsx(BasicLoader, { text: ["Fetching Automation data", "Finishing up"] }) });
68322
68479
  }
68323
- return /* @__PURE__ */ jsxs("div", { className: "bg-background", children: [
68480
+ return /* @__PURE__ */ jsxs("div", { children: [
68324
68481
  /* @__PURE__ */ jsx(
68325
68482
  ViewAutomationHeader,
68326
68483
  {
68327
- automation: automation2,
68328
- updateAutomation: updateAutomation2,
68329
- communicationGroup,
68330
- updateCommunicationGroup: updateCommunicationGroup2,
68331
- isLoading,
68332
- setIsLoading,
68333
68484
  iconDefinitions: finalIconDefinitions,
68334
- autoOpenEditPopup: shouldAutoOpenEditPopup,
68335
- showBackButton: shouldShowBackButton,
68485
+ autoOpenEditPopup,
68486
+ showBackButton,
68336
68487
  logoUrl,
68337
68488
  getExtraMergeFields,
68338
68489
  onDuplicationCreated,
68339
- onBeforeSchedule,
68340
- invalidateAutomation,
68341
- estimatedMatchesStats,
68342
- validateStep
68490
+ onBeforeSchedule
68343
68491
  }
68344
68492
  ),
68345
68493
  /* @__PURE__ */ jsx(
@@ -68353,8 +68501,7 @@ const ViewAutomationContent = ({
68353
68501
  AutomationContent,
68354
68502
  {
68355
68503
  iconDefinitions: finalIconDefinitions,
68356
- isLoading,
68357
- communicationGroup
68504
+ isLoading
68358
68505
  }
68359
68506
  )
68360
68507
  },
@@ -68379,6 +68526,21 @@ const ViewAutomationContent = ({
68379
68526
  )
68380
68527
  ] });
68381
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
+ };
68382
68544
  const ViewAutomation = ({ inRouter = false, ...props }) => inRouter ? /* @__PURE__ */ jsx(ViewAutomationContent, { ...props }) : /* @__PURE__ */ jsx(MemoryRouter, { children: /* @__PURE__ */ jsx(ViewAutomationContent, { ...props }) });
68383
68545
  Object.values(
68384
68546
  /* @__PURE__ */ Object.assign({})