@embedreach/components 0.2.69 → 0.2.71

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.
@@ -77831,23 +77831,6 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
77831
77831
  smsApplication
77832
77832
  });
77833
77833
  }, [channelSenders, channelAccounts, smsApplication]);
77834
- useEffect(() => {
77835
- if (showSmsEditor) {
77836
- if (editingMessage === null) {
77837
- setEditingMessage(message2);
77838
- }
77839
- if (imageUrls.length > 0 && !imagePreview && !isRemovingImage) {
77840
- setImagePreview(imageUrls[0]);
77841
- }
77842
- }
77843
- }, [
77844
- showSmsEditor,
77845
- message2,
77846
- imageUrls,
77847
- imagePreview,
77848
- isRemovingImage,
77849
- editingMessage
77850
- ]);
77851
77834
  useEffect(() => {
77852
77835
  if (!showSmsEditor) {
77853
77836
  setImagePreview(imageUrls.length > 0 ? imageUrls[0] : null);
@@ -77855,6 +77838,11 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
77855
77838
  setIsRemovingImage(false);
77856
77839
  }
77857
77840
  }, [showSmsEditor, imageUrls]);
77841
+ useEffect(() => {
77842
+ if (communicationGroup?.textMessageMediaUrls) {
77843
+ setImageUrls(communicationGroup.textMessageMediaUrls);
77844
+ }
77845
+ }, [communicationGroup?.textMessageMediaUrls]);
77858
77846
  const handleSaveSMS = () => {
77859
77847
  if (editingMessage && editingMessage.length > SMS_ABSOLUTE_LIMIT) {
77860
77848
  toast2({
@@ -77863,6 +77851,13 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
77863
77851
  });
77864
77852
  return;
77865
77853
  }
77854
+ if (editingMessage === null || editingMessage.length === 0) {
77855
+ toast2({
77856
+ title: "Oops",
77857
+ description: "Please enter a message"
77858
+ });
77859
+ return;
77860
+ }
77866
77861
  setMessage(editingMessage);
77867
77862
  const communicationGroupId = _getCommunicationGroupFromAutomation();
77868
77863
  if (communicationGroupId) {
@@ -77903,12 +77898,36 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
77903
77898
  setIsRemovingImage(false);
77904
77899
  };
77905
77900
  const handleRemoveImage = () => {
77906
- setImagePreview(null);
77907
- setImageBase64(null);
77908
- setIsRemovingImage(false);
77909
77901
  if (fileInputRef.current) {
77910
77902
  fileInputRef.current.value = "";
77911
77903
  }
77904
+ if (communicationGroup?.id) {
77905
+ updateCommunicationGroup2(
77906
+ {
77907
+ groupId: communicationGroup.id,
77908
+ params: {
77909
+ textMessageMedia: []
77910
+ }
77911
+ },
77912
+ {
77913
+ onSuccess: () => {
77914
+ setImagePreview(null);
77915
+ setImageBase64(null);
77916
+ setIsRemovingImage(false);
77917
+ setImageUrls([]);
77918
+ if (fileInputRef.current) {
77919
+ fileInputRef.current.value = "";
77920
+ }
77921
+ },
77922
+ onError: () => {
77923
+ toast2({
77924
+ title: "Error removing image",
77925
+ description: "Please contact your administrator"
77926
+ });
77927
+ }
77928
+ }
77929
+ );
77930
+ }
77912
77931
  };
77913
77932
  const handleImageUpload = async (event) => {
77914
77933
  const file = event.target.files?.[0];
@@ -77921,6 +77940,22 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
77921
77940
  setImageBase64(base64String);
77922
77941
  setImagePreview(pngDataUrl);
77923
77942
  setIsRemovingImage(false);
77943
+ if (communicationGroup?.id) {
77944
+ updateCommunicationGroup2(
77945
+ {
77946
+ groupId: communicationGroup.id,
77947
+ params: { textMessageMedia: [base64String] }
77948
+ },
77949
+ {
77950
+ onError: () => {
77951
+ toast2({
77952
+ title: "Error updating image",
77953
+ description: "Please contact your administrator"
77954
+ });
77955
+ }
77956
+ }
77957
+ );
77958
+ }
77924
77959
  } catch (error2) {
77925
77960
  console.error("Failed to convert image:", error2);
77926
77961
  toast2({
@@ -77941,12 +77976,13 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
77941
77976
  )?.channelSender.channelSenderMetadata.from ?? channelSenderId;
77942
77977
  };
77943
77978
  useEffect(() => {
77944
- if (communicationGroup) {
77945
- if (fromNumber === null) {
77979
+ if (communicationGroup && initialState2 === false) {
77980
+ if (communicationGroup.smsChannelSenderId && fromNumber === null) {
77946
77981
  setFromNumber(communicationGroup.smsChannelSenderId);
77947
77982
  }
77948
- if (message2 === null) {
77983
+ if (communicationGroup.smsMessageBody && message2 === null) {
77949
77984
  setMessage(communicationGroup.smsMessageBody);
77985
+ setEditingMessage(communicationGroup.smsMessageBody);
77950
77986
  }
77951
77987
  if (communicationGroup.textMessageCompanyName && companyName === null) {
77952
77988
  setCompanyName(communicationGroup.textMessageCompanyName);
@@ -77954,49 +77990,58 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
77954
77990
  if (communicationGroup.textMessageMediaUrls && imageUrls.length === 0) {
77955
77991
  setImageUrls(communicationGroup.textMessageMediaUrls);
77956
77992
  }
77957
- setInitialState(true);
77958
- }
77959
- }, [communicationGroup, fromNumber, message2, companyName, imageUrls]);
77960
- const updateCompanyName = (newCompanyName) => {
77961
- setCompanyName(newCompanyName);
77962
- };
77963
- useEffect(() => {
77964
- if (channelSenders === void 0 || !initialState2) {
77965
- return;
77966
- }
77967
- if (!fromNumber) {
77968
- if (smsChannelSenders?.[0]) {
77969
- setFromNumber(smsChannelSenders[0].channelSender.id);
77970
- if (communicationGroup?.id) {
77971
- updateCommunicationGroup2({
77972
- groupId: communicationGroup.id,
77973
- params: {
77974
- smsChannelSenderId: smsChannelSenders[0].channelSender.id
77975
- }
77976
- });
77993
+ if (showSmsEditor) {
77994
+ if (editingMessage === null) {
77995
+ setEditingMessage(message2);
77996
+ }
77997
+ if (imageUrls.length > 0 && !imagePreview && !isRemovingImage) {
77998
+ setImagePreview(imageUrls[0]);
77977
77999
  }
77978
78000
  }
77979
- } else if (fromNumber) {
77980
- if (communicationGroup?.id) {
77981
- updateCommunicationGroup2({
77982
- groupId: communicationGroup.id,
77983
- params: {
77984
- smsChannelSenderId: fromNumber
78001
+ if (channelSenders !== void 0) {
78002
+ if (!fromNumber) {
78003
+ if (smsChannelSenders?.[0]) {
78004
+ setFromNumber(smsChannelSenders[0].channelSender.id);
78005
+ if (communicationGroup?.id) {
78006
+ updateCommunicationGroup2({
78007
+ groupId: communicationGroup.id,
78008
+ params: {
78009
+ smsChannelSenderId: smsChannelSenders[0].channelSender.id
78010
+ }
78011
+ });
78012
+ }
77985
78013
  }
77986
- });
78014
+ } else if (fromNumber) {
78015
+ if (communicationGroup?.id) {
78016
+ updateCommunicationGroup2({
78017
+ groupId: communicationGroup.id,
78018
+ params: {
78019
+ smsChannelSenderId: fromNumber
78020
+ }
78021
+ });
78022
+ }
78023
+ }
77987
78024
  }
78025
+ setInitialState(true);
77988
78026
  }
77989
78027
  }, [
77990
- channelSenders,
78028
+ communicationGroup,
77991
78029
  fromNumber,
77992
- communicationGroup?.id,
77993
- updateCommunicationGroup2,
77994
- smsApplication,
77995
- channelAccounts?.results,
77996
- communicationGroup?.emailChannelSenderId,
78030
+ message2,
78031
+ companyName,
78032
+ imageUrls,
78033
+ initialState2,
78034
+ showSmsEditor,
78035
+ editingMessage,
78036
+ imagePreview,
78037
+ isRemovingImage,
78038
+ channelSenders,
77997
78039
  smsChannelSenders,
77998
- initialState2
78040
+ updateCommunicationGroup2
77999
78041
  ]);
78042
+ const updateCompanyName = (newCompanyName) => {
78043
+ setCompanyName(newCompanyName);
78044
+ };
78000
78045
  useEffect(() => {
78001
78046
  if (!companyName && me2?.name && !initCompanyName) {
78002
78047
  setInitCompanyName(true);
@@ -78023,28 +78068,15 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
78023
78068
  /* @__PURE__ */ jsx(DialogDescription, { children: "Learn more about the SMS editor and how to use it to create your SMS." })
78024
78069
  ] }),
78025
78070
  /* @__PURE__ */ jsxs("div", { className: "", children: [
78026
- imagePreview && /* @__PURE__ */ jsx("div", { className: "flex justify-center mb-6", children: /* @__PURE__ */ jsxs("div", { className: "relative group w-fit", children: [
78027
- /* @__PURE__ */ jsx(
78028
- "img",
78029
- {
78030
- src: imagePreview,
78031
- alt: "SMS attachment preview",
78032
- className: "max-h-48 max-w-xs rounded-xl shadow-lg border border-gray-200 object-contain bg-white transition-transform duration-200 group-hover:scale-105",
78033
- style: { boxShadow: "0 4px 24px 0 rgba(0,0,0,0.08)" }
78034
- }
78035
- ),
78036
- /* @__PURE__ */ jsx(
78037
- Button$1,
78038
- {
78039
- variant: "ghost",
78040
- size: "icon",
78041
- className: "absolute -top-3 -right-3 bg-white/80 hover:bg-red-100 text-gray-500 hover:text-red-500 shadow-md border border-gray-200 rounded-full opacity-0 group-hover:opacity-100 transition-opacity",
78042
- onClick: handleRemoveImage,
78043
- style: { boxShadow: "0 2px 8px 0 rgba(0,0,0,0.10)" },
78044
- children: /* @__PURE__ */ jsx(X$2, { className: "h-4 w-4" })
78045
- }
78046
- )
78047
- ] }) }),
78071
+ imagePreview && /* @__PURE__ */ jsx("div", { className: "flex justify-center mb-6", children: /* @__PURE__ */ jsx("div", { className: "relative group w-fit", children: /* @__PURE__ */ jsx(
78072
+ "img",
78073
+ {
78074
+ src: imagePreview,
78075
+ alt: "SMS attachment preview",
78076
+ className: "max-h-48 max-w-xs rounded-xl shadow-lg border border-gray-200 object-contain bg-white transition-transform duration-200",
78077
+ style: { boxShadow: "0 4px 24px 0 rgba(0,0,0,0.08)" }
78078
+ }
78079
+ ) }) }),
78048
78080
  /* @__PURE__ */ jsx(
78049
78081
  Textarea,
78050
78082
  {
@@ -78110,13 +78142,22 @@ const SMSPreview = ({ mergeFieldsResponse }) => {
78110
78142
  className: "hidden"
78111
78143
  }
78112
78144
  ),
78113
- /* @__PURE__ */ jsx(
78145
+ imagePreview ? /* @__PURE__ */ jsx(
78146
+ Button$1,
78147
+ {
78148
+ variant: "outline",
78149
+ onClick: handleRemoveImage,
78150
+ className: "px-4",
78151
+ disabled: isRemovingImage || isUpdating,
78152
+ children: "Remove Image"
78153
+ }
78154
+ ) : /* @__PURE__ */ jsx(
78114
78155
  Button$1,
78115
78156
  {
78116
78157
  variant: "outline",
78117
78158
  onClick: handleAddImage,
78118
78159
  className: "px-4",
78119
- disabled: imageUrls.length >= 1 || isRemovingImage || imageBase64 !== null,
78160
+ disabled: imageUrls.length >= 1 || isRemovingImage || imageBase64 !== null || isUpdating,
78120
78161
  children: "Add Image"
78121
78162
  }
78122
78163
  ),