@bikdotai/bik-component-library 0.0.407-beta.9 → 0.0.408

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.
Files changed (73) hide show
  1. package/dist/cjs/components/TablePagination/TablePagination.js +1 -1
  2. package/dist/cjs/components/bik-layout/MockMenus.d.ts +0 -1
  3. package/dist/cjs/components/discount-modal/CouponExpiration/CouponExpiration.js +1 -1
  4. package/dist/cjs/components/discount-modal/DiscountModal.js +1 -1
  5. package/dist/cjs/components/input-with-vars/InputWithVariables.d.ts +0 -1
  6. package/dist/cjs/components/input-with-vars/InputWithVariables.js +1 -1
  7. package/dist/cjs/components/shimmer-image/ShimmerImage.d.ts +1 -1
  8. package/dist/cjs/components/template-context-mapper/TemplateContextMapper.js +1 -1
  9. package/dist/cjs/components/template-context-mapper/modalElements/Body.js +1 -1
  10. package/dist/cjs/components/template-context-mapper/modalElements/EditMediaModal.js +1 -1
  11. package/dist/cjs/components/template-context-mapper/modalElements/EditMediaV2.js +3 -3
  12. package/dist/cjs/components/template-context-mapper/modalElements/EditWhatsAppTemplateMediaV2.js +1 -1
  13. package/dist/cjs/components/template-context-mapper/modalElements/EditWhatsAppTemplateV2.js +1 -1
  14. package/dist/cjs/components/template-context-mapper/modalElements/MobilePreview.js +1 -1
  15. package/dist/cjs/components/template-context-mapper/modalElements/VariableConnector.d.ts +1 -1
  16. package/dist/cjs/components/template-context-mapper/modalElements/VariableConnector.js +3 -3
  17. package/dist/cjs/components/template-context-mapper/modalElements/VariableConnectorWhatsApp.js +1 -1
  18. package/dist/cjs/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.d.ts +1 -2
  19. package/dist/cjs/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.js +1 -1
  20. package/dist/cjs/components/template-context-mapper/utils/getDataFromTemplateComponent.js +1 -1
  21. package/dist/cjs/components/template-context-mapper/utils/getPreviewDimension.d.ts +1 -1
  22. package/dist/cjs/components/template-context-mapper/utils/getPreviewDimension.js +1 -1
  23. package/dist/cjs/components/template-preview/WhatsApp/ChatUiV2.js +5 -5
  24. package/dist/cjs/components/template-preview/WhatsApp/MediaCard.js +1 -1
  25. package/dist/cjs/components/template-preview/WhatsAppTemplatePreview.js +1 -1
  26. package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.d.ts +0 -1
  27. package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
  28. package/dist/cjs/components/template-preview/models/TemplateMeta.d.ts +1 -1
  29. package/dist/cjs/components/template-preview/models/WhatsAppTemplate.d.ts +3 -25
  30. package/dist/cjs/components/template-preview/models/WhatsAppTemplate.js +1 -1
  31. package/dist/esm/components/TablePagination/TablePagination.js +1 -1
  32. package/dist/esm/components/bik-layout/MockMenus.d.ts +0 -1
  33. package/dist/esm/components/discount-modal/CouponExpiration/CouponExpiration.js +1 -1
  34. package/dist/esm/components/discount-modal/DiscountModal.js +1 -1
  35. package/dist/esm/components/input-with-vars/InputWithVariables.d.ts +0 -1
  36. package/dist/esm/components/input-with-vars/InputWithVariables.js +2 -2
  37. package/dist/esm/components/shimmer-image/ShimmerImage.d.ts +1 -1
  38. package/dist/esm/components/template-context-mapper/TemplateContextMapper.js +1 -1
  39. package/dist/esm/components/template-context-mapper/modalElements/Body.js +1 -1
  40. package/dist/esm/components/template-context-mapper/modalElements/EditMediaModal.js +1 -1
  41. package/dist/esm/components/template-context-mapper/modalElements/EditMediaV2.js +3 -3
  42. package/dist/esm/components/template-context-mapper/modalElements/EditWhatsAppTemplateMediaV2.js +1 -1
  43. package/dist/esm/components/template-context-mapper/modalElements/EditWhatsAppTemplateV2.js +1 -1
  44. package/dist/esm/components/template-context-mapper/modalElements/MobilePreview.js +1 -1
  45. package/dist/esm/components/template-context-mapper/modalElements/VariableConnector.d.ts +1 -1
  46. package/dist/esm/components/template-context-mapper/modalElements/VariableConnector.js +3 -3
  47. package/dist/esm/components/template-context-mapper/modalElements/VariableConnectorWhatsApp.js +1 -1
  48. package/dist/esm/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.d.ts +1 -2
  49. package/dist/esm/components/template-context-mapper/modalElements/WhatsAppTemplateCardButtonV2.js +1 -1
  50. package/dist/esm/components/template-context-mapper/utils/getDataFromTemplateComponent.js +1 -1
  51. package/dist/esm/components/template-context-mapper/utils/getPreviewDimension.d.ts +1 -1
  52. package/dist/esm/components/template-context-mapper/utils/getPreviewDimension.js +1 -1
  53. package/dist/esm/components/template-preview/WhatsApp/ChatUiV2.js +5 -5
  54. package/dist/esm/components/template-preview/WhatsApp/MediaCard.js +1 -1
  55. package/dist/esm/components/template-preview/WhatsAppTemplatePreview.js +1 -1
  56. package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.d.ts +0 -1
  57. package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
  58. package/dist/esm/components/template-preview/models/TemplateMeta.d.ts +1 -1
  59. package/dist/esm/components/template-preview/models/WhatsAppTemplate.d.ts +3 -25
  60. package/dist/esm/components/template-preview/models/WhatsAppTemplate.js +1 -1
  61. package/package.json +1 -1
  62. package/dist/cjs/assets/icons/copy-code-icon.svg.js +0 -1
  63. package/dist/cjs/assets/icons/lto_icon.svg.js +0 -1
  64. package/dist/cjs/components/template-context-mapper/custom-hooks/useAdditionalVariables.d.ts +0 -8
  65. package/dist/cjs/components/template-context-mapper/custom-hooks/useAdditionalVariables.js +0 -1
  66. package/dist/cjs/components/template-preview/WhatsApp/LimitedTimeOffer/LimitedTimeOffer.index.d.ts +0 -5
  67. package/dist/cjs/components/template-preview/WhatsApp/LimitedTimeOffer/LimitedTimeOffer.index.js +0 -18
  68. package/dist/esm/assets/icons/copy-code-icon.svg.js +0 -1
  69. package/dist/esm/assets/icons/lto_icon.svg.js +0 -1
  70. package/dist/esm/components/template-context-mapper/custom-hooks/useAdditionalVariables.d.ts +0 -8
  71. package/dist/esm/components/template-context-mapper/custom-hooks/useAdditionalVariables.js +0 -1
  72. package/dist/esm/components/template-preview/WhatsApp/LimitedTimeOffer/LimitedTimeOffer.index.d.ts +0 -5
  73. package/dist/esm/components/template-preview/WhatsApp/LimitedTimeOffer/LimitedTimeOffer.index.js +0 -18
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("date-fns"),i=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),l=require("../constants/TemplateConstants.js"),o=require("../models/TemplateMeta.js"),a=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t){var i,n,l,a,d,r,s,v,E,u;const p={headerType:o.HEADER_TYPES.NONE,headerVariables:[]},T=null===(i=e.components)||void 0===i?void 0:i.find((e=>"HEADER"===e.type));if(T){p.headerType=T.format,p.headerText=T.text,p.headerAssetLink=null===(l=null===(n=T.example)||void 0===n?void 0:n.header_handle)||void 0===l?void 0:l[0];const i=null===(d=null===(a=T.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],o=null===(s=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===s?void 0:s[0],c=o;if(i&&o){const e=null==o?void 0:o.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),n=/\(\(/.test(o),l={idx:0,variableVal:t?i:c,editable:n,editableDefaultValues:n?void 0:i,variableName:e};p.headerVariables=[l],(null===(E=null===(v=T.example)||void 0===v?void 0:v.header_text)||void 0===E?void 0:E.length)&&(p.headerText=null===(u=p.headerText)||void 0===u?void 0:u.replace("{{1}}",`{{${e}}}`))}}return p}validateState(e){var t,i,d,r,s,v,E,u,p,T,c,_,m,h,R,b,I,L,y,B,N;const C=/\p{Extended_Pictographic}/u;let O="valid";const D={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},f=new a.TemplateHelperUtils;let x=!1;const A=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?e.meta.name.trim().length>l.NAME_LEN_LIMIT?(D.meta.name=l.NAME_LEN_ERROR,O="invalid"):n.specialCharPattern.test(e.meta.name.trim())&&(D.meta.name=l.NO_SPECIAL_CHAR,O="invalid"):(D.meta.name=l.REQUIRED_FIELD,O="invalid"),D.meta.name&&!x&&(A(l.CREATE_TEMPLATE_DOM_IDS.name),x=!0),e.headerType===o.HEADER_TYPES.TEXT){const t=null!==(d=null===(i=e.headerText)||void 0===i?void 0:i.trim())&&void 0!==d?d:"";if(t)if(t.length>l.HEADER_TEXT_LEN_LIMIT)D.header=l.HEADER_LEN_ERROR,O="invalid";else{const e=f.getTemplateVariablesFromState(t);e&&e.length>1&&(D.header=l.ONE_VAR_ALLOWED,O="invalid")}else D.header=l.REQUIRED_FIELD,O="invalid"}else e.headerType===o.HEADER_TYPES.DOCUMENT||e.headerType===o.HEADER_TYPES.IMAGE||(e.headerType,o.HEADER_TYPES.VIDEO);if(e.headerType!==o.HEADER_TYPES.DOCUMENT&&e.headerType!==o.HEADER_TYPES.IMAGE&&e.headerType!==o.HEADER_TYPES.VIDEO||e.headerAssetLink||(D.header=l.HEADER_ASSET_LINK_ERROR,O="invalid"),D.header&&!x&&(A(l.CREATE_TEMPLATE_DOM_IDS.header),x=!0),e.bodyText?e.bodyTextRaw&&(null===(r=e.bodyTextRaw)||void 0===r?void 0:r.trim().length)>l.BODY_TEXT_LEN_LIMIT&&(D.body=l.BODY_LEN_ERROR,O="invalid"):(D.body=l.REQUIRED_FIELD,O="invalid"),D.body&&!x&&(A(l.CREATE_TEMPLATE_DOM_IDS.body),x=!0),e.footerText&&e.footerText.length>l.HEADER_TEXT_LEN_LIMIT&&(D.footer=l.HEADER_LEN_ERROR,O="invalid"),(null==D?void 0:D.footer)&&!x&&(A(l.CREATE_TEMPLATE_DOM_IDS.footer),x=!0),e.actionsType===o.ACTIONS_TYPES.CTA_BTN){if(null===(v=null===(s=e.ctaBtn)||void 0===s?void 0:s.phoneNumber)||void 0===v?void 0:v.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;D.ctaBtn&&!t?(D.ctaBtn.phoneNumber.btnText=l.REQUIRED_FIELD,O="invalid"):D.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.phoneNumber.btnText=l.QUICK_REPLY_LEN_ERROR,O="invalid"):D.ctaBtn&&t&&C.test(t)&&(D.ctaBtn.phoneNumber.btnText=l.BUTTON_EMOJI_ERROR,O="invalid"),D.ctaBtn&&!i?(D.ctaBtn.phoneNumber.link=l.REQUIRED_FIELD,O="invalid"):D.ctaBtn&&i&&i.length<10&&(D.ctaBtn.phoneNumber.link=l.VALID_PHONE_NUMBER,O="invalid")}if(null===(p=null===(u=e.ctaBtn)||void 0===u?void 0:u.websiteLinkBtn)||void 0===p?void 0:p.isChecked){const t=null===(T=e.ctaBtn.websiteLinkBtn.btnText)||void 0===T?void 0:T.trim(),i=null===(c=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===c?void 0:c.trim(),n=null===(_=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===_?void 0:_.trim();D.ctaBtn&&!t?(D.ctaBtn.websiteLink.btnText=l.REQUIRED_FIELD,O="invalid"):D.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.websiteLink.btnText=l.QUICK_REPLY_LEN_ERROR,O="invalid"):D.ctaBtn&&t&&C.test(t)&&(D.ctaBtn.websiteLink.btnText=l.BUTTON_EMOJI_ERROR,O="invalid"),!D.ctaBtn||i||n||(D.ctaBtn.websiteLink.link=l.REQUIRED_FIELD,O="invalid")}}else if(e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{const o=i.text.trim();if(o)if(o.length>l.QUICK_REPLY_NAME_LEN_LIMIT)t[n]=l.QUICK_REPLY_LEN_ERROR,O="invalid";else if(C.test(o))t[n]=l.BUTTON_EMOJI_ERROR,O="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===o))&&(t[n]=l.QUICK_REPLY_NAME_ERROR,O="invalid")}else t[n]=l.REQUIRED_FIELD,O="invalid"})),D.quickReply=t}if(e.actionsType===o.ACTIONS_TYPES.CTA_BTN||e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const e=null===(m=D.quickReply)||void 0===m?void 0:m.reduce(((e,t)=>e||!!t),!1);((null===(R=null===(h=null==D?void 0:D.ctaBtn)||void 0===h?void 0:h.websiteLink)||void 0===R?void 0:R.link)||(null===(I=null===(b=D.ctaBtn)||void 0===b?void 0:b.websiteLink)||void 0===I?void 0:I.btnText)||(null===(y=null===(L=D.ctaBtn)||void 0===L?void 0:L.phoneNumber)||void 0===y?void 0:y.link)||(null===(N=null===(B=D.ctaBtn)||void 0===B?void 0:B.phoneNumber)||void 0===N?void 0:N.btnText)||e)&&!x&&(A(l.CREATE_TEMPLATE_DOM_IDS.actionButtons),x=!0)}return{status:O,errors:D}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s;const v=[];let E="";const u=null===(o=e.components)||void 0===o?void 0:o.find((e=>"BODY"===e.type));return u&&(null===(d=null===(a=u.example)||void 0===a?void 0:a.body_text)||void 0===d||d[0].forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),E=null==d?void 0:d.match(n.placeHolderNamePattern);(null==E?void 0:E[2])&&(d=null==E?void 0:E[2]),v.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),E=e.htmlContentUrl?e.htmlContentUrl:(null===(r=u.text)||void 0===r?void 0:r.split(/\{\{[0-9]+\}\}/).length)?null===(s=u.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==v?void 0:v[n]){const l=v[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:v,bodyText:E}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,l,a,d,r,s;const v={actionsType:o.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},E=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(E&&(null===(i=null==E?void 0:E.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(l=null==E?void 0:E.buttons)||void 0===l?void 0:l[0].type)?o.ACTIONS_TYPES.QUICK_REPLY:o.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===o.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==E?void 0:E.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];return v.quickReply=e,v}t===o.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==E?void 0:E.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}}))),v.allButtons=null===(s=E.buttons)||void 0===s?void 0:s.map((e=>{var t;return"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:null===(t=e.example)||void 0===t?void 0:t[0]}):e}))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t.format(i?new Date(i):new Date,"MMM dd")}console.log("vj: limited time offer",n),i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o}=t,{headerType:a,headerAssetLink:d,headerAssetName:r,headerText:s,headerVariables:v}=yield this.parseDataFromHeaderComponent(e),{bodyText:E,bodyVariable:u}=yield this.parseBodyComponent(e,l,o),{actionsType:p,quickReply:T,ctaBtn:c,allButtons:_}=yield this.parseButtonComponent(e),m=this.parseLimitedTimeOfferComponent(e,_),h={quickReply:T,ctaBtn:c,allButtons:_,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:p,footerText:this.parseFooterComponent(e),bodyVariables:u,bodyText:E,headerType:a,headerAssetLink:d,headerAssetName:r,headerText:s,headerVariables:v,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:m},{errors:R}=this.validateState(h);return h.error=R,h}))}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),i=require("../constants/TemplateConstants.js"),l=require("../models/TemplateMeta.js"),o=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t){var n,i,o,a,d,r,v,s,E,u;const T={headerType:l.HEADER_TYPES.NONE,headerVariables:[]},p=null===(n=e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(p){T.headerType=p.format,T.headerText=p.text,T.headerAssetLink=null===(o=null===(i=p.example)||void 0===i?void 0:i.header_handle)||void 0===o?void 0:o[0];const n=null===(d=null===(a=p.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],l=null===(v=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===v?void 0:v[0],c=l;if(n&&l){const e=null==l?void 0:l.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),i=/\(\(/.test(l),o={idx:0,variableVal:t?n:c,editable:i,editableDefaultValues:i?void 0:n,variableName:e};T.headerVariables=[o],(null===(E=null===(s=p.example)||void 0===s?void 0:s.header_text)||void 0===E?void 0:E.length)&&(T.headerText=null===(u=T.headerText)||void 0===u?void 0:u.replace("{{1}}",`{{${e}}}`))}}return T}validateState(e){var t,a,d,r,v,s,E,u,T,p,c,_,m,R,h,b,I,L,N,y,B;const A=/\p{Extended_Pictographic}/u;let D="valid";const C={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},O=new o.TemplateHelperUtils;let x=!1;const P=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?e.meta.name.trim().length>i.NAME_LEN_LIMIT?(C.meta.name=i.NAME_LEN_ERROR,D="invalid"):n.specialCharPattern.test(e.meta.name.trim())&&(C.meta.name=i.NO_SPECIAL_CHAR,D="invalid"):(C.meta.name=i.REQUIRED_FIELD,D="invalid"),C.meta.name&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.name),x=!0),e.headerType===l.HEADER_TYPES.TEXT){const t=null!==(d=null===(a=e.headerText)||void 0===a?void 0:a.trim())&&void 0!==d?d:"";if(t)if(t.length>i.HEADER_TEXT_LEN_LIMIT)C.header=i.HEADER_LEN_ERROR,D="invalid";else{const e=O.getTemplateVariablesFromState(t);e&&e.length>1&&(C.header=i.ONE_VAR_ALLOWED,D="invalid")}else C.header=i.REQUIRED_FIELD,D="invalid"}else e.headerType===l.HEADER_TYPES.DOCUMENT||e.headerType===l.HEADER_TYPES.IMAGE||(e.headerType,l.HEADER_TYPES.VIDEO);if(e.headerType!==l.HEADER_TYPES.DOCUMENT&&e.headerType!==l.HEADER_TYPES.IMAGE&&e.headerType!==l.HEADER_TYPES.VIDEO||e.headerAssetLink||(C.header=i.HEADER_ASSET_LINK_ERROR,D="invalid"),C.header&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.header),x=!0),e.bodyText?e.bodyTextRaw&&(null===(r=e.bodyTextRaw)||void 0===r?void 0:r.trim().length)>i.BODY_TEXT_LEN_LIMIT&&(C.body=i.BODY_LEN_ERROR,D="invalid"):(C.body=i.REQUIRED_FIELD,D="invalid"),C.body&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.body),x=!0),e.footerText&&e.footerText.length>i.HEADER_TEXT_LEN_LIMIT&&(C.footer=i.HEADER_LEN_ERROR,D="invalid"),(null==C?void 0:C.footer)&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.footer),x=!0),e.actionsType===l.ACTIONS_TYPES.CTA_BTN){if(null===(s=null===(v=e.ctaBtn)||void 0===v?void 0:v.phoneNumber)||void 0===s?void 0:s.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),n=e.ctaBtn.phoneNumber.phoneNumber;C.ctaBtn&&!t?(C.ctaBtn.phoneNumber.btnText=i.REQUIRED_FIELD,D="invalid"):C.ctaBtn&&t&&t.length>i.QUICK_REPLY_BTN_TEXT_LIMIT?(C.ctaBtn.phoneNumber.btnText=i.QUICK_REPLY_LEN_ERROR,D="invalid"):C.ctaBtn&&t&&A.test(t)&&(C.ctaBtn.phoneNumber.btnText=i.BUTTON_EMOJI_ERROR,D="invalid"),C.ctaBtn&&!n?(C.ctaBtn.phoneNumber.link=i.REQUIRED_FIELD,D="invalid"):C.ctaBtn&&n&&n.length<10&&(C.ctaBtn.phoneNumber.link=i.VALID_PHONE_NUMBER,D="invalid")}if(null===(T=null===(u=e.ctaBtn)||void 0===u?void 0:u.websiteLinkBtn)||void 0===T?void 0:T.isChecked){const t=null===(p=e.ctaBtn.websiteLinkBtn.btnText)||void 0===p?void 0:p.trim(),n=null===(c=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===c?void 0:c.trim(),l=null===(_=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===_?void 0:_.trim();C.ctaBtn&&!t?(C.ctaBtn.websiteLink.btnText=i.REQUIRED_FIELD,D="invalid"):C.ctaBtn&&t&&t.length>i.QUICK_REPLY_BTN_TEXT_LIMIT?(C.ctaBtn.websiteLink.btnText=i.QUICK_REPLY_LEN_ERROR,D="invalid"):C.ctaBtn&&t&&A.test(t)&&(C.ctaBtn.websiteLink.btnText=i.BUTTON_EMOJI_ERROR,D="invalid"),!C.ctaBtn||n||l||(C.ctaBtn.websiteLink.link=i.REQUIRED_FIELD,D="invalid")}}else if(e.actionsType===l.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((n,l)=>{const o=n.text.trim();if(o)if(o.length>i.QUICK_REPLY_NAME_LEN_LIMIT)t[l]=i.QUICK_REPLY_LEN_ERROR,D="invalid";else if(A.test(o))t[l]=i.BUTTON_EMOJI_ERROR,D="invalid";else{const n=[...e.quickReply];n.splice(l,1);n.find((e=>e.text===o))&&(t[l]=i.QUICK_REPLY_NAME_ERROR,D="invalid")}else t[l]=i.REQUIRED_FIELD,D="invalid"})),C.quickReply=t}if(e.actionsType===l.ACTIONS_TYPES.CTA_BTN||e.actionsType===l.ACTIONS_TYPES.QUICK_REPLY){const e=null===(m=C.quickReply)||void 0===m?void 0:m.reduce(((e,t)=>e||!!t),!1);((null===(h=null===(R=null==C?void 0:C.ctaBtn)||void 0===R?void 0:R.websiteLink)||void 0===h?void 0:h.link)||(null===(I=null===(b=C.ctaBtn)||void 0===b?void 0:b.websiteLink)||void 0===I?void 0:I.btnText)||(null===(N=null===(L=C.ctaBtn)||void 0===L?void 0:L.phoneNumber)||void 0===N?void 0:N.link)||(null===(B=null===(y=C.ctaBtn)||void 0===y?void 0:y.phoneNumber)||void 0===B?void 0:B.btnText)||e)&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.actionButtons),x=!0)}return{status:D,errors:C}}parseBodyComponent(e){let i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,v;const s=[];let E="";const u=null===(o=e.components)||void 0===o?void 0:o.find((e=>"BODY"===e.type));return u&&(null===(d=null===(a=u.example)||void 0===a?void 0:a.body_text)||void 0===d||d[0].forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,v=d&&/\(\(/.test(d),E=null==d?void 0:d.match(n.placeHolderNamePattern);(null==E?void 0:E[2])&&(d=null==E?void 0:E[2]),s.push({idx:i,variableVal:l?t:r,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=d?d:""})})),E=e.htmlContentUrl?e.htmlContentUrl:(null===(r=u.text)||void 0===r?void 0:r.split(/\{\{[0-9]+\}\}/).length)?null===(v=u.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==s?void 0:s[n]){const l=s[n].variableName;return i?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${t.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:s,bodyText:E}}parseFooterComponent(e){var t;const n=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==n?void 0:n.text}parseButtonComponent(e){var t,i,o,a,d,r;const v={actionsType:l.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0}},s=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(s&&(null===(i=null==s?void 0:s.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(o=null==s?void 0:s.buttons)||void 0===o?void 0:o[0].type)?l.ACTIONS_TYPES.QUICK_REPLY:l.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===l.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==s?void 0:s.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];return v.quickReply=e,v}t===l.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==s?void 0:s.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})))}return v}parseUITemplateFromDBFormat(t){var n;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:i,isV2:l=!1,showSampleValues:o}=t,{headerType:a,headerAssetLink:d,headerAssetName:r,headerText:v,headerVariables:s}=yield this.parseDataFromHeaderComponent(e),{bodyText:E,bodyVariable:u}=yield this.parseBodyComponent(e,l,o),{actionsType:T,quickReply:p,ctaBtn:c}=yield this.parseButtonComponent(e),_={quickReply:p,ctaBtn:c,meta:{name:i?`${e.label} Copy`:e.label,category:null===(n=e.category)||void 0===n?void 0:n.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:T,footerText:this.parseFooterComponent(e),bodyVariables:u,bodyText:E,headerType:a,headerAssetLink:d,headerAssetName:r,headerText:v,headerVariables:s,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1},{errors:m}=this.validateState(_);return _.error=m,_}))}};
@@ -1,7 +1,7 @@
1
1
  import { SingleOption } from "../../dropdown/type";
2
2
  export type CUSTOM_VARIABLE = {
3
3
  variableName: string;
4
- type: 'string' | 'link' | 'image' | 'button' | 'date_time';
4
+ type: 'string' | 'link' | 'image';
5
5
  isEditableVariable: boolean;
6
6
  updatedValue: string;
7
7
  index?: number;
@@ -11,15 +11,11 @@ export type WhatsAppTemplate = {
11
11
  templateCategory: string;
12
12
  type?: 'email' | 'whatsapp';
13
13
  components: {
14
- type: 'HEADER' | 'BODY' | 'BUTTONS' | 'FOOTER' | 'limited_time_offer';
14
+ type: 'HEADER' | 'BODY' | 'BUTTONS' | 'FOOTER';
15
15
  format?: HEADER_TYPES;
16
16
  text?: string;
17
- limited_time_offer?: {
18
- text: string;
19
- has_expiration: boolean;
20
- };
21
17
  buttons?: {
22
- type: 'QUICK_REPLY' | 'URL' | 'PHONE_NUMBER' | 'COPY_CODE';
18
+ type: 'QUICK_REPLY' | 'URL' | 'PHONE_NUMBER';
23
19
  text?: string;
24
20
  url?: string;
25
21
  example?: string[];
@@ -32,7 +28,6 @@ export type WhatsAppTemplate = {
32
28
  header_handle?: Array<string>;
33
29
  body_text?: Array<string[]>;
34
30
  header_text?: Array<string>;
35
- limited_time_offer?: string;
36
31
  };
37
32
  }[];
38
33
  mapping: {
@@ -51,7 +46,6 @@ export type WhatsAppTemplate = {
51
46
  updatedAt: number;
52
47
  isDraft?: boolean;
53
48
  };
54
- export type WhatsappTemplateButtonTypes = 'QUICK_REPLY' | 'URL' | 'PHONE_NUMBER' | 'COPY_CODE';
55
49
  export type CreateTemplateType = {
56
50
  /** Data */
57
51
  headerType: HEADER_TYPES;
@@ -78,7 +72,6 @@ export type CreateTemplateType = {
78
72
  placeholder?: string;
79
73
  };
80
74
  };
81
- allButtons: WhatsappPreviewButtonType[];
82
75
  meta: {
83
76
  name: string;
84
77
  category?: string;
@@ -90,11 +83,6 @@ export type CreateTemplateType = {
90
83
  alreadyAsADraft?: boolean;
91
84
  /** UI */
92
85
  initialLoading: boolean;
93
- limitedTimeOfferComponent: {
94
- text: string;
95
- dateTime: string;
96
- code: string;
97
- };
98
86
  error: {
99
87
  modalError?: string;
100
88
  header?: string;
@@ -184,15 +172,6 @@ export type WhatsappLikePreviewTypes = {
184
172
  children?: React.ReactNode;
185
173
  bodyVariableList?: variableType[];
186
174
  headerVariableList?: variableType[];
187
- buttons?: WhatsappPreviewButtonType[];
188
- limitedTimeOfferComponent?: CreateTemplateType['limitedTimeOfferComponent'];
189
- };
190
- export type WhatsappPreviewButtonType = {
191
- type: WhatsappTemplateButtonTypes;
192
- text: string;
193
- placeholder?: string;
194
- flowId: string;
195
- flowName: string;
196
175
  };
197
176
  export type WhatsappMeta = {
198
177
  containerStyle?: React.CSSProperties | undefined;
@@ -245,8 +224,7 @@ export type TEMPLATE_BUTTON = {
245
224
  export declare enum BUTTON_TYPE {
246
225
  QUICK_REPLY = "QUICK_REPLY",
247
226
  URL = "URL",
248
- PHONE_NUMBER = "PHONE_NUMBER",
249
- COPY_CODE = "COPY_CODE"
227
+ PHONE_NUMBER = "PHONE_NUMBER"
250
228
  }
251
229
  export declare enum POD {
252
230
  CHATBOT = "CHATBOT",
@@ -1 +1 @@
1
- "use strict";var O,T;Object.defineProperty(exports,"__esModule",{value:!0}),exports.BUTTON_TYPE=void 0,(O=exports.BUTTON_TYPE||(exports.BUTTON_TYPE={})).QUICK_REPLY="QUICK_REPLY",O.URL="URL",O.PHONE_NUMBER="PHONE_NUMBER",O.COPY_CODE="COPY_CODE",exports.POD=void 0,(T=exports.POD||(exports.POD={})).CHATBOT="CHATBOT",T.GROWTH="GROWTH",T.CAMPAIGN="CAMPAIGN",T.CRM="CRM",T.INTEGRATIONS="INTEGRATIONS",T.OPENAI="OPENAI",T.DM="DM",T.FRONTEND="FRONTEND";
1
+ "use strict";var T,N;Object.defineProperty(exports,"__esModule",{value:!0}),exports.BUTTON_TYPE=void 0,(T=exports.BUTTON_TYPE||(exports.BUTTON_TYPE={})).QUICK_REPLY="QUICK_REPLY",T.URL="URL",T.PHONE_NUMBER="PHONE_NUMBER",exports.POD=void 0,(N=exports.POD||(exports.POD={})).CHATBOT="CHATBOT",N.GROWTH="GROWTH",N.CAMPAIGN="CAMPAIGN",N.CRM="CRM",N.INTEGRATIONS="INTEGRATIONS",N.OPENAI="OPENAI",N.DM="DM",N.FRONTEND="FRONTEND";
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";import s from"../../assets/icons/chevronLeft.svg.js";import o from"../../assets/icons/chevronRight.svg.js";import{StyledTablePaginationContainer as i,StyledPagingContainer as n}from"./TablePagination.styled.js";import{DEFAULT_THEME as a}from"../../constants/Theme.js";import{Dropdown as r}from"../dropdown/Dropdown.js";import{BodySecondary as c}from"../TypographyStyle.js";const l=l=>{let{pageNumber:d,pageSize:p,totalRows:g,updatePageNumber:h,updatePageSize:m,hidePageSizeOptions:b}=l;const j=a.colorsV2,v=(d-1)*p+1,y=(d-1)*p+p,f=Math.ceil(g/p),u=1==f;let w=[];w=f>=5?d===f?[d-4,d-3,d-2,d-1,d]:1===d?[d,d+1,d+2,d+3,d+4]:2===d?[d-1,d,d+1,d+2,d+3]:d===f-1?[d-3,d-2,d-1,d,d+1]:[d-2,d-1,d,d+1,d+2]:Array.from({length:f},((e,t)=>t+1));return e(i,{children:[!b&&t("div",{children:t(r,{size:"small",options:[{label:"5 rows per page",value:"5",selected:5===p},{label:"10 rows per page",value:"10",selected:10===p},{label:"20 rows per page",value:"20",selected:20===p}],onSelect:m,width:"162px"})}),e("div",Object.assign({className:"paging__container"},{children:[!b&&g&&e(c,Object.assign({style:{color:j.content.placeholder,marginRight:8}},{children:["Showing ",v,"-",y>g?g:y," of"," ",g," results"]})),e("div",Object.assign({className:"pages__buttons-container"},{children:[!u&&t(n,Object.assign({active:!1,onClick:()=>{1!==d&&h(Math.max(d-1,1))},disabled:1===d},{children:t(s,{color:j.content.secondary,height:14,width:14})})),w.map((e=>t(n,Object.assign({active:e==d,onClick:()=>h(e),style:{display:1==e&&g<=p?"none":"flex"}},{children:t(c,Object.assign({style:{color:e==d?j.content.primaryInverse:j.content.secondary}},{children:e}))}),e))),!u&&t(n,Object.assign({isLast:!0,active:!1,onClick:()=>{d!==f&&h(Math.min(d+1,f))},disabled:d===f},{children:t(o,{color:j.content.secondary,height:14,width:14})}))]}))]}))]})};export{l as TablePagination};
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import s from"../../assets/icons/chevronLeft.svg.js";import o from"../../assets/icons/chevronRight.svg.js";import{StyledTablePaginationContainer as i,StyledPagingContainer as n}from"./TablePagination.styled.js";import{DEFAULT_THEME as a}from"../../constants/Theme.js";import{BodySecondary as r}from"../TypographyStyle.js";import{Dropdown as c}from"../dropdown/Dropdown.js";const l=l=>{let{pageNumber:d,pageSize:p,totalRows:g,updatePageNumber:h,updatePageSize:m,hidePageSizeOptions:b}=l;const j=a.colorsV2,v=(d-1)*p+1,y=(d-1)*p+p,f=Math.ceil(g/p),u=1==f;let w=[];w=f>=5?d===f?[d-4,d-3,d-2,d-1,d]:1===d?[d,d+1,d+2,d+3,d+4]:2===d?[d-1,d,d+1,d+2,d+3]:d===f-1?[d-3,d-2,d-1,d,d+1]:[d-2,d-1,d,d+1,d+2]:Array.from({length:f},((e,t)=>t+1));return e(i,{children:[!b&&t("div",{children:t(c,{size:"small",options:[{label:"5 rows per page",value:"5",selected:5===p},{label:"10 rows per page",value:"10",selected:10===p},{label:"20 rows per page",value:"20",selected:20===p}],onSelect:m,width:"162px"})}),e("div",Object.assign({className:"paging__container"},{children:[!b&&g&&e(r,Object.assign({style:{color:j.content.placeholder,marginRight:8}},{children:["Showing ",v,"-",y>g?g:y," of"," ",g," results"]})),e("div",Object.assign({className:"pages__buttons-container"},{children:[!u&&t(n,Object.assign({active:!1,onClick:()=>{1!==d&&h(Math.max(d-1,1))},disabled:1===d},{children:t(s,{color:j.content.secondary,height:14,width:14})})),w.map((e=>t(n,Object.assign({active:e==d,onClick:()=>h(e),style:{display:1==e&&g<=p?"none":"flex"}},{children:t(r,Object.assign({style:{color:e==d?j.content.primaryInverse:j.content.secondary}},{children:e}))}),e))),!u&&t(n,Object.assign({isLast:!0,active:!1,onClick:()=>{d!==f&&h(Math.min(d+1,f))},disabled:d===f},{children:t(o,{color:j.content.secondary,height:14,width:14})}))]}))]}))]})};export{l as TablePagination};
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  export declare const Menus: ({
3
2
  displayName: string;
4
3
  key: number;
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import{format as a}from"date-fns";import{useState as n,useEffect as o}from"react";import{CustomDateTime as r}from"../../custom-date-time/CustomDateTime.js";import{Input as s}from"../../input/Input.js";import{RadioButton as d}from"../../radioButton/RadioButton.js";import{TitleRegular as c,BodySecondary as p}from"../../TypographyStyle.js";var D;!function(e){e.FIXED_EXPIRATION="fixedExpiration",e.DYNAMIC_EXPIRATION="dynamicExpiration"}(D||(D={}));const I=I=>{var A;const[u,l]=n(I.discountData.expireAt?D.FIXED_EXPIRATION:I.discountData.expireAfter?D.DYNAMIC_EXPIRATION:void 0),[m,x]=n(),[E,O]=n(),f=(new Date).setDate((new Date).getDate()+1);o((()=>{l(I.discountData.expireAt?D.FIXED_EXPIRATION:I.discountData.expireAfter?D.DYNAMIC_EXPIRATION:void 0)}),[I.discountData.expireAt,I.discountData.expireAfter]),o((()=>{(null==u||m||E)&&I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAfter:void 0,expireAt:void 0})),u&&(m||E)&&(u===D.FIXED_EXPIRATION?O(void 0):x(void 0))}),[u,m,E]);return e("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:13}},{children:[t(c,{children:"Coupon expiration (optional)"}),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(d,{isActive:u===D.DYNAMIC_EXPIRATION,onValueChange:()=>{O(void 0),l(u===D.DYNAMIC_EXPIRATION?void 0:D.DYNAMIC_EXPIRATION)}}),t(p,{children:"Validity days from coupon claim"})]})),u===D.DYNAMIC_EXPIRATION&&t(s,{errorMessage:E,value:null===(A=I.discountData.expireAfter)||void 0===A?void 0:A.toString(),placeholder:"Enter the number of days",width:"400px",type:"number",onChangeText:e=>{(e=>{O(void 0);const t=Number.parseInt(e);t>0?I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAfter:t,expireAt:void 0})):O("Please enter valid input")})(e)}}),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(d,{isActive:u===D.FIXED_EXPIRATION,onValueChange:()=>{l(u===D.FIXED_EXPIRATION?void 0:D.FIXED_EXPIRATION)}}),t(p,{children:"Fixed expiry date"})]})),u===D.FIXED_EXPIRATION&&e(i,{children:[t(p,{children:"Ending on"}),t(r,{placement:"bottom-start",time:I.discountData.expireAt?a(new Date(I.discountData.expireAt),"hh:mm a"):a(new Date(f),"hh:mm a"),date:I.discountData.expireAt?new Date(I.discountData.expireAt):new Date(f),error:m,setError:x,onChange:e=>{I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAt:e,expireAfter:void 0}))},minDate:new Date(f)})]})]}))};export{D as COUPON_EXPIRATION,I as CouponExpiration};
1
+ import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import{format as a}from"date-fns";import{useState as n,useEffect as o}from"react";import{CustomDateTime as r}from"../../custom-date-time/CustomDateTime.js";import{Input as s}from"../../input/Input.js";import{RadioButton as d}from"../../radioButton/RadioButton.js";import{TitleRegular as c,BodySecondary as p}from"../../TypographyStyle.js";var D;!function(e){e.FIXED_EXPIRATION="fixedExpiration",e.DYNAMIC_EXPIRATION="dynamicExpiration"}(D||(D={}));const I=I=>{var l;const[m,u]=n(I.discountData.expireAt?D.FIXED_EXPIRATION:I.discountData.expireAfter?D.DYNAMIC_EXPIRATION:void 0),[A,x]=n(),[E,v]=n(),O=(new Date).setDate((new Date).getDate()+1);o((()=>{(null==m||A||E)&&I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAfter:void 0,expireAt:void 0})),m&&(A||E)&&(m===D.FIXED_EXPIRATION?v(void 0):x(void 0))}),[m,A,E]);return e("div",Object.assign({style:{display:"flex",flexDirection:"column",gap:13}},{children:[t(c,{children:"Coupon expiration (optional)"}),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(d,{isActive:m===D.DYNAMIC_EXPIRATION,onValueChange:()=>{v(void 0),u(m===D.DYNAMIC_EXPIRATION?void 0:D.DYNAMIC_EXPIRATION)}}),t(p,{children:"Validity days from coupon claim"})]})),m===D.DYNAMIC_EXPIRATION&&t(s,{errorMessage:E,value:null===(l=I.discountData.expireAfter)||void 0===l?void 0:l.toString(),placeholder:"Enter the number of days",width:"400px",type:"number",onChangeText:e=>{(e=>{v(void 0);const t=Number.parseInt(e);t>0?I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAfter:t,expireAt:void 0})):v("Please enter valid input")})(e)}}),e("div",Object.assign({style:{display:"flex",gap:18}},{children:[t(d,{isActive:m===D.FIXED_EXPIRATION,onValueChange:()=>{u(m===D.FIXED_EXPIRATION?void 0:D.FIXED_EXPIRATION)}}),t(p,{children:"Fixed expiry date"})]})),m===D.FIXED_EXPIRATION&&e(i,{children:[t(p,{children:"Ending on"}),t(r,{placement:"bottom-start",time:I.discountData.expireAt?a(new Date(I.discountData.expireAt),"hh:mm a"):a(new Date(O),"hh:mm a"),date:I.discountData.expireAt?new Date(I.discountData.expireAt):new Date(O),error:A,setError:x,onChange:e=>{I.setDiscountData(Object.assign(Object.assign({},I.discountData),{expireAt:e,expireAfter:void 0}))},minDate:new Date(O)})]})]}))};export{D as COUPON_EXPIRATION,I as CouponExpiration};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import{useState as i,useEffect as n}from"react";import{MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_TARGET_TYPES as d,DISCOUNT_TYPES as c,DISCOUNT_TARGET_SELECTION as l,DISCOUNT_VALUE_TYPES as s}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as a}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as u,BodyCaption as p}from"../TypographyStyle.js";import{DEFAULT_THEME as v}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.styled.js";import"../list-item/ListItem.js";import"../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as C}from"../modals/styledModal.js";import{ProductPickerContent as m}from"../product-picker/ProductPickerModal.js";import{Tag as h}from"../tag/Tag.js";import{Tooltip as b}from"../tooltips/Tooltip.js";import y from"../../assets/icons/triangle_error.svg.js";import{ProductPickerModal as T}from"../product-picker-v2/modal.js";import{StyledDiscountDialogueContainer as P,CouponTypeContainerStyled as f}from"./DiscountModal.styled.js";import{validateDiscountData as I,descriptionBuilder as O}from"./DiscountUtils.js";import g,{DISCOUNT_PRODUCTS as E}from"./DynamicCoupon/DynamicCoupon.js";import S from"./StaticCoupon/StaticCoupon.js";const j=j=>{var w,_,k,D,N,F,A,q,x,M;const[L,R]=i(),[U,G]=i(),[B,Y]=i(null!==(w=j.data)&&void 0!==w?w:"string"==typeof j.hideOption?{isStaticCoupon:"dynamic"===j.hideOption}:{isStaticCoupon:!1}),[X,H]=i(!0),[V,z]=i(),[K,Q]=i((null===(_=j.data)||void 0===_?void 0:_.minAmount)?r.AMOUNT:(null===(k=j.data)||void 0===k?void 0:k.minQuantity)?r.QUANTITY:r.NA),[$,Z]=i(void 0),[J,W]=i(void 0),[ee,te]=i(void 0),[oe,ie]=i(void 0),[ne,re]=i(0);n((()=>{let e;const{tempCouponData:t,discountType:o}=de();z(o),Y(Object.assign({},t)),j.hideProbability||(e=le()),H(I(t,K,o,j.hideProbability||!1,e,!!t.isStaticCoupon)),j.hideProbability||le()}),[]),n((()=>{let e;j.hideProbability||(e=le()),H(I(B,K,V,j.hideProbability||!1,e,!!B.isStaticCoupon))}),[B,ne,V,K]),n((()=>{var e,t,o,i,n,r,d;if(!j.newPickerConf&&((null===(e=j.products)||void 0===e?void 0:e.length)||(null===(t=j.collection)||void 0===t?void 0:t.length))){if(j.products&&(null===(o=j.products)||void 0===o?void 0:o.length)){if(null===(i=j.data)||void 0===i?void 0:i.entitledProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));W(e)}if(null===(n=j.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));Z(e)}}if(j.collection&&j.collection.length){if(null===(r=j.data)||void 0===r?void 0:r.entitledCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));ie(e)}if(null===(d=j.data)||void 0===d?void 0:d.prerequisiteCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));te(e)}}}}),[j.products,j.collection]),n((()=>{var e,t,o,i,n,r,d,c;(null===(t=null===(e=j.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&W(j.data.productsConf.entitledProducts),(null===(i=null===(o=j.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&Z(j.data.productsConf.prerequisiteProducts),(null===(r=null===(n=j.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&ie(j.data.collectionsConf.entitledCollections),(null===(c=null===(d=j.data)||void 0===d?void 0:d.collectionsConf)||void 0===c?void 0:c.prerequisiteCollections)&&te(j.data.collectionsConf.prerequisiteCollections)}),[null===(D=j.data)||void 0===D?void 0:D.productsConf,null===(N=j.data)||void 0===N?void 0:N.collectionsConf]),n((()=>{if(!J)return;if(j.newPickerConf){const e=[];return Object.values(J).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}const e=J.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}),[J]),n((()=>{if(!$)return;if(j.newPickerConf){const e=[];return Object.values($).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}const e=$.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}),[$]),n((()=>{if(!oe)return;if(j.newPickerConf){(null==oe?void 0:oe.isCustom)&&delete oe.isCustom;const e=Object.keys(oe).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}const e=oe.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}),[oe]),n((()=>{if(!ee)return;if(j.newPickerConf){(null==ee?void 0:ee.isCustom)&&delete ee.isCustom;const e=Object.keys(ee).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}const e=ee.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}),[ee]);const de=()=>{var e,t;let o,i=B;return B.isStaticCoupon||(B.targetType===d.SHIPPING_LINE?o=c.FREE_SHIPPING:B.targetType===d.LINE_ITEM?o=B.targetSelection===l.ENTITLED?(null===(e=B.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=B.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?c.BUY_X_GET_Y:c.AMOUNT_OFF_PRODUCTS:c.AMOUNT_OFF_ORDER:(i=Object.assign(Object.assign({},i),{targetType:d.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}),o=c.AMOUNT_OFF_ORDER)),{discountType:o,tempCouponData:i}},ce=[{value:c.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:V===c.AMOUNT_OFF_ORDER},{value:c.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:V===c.AMOUNT_OFF_PRODUCTS},{value:c.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:V===c.BUY_X_GET_Y},{value:c.FREE_SHIPPING,label:"Free shipping",selected:V===c.FREE_SHIPPING}],le=()=>{if(!j.quadrant||!j.probability)return;const e=[...j.probability];let t=[];e.length>=j.quadrant&&e.splice(j.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(B.probability||0);return re(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},se=e=>{var t,o,i,n;const a=e.value;z(a),Z([]),W([]),te([]),ie([]),Q(r.NA),a===c.FREE_SHIPPING?Y({value:100,targetSelection:l.ALL,targetType:d.SHIPPING_LINE,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):a===c.BUY_X_GET_Y?Y({targetSelection:l.ENTITLED,targetType:d.LINE_ITEM,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):a===c.AMOUNT_OFF_ORDER?Y({targetSelection:l.ALL,targetType:d.LINE_ITEM,valueType:null!==(o=null===(t=j.data)||void 0===t?void 0:t.valueType)&&void 0!==o?o:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0}):a===c.AMOUNT_OFF_PRODUCTS&&Y({targetSelection:l.ENTITLED,targetType:d.LINE_ITEM,valueType:null!==(n=null===(i=j.data)||void 0===i?void 0:i.valueType)&&void 0!==n?n:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:"",expireAt:void 0,expireAfter:void 0})};return e(C,Object.assign({width:(U||L)&&j.newPickerConf?"25px":"750px",open:j.isOpen,headingTitle:L?"Select Products":j.title,headingSubtitle:L?void 0:j.subTitle,footerLeftCustomElement:j.errorMsg?j.errorMsg&&t(h,{theme:"light",tagText:j.errorMsg,type:"negative"}):!j.quadrant||j.hideProbability?t(o,{}):ne<=1?t(h,{theme:"light",tagText:`Current probability sum: ${ne}`,type:"white"}):t(b,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:t("div",{children:t(h,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${ne}`,type:"negative",LeadingIcon:y})})})),headerRightCustomElement:j.allowStaticCoupon||L?void 0:t(a,{options:ce,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{se(e)}}),onClose:j.onClose,footerShadow:!0,primaryButton:L?{buttonType:"primary",onClick:()=>{R(void 0)},buttonText:"Add"}:U?{buttonType:"primary",onClick:()=>{G(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:X,isLoading:null!==(F=j.loading)&&void 0!==F&&F,onClick:()=>{var e,t;B.isStaticCoupon?j.onSaveClicked({quadrant:B.quadrant,couponCode:B.couponCode,description:B.description,isStaticCoupon:B.isStaticCoupon,probability:B.probability,title:B.title}):j.onSaveClicked(Object.assign(Object.assign({},B),{description:O(B,j.currency,null!==(e=j.products)&&void 0!==e?e:[],null!==(t=j.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:J,prerequisiteProducts:$},collectionsConf:{entitledCollections:oe,prerequisiteCollections:ee}}))}},secondaryButton:L?{buttonType:"tertiaryGray",onClick:()=>{R(void 0)},buttonText:"Back"}:U?{buttonType:"tertiaryGray",onClick:()=>{G(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:j.onClose,buttonText:"Close"}},{children:[!L&&!U&&e(P,{children:[j.allowStaticCoupon&&!L&&e(f,Object.assign({selectedDiv:B.isStaticCoupon?1:2},{children:["static"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{B.isStaticCoupon||Y({isStaticCoupon:!0,quadrant:B.quadrant})}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{color:v.colorsV2.content.brand}:{}},{children:"Static code"})),t(p,Object.assign({style:B.isStaticCoupon?{color:v.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{B.isStaticCoupon&&(z(c.AMOUNT_OFF_ORDER),Y({isStaticCoupon:!1,quadrant:B.quadrant,targetType:d.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}))}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{}:{color:v.colorsV2.content.brand}},{children:"Dynamic code"})),t(p,Object.assign({style:B.isStaticCoupon?{}:{color:v.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),B.isStaticCoupon&&!L&&t(S,{discountData:B,setDiscountData:Y,hideProbability:j.hideProbability||!1,discountAdminUrl:j.discountAdminUrl}),!B.isStaticCoupon&&!L&&!U&&t(g,{currency:j.currency,entitledProducts:null!=J?J:[],prerequisiteProducts:null!=$?$:[],setEntitledProducts:W,setPrerequisiteProducts:Z,discountData:B,productPickerOpen:L,setIsProductPickerOpen:R,setDiscountData:Y,selectedCouponType:V,setSelectedCouponType:z,selectedMinimumRequirement:K,setSelectedMinimumRequirement:Q,hideProbability:j.hideProbability||!1,hideExpiration:j.hideExpiration||!1,allowStaticCoupon:j.allowStaticCoupon,onChangeCouponType:se,collectionPickerOpen:U,entitledCollections:null!=oe?oe:[],prerequisiteCollections:null!=ee?ee:[],setIsCollectionPickerOpen:G,setEntitledCollections:ie,setPrerequisiteCollections:te,useNewPicker:!!j.newPickerConf})]}),!!L&&e(o,{children:[!j.newPickerConf&&t("div",Object.assign({style:{padding:"12px 0"}},{children:t(m,{show:!0,onSave:()=>{},products:null!==(A=j.products)&&void 0!==A?A:[],title:"Select Products",onClose:()=>{R(void 0)},selectedProducts:null!==(q=L===E.ENTITLED?J:$)&&void 0!==q?q:[],setSelectedProducts:L===E.ENTITLED?W:Z,onSearchKeyChange:j.onProductSearch})})),j.newPickerConf&&t(T,{visible:!0,onClose:()=>R(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:L===E.ENTITLED?J:$,onAdd:e=>{L===E.ENTITLED?W(e):Z(e),R(void 0)},zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:j.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!U&&t("div",Object.assign({style:{padding:"12px 0"}},{children:e(o,{children:[j.newPickerConf&&t(T,{visible:!0,onClose:()=>G(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:U===E.ENTITLED?oe:ee,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),U===E.ENTITLED?ie(e):te(e),G(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,searchFetcher:j.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!j.newPickerConf&&t(m,{show:!0,onSave:()=>{},products:null!==(x=j.collection)&&void 0!==x?x:[],title:"Select Products",onClose:()=>{G(void 0)},selectedProducts:null!==(M=U===E.ENTITLED?oe:ee)&&void 0!==M?M:[],setSelectedProducts:U===E.ENTITLED?ie:te,onSearchKeyChange:j.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};export{j as DiscountModal};
1
+ import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import{useState as i,useEffect as n}from"react";import{MIN_PURCHASE_REQUIREMENT as r,DISCOUNT_TARGET_TYPES as c,DISCOUNT_TYPES as d,DISCOUNT_TARGET_SELECTION as l,DISCOUNT_VALUE_TYPES as s}from"./type.js";import"../dropdown/DropdownPopover/index.js";import{Dropdown as a}from"../dropdown/Dropdown.js";import"../dropdown/ChipDropdown.js";import"../zeroState/ZeroState.js";import{TitleSmall as u,BodyCaption as p}from"../TypographyStyle.js";import{DEFAULT_THEME as C}from"../../constants/Theme.js";import"../dropdown/OpenedDropdown/components/description/Description.styled.js";import"../checkBox/CheckBox.styled.js";import"../list-item/ListItem.js";import"../dropdown/OpenedDropdown/components/menu/FreeFormMenu.styled.js";import"../dropdown/OpenedDropdown/components/menu/MenuItem.js";import"../dropdown/OpenedDropdown/components/menu/MenuList.styled.js";import"../button/Button.js";import"../dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.styled.js";import"../dropdown/OpenedDropdown/components/OpennedDropdown.styled.js";import"../input/Input.js";import"../dropdown/MenuItem/MenuItem.js";import{StyledModal as v}from"../modals/styledModal.js";import{ProductPickerContent as m}from"../product-picker/ProductPickerModal.js";import{Tag as h}from"../tag/Tag.js";import{Tooltip as b}from"../tooltips/Tooltip.js";import y from"../../assets/icons/triangle_error.svg.js";import{ProductPickerModal as T}from"../product-picker-v2/modal.js";import{StyledDiscountDialogueContainer as P,CouponTypeContainerStyled as I}from"./DiscountModal.styled.js";import{validateDiscountData as O,descriptionBuilder as f}from"./DiscountUtils.js";import g,{DISCOUNT_PRODUCTS as E}from"./DynamicCoupon/DynamicCoupon.js";import S from"./StaticCoupon/StaticCoupon.js";const j=j=>{var w,_,k,D,N,F,q,M,A,L;const[x,R]=i(),[U,G]=i(),[B,Y]=i(null!==(w=j.data)&&void 0!==w?w:"string"==typeof j.hideOption?{isStaticCoupon:"dynamic"===j.hideOption}:{isStaticCoupon:!1}),[X,H]=i(!0),[V,z]=i(),[K,Q]=i((null===(_=j.data)||void 0===_?void 0:_.minAmount)?r.AMOUNT:(null===(k=j.data)||void 0===k?void 0:k.minQuantity)?r.QUANTITY:r.NA),[$,Z]=i(void 0),[J,W]=i(void 0),[ee,te]=i(void 0),[oe,ie]=i(void 0),[ne,re]=i(0);n((()=>{let e;const{tempCouponData:t,discountType:o}=ce();z(o),Y(Object.assign({},t)),j.hideProbability||(e=le()),H(O(t,K,o,j.hideProbability||!1,e,!!t.isStaticCoupon)),j.hideProbability||le()}),[]),n((()=>{let e;j.hideProbability||(e=le()),H(O(B,K,V,j.hideProbability||!1,e,!!B.isStaticCoupon))}),[B,ne,V,K]),n((()=>{var e,t,o,i,n,r,c;if(!j.newPickerConf&&((null===(e=j.products)||void 0===e?void 0:e.length)||(null===(t=j.collection)||void 0===t?void 0:t.length))){if(j.products&&(null===(o=j.products)||void 0===o?void 0:o.length)){if(null===(i=j.data)||void 0===i?void 0:i.entitledProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));W(e)}if(null===(n=j.data)||void 0===n?void 0:n.prerequisiteProductIds){const e=j.products.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteProductIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));Z(e)}}if(j.collection&&j.collection.length){if(null===(r=j.data)||void 0===r?void 0:r.entitledCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.entitledCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));ie(e)}if(null===(c=j.data)||void 0===c?void 0:c.prerequisiteCollectionIds){const e=j.collection.filter((e=>{var t,o;return null===(o=null===(t=j.data)||void 0===t?void 0:t.prerequisiteCollectionIds)||void 0===o?void 0:o.includes(parseInt(e.id))}));te(e)}}}}),[j.products,j.collection]),n((()=>{var e,t,o,i,n,r,c,d;(null===(t=null===(e=j.data)||void 0===e?void 0:e.productsConf)||void 0===t?void 0:t.entitledProducts)&&W(j.data.productsConf.entitledProducts),(null===(i=null===(o=j.data)||void 0===o?void 0:o.productsConf)||void 0===i?void 0:i.prerequisiteProducts)&&Z(j.data.productsConf.prerequisiteProducts),(null===(r=null===(n=j.data)||void 0===n?void 0:n.collectionsConf)||void 0===r?void 0:r.entitledCollections)&&ie(j.data.collectionsConf.entitledCollections),(null===(d=null===(c=j.data)||void 0===c?void 0:c.collectionsConf)||void 0===d?void 0:d.prerequisiteCollections)&&te(j.data.collectionsConf.prerequisiteCollections)}),[null===(D=j.data)||void 0===D?void 0:D.productsConf,null===(N=j.data)||void 0===N?void 0:N.collectionsConf]),n((()=>{if(!J)return;if(j.newPickerConf){const e=[];return Object.values(J).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}const e=J.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledProductIds:e}))}),[J]),n((()=>{if(!$)return;if(j.newPickerConf){const e=[];return Object.values($).forEach((t=>{t.products&&Object.keys(t.products).forEach((t=>{e.push(parseInt(t))}))})),void Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}const e=$.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteProductIds:e}))}),[$]),n((()=>{if(!oe)return;if(j.newPickerConf){(null==oe?void 0:oe.isCustom)&&delete oe.isCustom;const e=Object.keys(oe).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}const e=oe.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{entitledCollectionIds:e}))}),[oe]),n((()=>{if(!ee)return;if(j.newPickerConf){(null==ee?void 0:ee.isCustom)&&delete ee.isCustom;const e=Object.keys(ee).map((e=>parseInt(e)));return void Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}const e=ee.map((e=>parseInt(e.id)));Y(Object.assign(Object.assign({},B),{prerequisiteCollectionIds:e}))}),[ee]);const ce=()=>{var e,t;let o,i=B;return B.isStaticCoupon||(B.targetType===c.SHIPPING_LINE?o=d.FREE_SHIPPING:B.targetType===c.LINE_ITEM?o=B.targetSelection===l.ENTITLED?(null===(e=B.prerequisiteProductIds)||void 0===e?void 0:e.length)||(null===(t=B.prerequisiteCollectionIds)||void 0===t?void 0:t.length)?d.BUY_X_GET_Y:d.AMOUNT_OFF_PRODUCTS:d.AMOUNT_OFF_ORDER:(i=Object.assign(Object.assign({},i),{targetType:c.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}),o=d.AMOUNT_OFF_ORDER)),{discountType:o,tempCouponData:i}},de=[{value:d.AMOUNT_OFF_ORDER,label:"Amount off on order",selected:V===d.AMOUNT_OFF_ORDER},{value:d.AMOUNT_OFF_PRODUCTS,label:"Amount off on products",selected:V===d.AMOUNT_OFF_PRODUCTS},{value:d.BUY_X_GET_Y,label:"Buy X Get Y FREE",selected:V===d.BUY_X_GET_Y},{value:d.FREE_SHIPPING,label:"Free shipping",selected:V===d.FREE_SHIPPING}],le=()=>{if(!j.quadrant||!j.probability)return;const e=[...j.probability];let t=[];e.length>=j.quadrant&&e.splice(j.quadrant-1,1),t=e;const o=t.reduce(((e,t)=>e+t),0)+(B.probability||0);return re(parseFloat(o.toFixed(4))),parseFloat(o.toFixed(4))},se=e=>{var t,o,i,n;const a=e.value;z(a),Z([]),W([]),te([]),ie([]),Q(r.NA),a===d.FREE_SHIPPING?Y({value:100,targetSelection:l.ALL,targetType:c.SHIPPING_LINE,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:""}):a===d.BUY_X_GET_Y?Y({targetSelection:l.ENTITLED,targetType:c.LINE_ITEM,valueType:s.PERCENTAGE,quadrant:B.quadrant,isStaticCoupon:!1,title:""}):a===d.AMOUNT_OFF_ORDER?Y({targetSelection:l.ALL,targetType:c.LINE_ITEM,valueType:null!==(o=null===(t=j.data)||void 0===t?void 0:t.valueType)&&void 0!==o?o:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:""}):a===d.AMOUNT_OFF_PRODUCTS&&Y({targetSelection:l.ENTITLED,targetType:c.LINE_ITEM,valueType:null!==(n=null===(i=j.data)||void 0===i?void 0:i.valueType)&&void 0!==n?n:s.FIXED_AMOUNT,quadrant:B.quadrant,isStaticCoupon:!1,title:""})};return e(v,Object.assign({width:(U||x)&&j.newPickerConf?"25px":"750px",open:j.isOpen,headingTitle:x?"Select Products":j.title,headingSubtitle:x?void 0:j.subTitle,footerLeftCustomElement:j.errorMsg?j.errorMsg&&t(h,{theme:"light",tagText:j.errorMsg,type:"negative"}):!j.quadrant||j.hideProbability?t(o,{}):ne<=1?t(h,{theme:"light",tagText:`Current probability sum: ${ne}`,type:"white"}):t(b,Object.assign({body:"Probability sum should not exceed 1",placement:"top"},{children:t("div",{children:t(h,{style:{cursor:"pointer"},theme:"light",tagText:`Current probability sum: ${ne}`,type:"negative",LeadingIcon:y})})})),headerRightCustomElement:j.allowStaticCoupon||x?void 0:t(a,{options:de,width:"200px",placement:"bottom-start",size:"small",onSelect:e=>{se(e)}}),onClose:j.onClose,footerShadow:!0,primaryButton:x?{buttonType:"primary",onClick:()=>{R(void 0)},buttonText:"Add"}:U?{buttonType:"primary",onClick:()=>{G(void 0)},buttonText:"Add"}:{buttonType:"primary",buttonText:"Add code",disabled:X,isLoading:null!==(F=j.loading)&&void 0!==F&&F,onClick:()=>{var e,t;B.isStaticCoupon?j.onSaveClicked({quadrant:B.quadrant,couponCode:B.couponCode,description:B.description,isStaticCoupon:B.isStaticCoupon,probability:B.probability,title:B.title}):j.onSaveClicked(Object.assign(Object.assign({},B),{description:f(B,j.currency,null!==(e=j.products)&&void 0!==e?e:[],null!==(t=j.collection)&&void 0!==t?t:[]),productsConf:{entitledProducts:J,prerequisiteProducts:$},collectionsConf:{entitledCollections:oe,prerequisiteCollections:ee}}))}},secondaryButton:x?{buttonType:"tertiaryGray",onClick:()=>{R(void 0)},buttonText:"Back"}:U?{buttonType:"tertiaryGray",onClick:()=>{G(void 0)},buttonText:"Back"}:{buttonType:"tertiaryGray",onClick:j.onClose,buttonText:"Close"}},{children:[!x&&!U&&e(P,{children:[j.allowStaticCoupon&&!x&&e(I,Object.assign({selectedDiv:B.isStaticCoupon?1:2},{children:["static"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{B.isStaticCoupon||Y({isStaticCoupon:!0,quadrant:B.quadrant})}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{color:C.colorsV2.content.brand}:{}},{children:"Static code"})),t(p,Object.assign({style:B.isStaticCoupon?{color:C.colorsV2.content.brand}:{}},{children:"One static code for all customers"}))]})),"dynamic"===j.hideOption?t(o,{}):e("div",Object.assign({className:"coupon-type__container",onClick:()=>{B.isStaticCoupon&&(z(d.AMOUNT_OFF_ORDER),Y({isStaticCoupon:!1,quadrant:B.quadrant,targetType:c.LINE_ITEM,targetSelection:l.ALL,valueType:s.FIXED_AMOUNT}))}},{children:[t(u,Object.assign({style:B.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"Dynamic code"})),t(p,Object.assign({style:B.isStaticCoupon?{}:{color:C.colorsV2.content.brand}},{children:"New code generated for everyone"}))]}))]})),B.isStaticCoupon&&!x&&t(S,{discountData:B,setDiscountData:Y,hideProbability:j.hideProbability||!1,discountAdminUrl:j.discountAdminUrl}),!B.isStaticCoupon&&!x&&!U&&t(g,{currency:j.currency,entitledProducts:null!=J?J:[],prerequisiteProducts:null!=$?$:[],setEntitledProducts:W,setPrerequisiteProducts:Z,discountData:B,productPickerOpen:x,setIsProductPickerOpen:R,setDiscountData:Y,selectedCouponType:V,setSelectedCouponType:z,selectedMinimumRequirement:K,setSelectedMinimumRequirement:Q,hideProbability:j.hideProbability||!1,hideExpiration:j.hideExpiration||!1,allowStaticCoupon:j.allowStaticCoupon,onChangeCouponType:se,collectionPickerOpen:U,entitledCollections:null!=oe?oe:[],prerequisiteCollections:null!=ee?ee:[],setIsCollectionPickerOpen:G,setEntitledCollections:ie,setPrerequisiteCollections:te,useNewPicker:!!j.newPickerConf})]}),!!x&&e(o,{children:[!j.newPickerConf&&t("div",Object.assign({style:{padding:"12px 0"}},{children:t(m,{show:!0,onSave:()=>{},products:null!==(q=j.products)&&void 0!==q?q:[],title:"Select Products",onClose:()=>{R(void 0)},selectedProducts:null!==(M=x===E.ENTITLED?J:$)&&void 0!==M?M:[],setSelectedProducts:x===E.ENTITLED?W:Z,onSearchKeyChange:j.onProductSearch})})),j.newPickerConf&&t(T,{visible:!0,onClose:()=>R(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:x===E.ENTITLED?J:$,onAdd:e=>{x===E.ENTITLED?W(e):Z(e),R(void 0)},zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,customCollectionRestriction:!1,searchFetcher:j.newPickerConf.searchProducts,hideCollectionCheckbox:!0,hideVariantCheckbox:!0,selectProductsFromCustomCollection:!0,hideSelectionCount:!0})]}),!!U&&t("div",Object.assign({style:{padding:"12px 0"}},{children:e(o,{children:[j.newPickerConf&&t(T,{visible:!0,onClose:()=>G(void 0),collectionFetcher:j.newPickerConf.fetchCollections,productFetcher:j.newPickerConf.fetchProducts,selectedItems:U===E.ENTITLED?oe:ee,onAdd:e=>{Object.values(e).forEach((e=>{e.products&&delete e.products})),U===E.ENTITLED?ie(e):te(e),G(void 0)},customCollectionRestriction:!1,zIndex:200,storeId:j.newPickerConf.storeId,searchInCollectionFetcher:j.newPickerConf.searchInCollection,searchFetcher:j.newPickerConf.searchProducts,hideProductCheckbox:!0,hideVariantCheckbox:!0,title:"Select Collections",hideGlobalSearch:!0,hideSelectionCount:!0}),!j.newPickerConf&&t(m,{show:!0,onSave:()=>{},products:null!==(A=j.collection)&&void 0!==A?A:[],title:"Select Products",onClose:()=>{G(void 0)},selectedProducts:null!==(L=U===E.ENTITLED?oe:ee)&&void 0!==L?L:[],setSelectedProducts:U===E.ENTITLED?ie:te,onSearchKeyChange:j.onCollectionSearch,searchPlaceholder:"Search collections..."})]})}))]}))};export{j as DiscountModal};
@@ -15,7 +15,6 @@ interface InputWithVariablesProps {
15
15
  showAddButton?: boolean;
16
16
  errorMessage?: string;
17
17
  showSideModal?: boolean;
18
- noMaxCharCheck?: boolean;
19
18
  }
20
19
  export declare const InputWithVariables: React.FC<InputWithVariablesProps>;
21
20
  export {};
@@ -1,6 +1,6 @@
1
- import{jsxs as e,Fragment as a,jsx as l}from"react/jsx-runtime";import r from"../../assets/icons/PlusIcon.js";import{useRef as i,useState as d,useEffect as t}from"react";import o from"styled-components";import{v4 as s}from"uuid";import{COLORS as n}from"../../constants/Theme.js";import{AddVariableV2SideModal as u}from"../add-variableV2/AddVariableV2SideModal.js";import{AddVariableV2 as c}from"../add-variableV2/AddVariableV2.js";import{AddVariableStyled as v}from"../add-variableV2/AddVariableBox.styled.js";import{Input as p}from"../input/Input.js";import{BodyCaption as g}from"../TypographyStyle.js";const h=o=>{let{addVarBoxRight:n,allowMix:h,onChange:b,prevVariable:V,variablesList:T,onBlur:y,onlyVariables:f,placeHolder:x,showAddButton:j=!0,showHelp:w,showSideVariablePanel:C,errorMessage:B,showSideModal:S,noMaxCharCheck:k}=o;const A=i(null),[N,M]=d(!1),[O]=d(s()),[I,L]=d(),[E,F]=d(V),[q,Z]=d(!1),[$,z]=d(!1),[H,P]=d(B||"");return t((()=>{I&&I.actualValue&&F(h?e=>({actualValue:e.actualValue+I.actualValue,variableType:"string"}):e=>({actualValue:I.actualValue,variableType:I.variableType,needsFetching:I.needsFetching}))}),[I]),t((()=>{b(E)}),[E]),e(a,{children:[e(m,Object.assign({isVar:/^{{.*}}$/.test(E.actualValue)},{children:[l(p,{id:O,ref:A,skipFocus:!0,textControl:!0,isActive:N,value:E.actualValue,validate:e=>[!0,""],errorMessage:H,placeholder:x||"Add a value",onChangeText:(e,a)=>{if(P(""),f){const e=(null==a?void 0:a.keyCode)||(null==a?void 0:a.charCode);8!==e&&46!==e||F({actualValue:"",variableType:"string"})}else F(h?{actualValue:e,variableType:"string"}:{actualValue:e.replace(/{{.*}}/,""),variableType:"string"})},onReferenceInit:()=>{},onFocus:e=>{M(!0),z(!0),document.getElementById("varList")&&!q&&Z(!0)},onBlur:e=>{var a,l,r,i,d,t;null==y||y(e,E),"addVar"===(null===(a=e.relatedTarget)||void 0===a?void 0:a.id)||"varList"===(null===(l=e.relatedTarget)||void 0===l?void 0:l.id)||(null===(i=null===(r=e.relatedTarget)||void 0===r?void 0:r.className)||void 0===i?void 0:i.includes("exlualr0"))||(null===(t=null===(d=e.relatedTarget)||void 0===d?void 0:d.className)||void 0===t?void 0:t.includes("sc-dZoequ "))?(A.current&&A.current.focus(),M(!0)):document.getElementById("varList")?M(!0):(M(!1),Z(!1),z(!1))},noMaxCharCheck:k}),e("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"space-between"}},{children:[E.actualValue&&w&&l("div",Object.assign({style:{marginTop:4}},{children:l(g,{children:`This value is of type ${E.variableType}`})})),j&&$&&l("div",Object.assign({style:{marginTop:B?"-24px":"0px"}},{children:l(v,Object.assign({right:n,id:"addVar",onClick:()=>{Z(!q)}},{children:e("div",Object.assign({className:"add"},{children:[l(r,{color:"white"}),l("div",Object.assign({className:"variable"},{children:"Add variable"}))]}))}))}))]})),!C&&q&&l(c,{data:T,showVariable:!0,setShowVariable:()=>{Z(!1)},variableValue:I,setVariableValue:L,placeholder:"",pickerSize:"large",enableVariable:!0,selectWithTypes:!0,onSearchBlur:e=>{var a,l,r,i,d,t;"varList"===(null===(a=e.relatedTarget)||void 0===a?void 0:a.id)||(null===(r=null===(l=e.relatedTarget)||void 0===l?void 0:l.className)||void 0===r?void 0:r.includes("exlualr0"))||(null===(d=null===(i=e.relatedTarget)||void 0===i?void 0:i.className)||void 0===d?void 0:d.includes("sc-dZoequ "))?A.current.focus():"Enter here"===(null===(t=e.relatedTarget)||void 0===t?void 0:t.placeholder)?e.relatedTarget.id!==O&&(Z(!1),z(!1),M(!1)):(Z(!1),z(!1),M(!1))}})]})),C&&q&&l(u,{zIndex:2e3,data:null!=T?T:[],showVariable:q,setShowVariable:()=>{Z(!1)},placeholder:"Add a variable",customTrigger:e=>{L({actualValue:e.actualValue,variableType:"string"}),F(e)},onSearchBlur:e=>{var a,l,r,i,d,t;"varList"===(null===(a=e.relatedTarget)||void 0===a?void 0:a.id)||(null===(r=null===(l=e.relatedTarget)||void 0===l?void 0:l.className)||void 0===r?void 0:r.includes("exlualr0"))||(null===(d=null===(i=e.relatedTarget)||void 0===i?void 0:i.className)||void 0===d?void 0:d.includes("sc-dZoequ "))?A.current.focus():"Enter here"===(null===(t=e.relatedTarget)||void 0===t?void 0:t.placeholder)?e.relatedTarget.id!==O&&(Z(!1),z(!1),M(!1)):(Z(!1),z(!1),M(!1))}})]})},m=o.div`
1
+ import{jsxs as e,Fragment as a,jsx as l}from"react/jsx-runtime";import r from"../../assets/icons/PlusIcon.js";import{useRef as i,useState as d,useEffect as t}from"react";import o from"styled-components";import{v4 as s}from"uuid";import{COLORS as n}from"../../constants/Theme.js";import{AddVariableV2SideModal as u}from"../add-variableV2/AddVariableV2SideModal.js";import{AddVariableV2 as c}from"../add-variableV2/AddVariableV2.js";import{AddVariableStyled as v}from"../add-variableV2/AddVariableBox.styled.js";import{Input as p}from"../input/Input.js";import{BodyCaption as g}from"../TypographyStyle.js";const m=o=>{let{addVarBoxRight:n,allowMix:m,onChange:h,prevVariable:V,variablesList:T,onBlur:y,onlyVariables:f,placeHolder:j,showAddButton:x=!0,showHelp:w,showSideVariablePanel:B,errorMessage:S,showSideModal:A}=o;const N=i(null),[C,O]=d(!1),[k]=d(s()),[I,L]=d(),[M,E]=d(V),[F,q]=d(!1),[Z,$]=d(!1),[z,H]=d(S||"");return t((()=>{I&&I.actualValue&&E(m?e=>({actualValue:e.actualValue+I.actualValue,variableType:"string"}):e=>({actualValue:I.actualValue,variableType:I.variableType,needsFetching:I.needsFetching}))}),[I]),t((()=>{h(M)}),[M]),e(a,{children:[e(b,Object.assign({isVar:/^{{.*}}$/.test(M.actualValue)},{children:[l(p,{id:k,ref:N,skipFocus:!0,textControl:!0,isActive:C,value:M.actualValue,validate:e=>[!0,""],errorMessage:z,placeholder:j||"Add a value",onChangeText:(e,a)=>{if(H(""),f){const e=(null==a?void 0:a.keyCode)||(null==a?void 0:a.charCode);8!==e&&46!==e||E({actualValue:"",variableType:"string"})}else E(m?{actualValue:e,variableType:"string"}:{actualValue:e.replace(/{{.*}}/,""),variableType:"string"})},onReferenceInit:()=>{},onFocus:e=>{O(!0),$(!0),document.getElementById("varList")&&!F&&q(!0)},onBlur:e=>{var a,l,r,i,d,t;null==y||y(e,M),"addVar"===(null===(a=e.relatedTarget)||void 0===a?void 0:a.id)||"varList"===(null===(l=e.relatedTarget)||void 0===l?void 0:l.id)||(null===(i=null===(r=e.relatedTarget)||void 0===r?void 0:r.className)||void 0===i?void 0:i.includes("exlualr0"))||(null===(t=null===(d=e.relatedTarget)||void 0===d?void 0:d.className)||void 0===t?void 0:t.includes("sc-dZoequ "))?(N.current&&N.current.focus(),O(!0)):document.getElementById("varList")?O(!0):(O(!1),q(!1),$(!1))}}),e("div",Object.assign({style:{display:"flex",flexDirection:"row",justifyContent:"space-between"}},{children:[M.actualValue&&w&&l("div",Object.assign({style:{marginTop:4}},{children:l(g,{children:`This value is of type ${M.variableType}`})})),x&&Z&&l("div",Object.assign({style:{marginTop:S?"-24px":"0px"}},{children:l(v,Object.assign({right:n,id:"addVar",onClick:()=>{q(!F)}},{children:e("div",Object.assign({className:"add"},{children:[l(r,{color:"white"}),l("div",Object.assign({className:"variable"},{children:"Add variable"}))]}))}))}))]})),!B&&F&&l(c,{data:T,showVariable:!0,setShowVariable:()=>{q(!1)},variableValue:I,setVariableValue:L,placeholder:"",pickerSize:"large",enableVariable:!0,selectWithTypes:!0,onSearchBlur:e=>{var a,l,r,i,d,t;"varList"===(null===(a=e.relatedTarget)||void 0===a?void 0:a.id)||(null===(r=null===(l=e.relatedTarget)||void 0===l?void 0:l.className)||void 0===r?void 0:r.includes("exlualr0"))||(null===(d=null===(i=e.relatedTarget)||void 0===i?void 0:i.className)||void 0===d?void 0:d.includes("sc-dZoequ "))?N.current.focus():"Enter here"===(null===(t=e.relatedTarget)||void 0===t?void 0:t.placeholder)?e.relatedTarget.id!==k&&(q(!1),$(!1),O(!1)):(q(!1),$(!1),O(!1))}})]})),B&&F&&l(u,{zIndex:2e3,data:null!=T?T:[],showVariable:F,setShowVariable:()=>{q(!1)},placeholder:"Add a variable",customTrigger:e=>{L({actualValue:e.actualValue,variableType:"string"}),E(e)},onSearchBlur:e=>{var a,l,r,i,d,t;"varList"===(null===(a=e.relatedTarget)||void 0===a?void 0:a.id)||(null===(r=null===(l=e.relatedTarget)||void 0===l?void 0:l.className)||void 0===r?void 0:r.includes("exlualr0"))||(null===(d=null===(i=e.relatedTarget)||void 0===i?void 0:i.className)||void 0===d?void 0:d.includes("sc-dZoequ "))?N.current.focus():"Enter here"===(null===(t=e.relatedTarget)||void 0===t?void 0:t.placeholder)?e.relatedTarget.id!==k&&(q(!1),$(!1),O(!1)):(q(!1),$(!1),O(!1))}})]})},b=o.div`
2
2
  margin-bottom: 16px;
3
3
  input {
4
4
  color: ${e=>e.isVar?n.stroke.brand:"black"};
5
5
  }
6
- `;export{h as InputWithVariables};
6
+ `;export{m as InputWithVariables};
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  export type ShimmerImageProps = {
3
3
  imageUrl: string;
4
- width: number | string;
4
+ width: number;
5
5
  height: number;
6
6
  alt?: string;
7
7
  borderRadius?: number;
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t,Fragment as l}from"react/jsx-runtime";import{useEffect as o,useState as a,useMemo as i}from"react";import r from"../../utils/StringUtils.js";import{StyledModal as s}from"../modals/styledModal.js";import{CHANNEL_TYPE as n}from"../template-preview/models/Channels.js";import{TemplateModalContext as d}from"./context/templateModalContext.js";import c from"./modalElements/Footer.js";import m from"./modalElements/TemplateSelectModalContent.js";import{convertPlaceholdersToBikDropdown as p}from"./utils/convertPlaceholdersToBikDropdown.js";const u=u=>{let{selectedTemplate:h,closeDialog:b,showVariableMapping:g,channel:v,htmlContent:C,templateVariables:S,onTemplateSelect:f,globalPlaceholders:w,showOnlyContent:M,whatsappSpecificPickerMeta:T,zIndex:V,showVariableModal:j,variableList:x,discountCode:L,setDiscountCode:P,onBackPress:E,enabledCustomText:I,variableListForImage:y,showSampleValues:k,disableEditVariable:D,pod:A,extras:O}=u;var F,z;o((()=>{N(C)}),[C]);const[B,H]=a(v===n.EMAIL?"desktop":"mobile"),[$,N]=a(C),[U,W]=a(!1),[_,q]=a(h),[G,J]=a(null!=S?S:[]),[K,Q]=a(!1);const R=i((()=>p(w)),[w]);return e(d.Provider,Object.assign({value:{template:_,setTemplate:q,device:B,setDevice:H,display_content:$,setDisplayContent:N,originalVariableList:G,setOriginalVariableList:J,isError:U,setIsError:W,channel:v,globalNormalizedPlaceholders:R,templateSelectionTriggered:K,setTemplateSelectionTriggered:Q,enabledCustomText:I,disableEditVariable:D,pod:A,extras:O}},{children:M?e(m,{channel:n.EMAIL,hideHeader:!0}):t(s,Object.assign({zIndex:V,centralContainerStyles:{width:v===n.EMAIL&&g?1e3:800},open:!0,onClose:()=>{null==b||b()},headingTitle:null==_?void 0:_.label,headingSubtitle:v===n.WHATSAPP?`${r.capitaliseFirstLetterOfString(null!==(F=null==_?void 0:_.category)&&void 0!==F?F:"")} • ${null!==(z=null==_?void 0:_.templateCategory)&&void 0!==z?z:""}`:"",onBackPress:()=>{null==E||E()}},{children:[e(m,{showSampleValues:k,showVariableMapping:g,channel:v,whatsappSpecificPickerMeta:T,showVariableModal:j,variableList:x,discountCode:L,setDiscountCode:P,variableListForImage:y&&(null==y?void 0:y.length)>0?y:x}),f?e(c,{onSelect:function(){const e=null==f?void 0:f(_,G,null!=$?$:"");e?W(!!e):Q(!0)}}):e(l,{})]}))}))};export{u as TemplateContextMapper};
1
+ import{jsx as e,jsxs as t,Fragment as l}from"react/jsx-runtime";import{useEffect as o,useState as a,useMemo as i}from"react";import r from"../../utils/StringUtils.js";import{StyledModal as s}from"../modals/styledModal.js";import{CHANNEL_TYPE as n}from"../template-preview/models/Channels.js";import{TemplateModalContext as d}from"./context/templateModalContext.js";import c from"./modalElements/Footer.js";import m from"./modalElements/TemplateSelectModalContent.js";import{convertPlaceholdersToBikDropdown as p}from"./utils/convertPlaceholdersToBikDropdown.js";const u=u=>{let{selectedTemplate:h,closeDialog:b,showVariableMapping:g,channel:v,htmlContent:C,templateVariables:S,onTemplateSelect:f,globalPlaceholders:w,showOnlyContent:M,whatsappSpecificPickerMeta:T,zIndex:V,showVariableModal:j,variableList:x,discountCode:L,setDiscountCode:P,onBackPress:E,enabledCustomText:I,variableListForImage:y,showSampleValues:k,disableEditVariable:D,pod:A,extras:O}=u;var F,z;o((()=>{N(C)}),[C]);const[B,H]=a(v===n.EMAIL?"desktop":"mobile"),[$,N]=a(C),[U,W]=a(!1),[_,q]=a(h),[G,J]=a(null!=S?S:[]),[K,Q]=a(!1);const R=i((()=>p(w)),[w]);return e(d.Provider,Object.assign({value:{template:_,setTemplate:q,device:B,setDevice:H,display_content:$,setDisplayContent:N,originalVariableList:G,setOriginalVariableList:J,isError:U,setIsError:W,channel:v,globalNormalizedPlaceholders:R,templateSelectionTriggered:K,setTemplateSelectionTriggered:Q,enabledCustomText:I,disableEditVariable:D,pod:A,extras:O}},{children:M?e(m,{channel:n.EMAIL,hideHeader:!0}):t(s,Object.assign({zIndex:V,centralContainerStyles:{width:v===n.EMAIL&&g?1e3:700},open:!0,onClose:()=>{null==b||b()},headingTitle:null==_?void 0:_.label,headingSubtitle:v===n.WHATSAPP?`${r.capitaliseFirstLetterOfString(null!==(F=null==_?void 0:_.category)&&void 0!==F?F:"")} • ${null!==(z=null==_?void 0:_.templateCategory)&&void 0!==z?z:""}`:"",onBackPress:()=>{null==E||E()}},{children:[e(m,{showSampleValues:k,showVariableMapping:g,channel:v,whatsappSpecificPickerMeta:T,showVariableModal:j,variableList:x,discountCode:L,setDiscountCode:P,variableListForImage:y&&(null==y?void 0:y.length)>0?y:x}),f?e(c,{onSelect:function(){const e=null==f?void 0:f(_,G,null!=$?$:"");e?W(!!e):Q(!0)}}):e(l,{})]}))}))};export{u as TemplateContextMapper};
@@ -3,7 +3,7 @@ import{jsxs as e,jsx as t,Fragment as o}from"react/jsx-runtime";import{useRef as
3
3
  // height: 100%;
4
4
  `,f=n.div`
5
5
  padding: 16px 14px;
6
- max-width: 450px;
6
+ max-width: 350px;
7
7
 
8
8
  height: ${e=>e.channel===i.WHATSAPP?"500px":"475px"};
9
9
  overflow-y: 'auto';
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import{Button as a}from"../../button/Button.js";import{InputWithVariables as i}from"../../input-with-vars/InputWithVariables.js";import{StyledModal as o}from"../../modals/styledModal.js";import"../../template-preview/TemplatePreview.js";import"../../template-preview/WhatsApp/WhatsAppLikePreview.js";import"../../template-preview/WhatsApp/WhatsAppLikePreviewV2.js";import{DEFAULT_THEME as r}from"../../../constants/Theme.js";import{HEADER_TYPES as s}from"../../template-preview/models/TemplateMeta.js";import{POD as l}from"../../template-preview/models/WhatsAppTemplate.js";import{TitleMedium as d,BodySecondary as n,BodyRegular as p,BodyCaption as m}from"../../TypographyStyle.js";import c from"../../../assets/icons/file.svg.js";import h from"../../../assets/icons/filePdf.svg.js";import g from"../../../assets/icons/image.svg.js";import u from"../../../assets/icons/upload.svg.js";import{useTemplateModalContext as b}from"../context/templateModalContext.js";const f=f=>{let{setOpenEditMedia:j,mediaComponentFormat:v,variableListForImage:y,openEditMedia:x,uploadMedia:M}=f;const{pod:w}=b();return e(o,Object.assign({open:x,zIndex:2e3,onClose:()=>j(!1),width:"440px"},{children:t("div",Object.assign({style:{padding:24,borderRadius:4}},{children:[e(d,Object.assign({style:{marginBottom:16}},{children:"Update media"})),t("div",Object.assign({style:{padding:24,border:`1px dashed ${r.colorsV2.stroke.primary}`,backgroundColor:r.colorsV2.surface.subdued}},{children:[t("div",Object.assign({style:{marginBottom:24,display:"flex",justifyContent:"center",flexDirection:"column",alignItems:"center",gap:16}},{children:[e("div",Object.assign({style:{height:80,width:80,borderRadius:"100%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:r.colorsV2.background.base}},{children:v===s.IMAGE?e(g,{width:40,height:40}):v===s.VIDEO?e(c,{width:40,height:40}):e(h,{width:40,height:40})})),e(d,{children:v===s.IMAGE?"Upload an image":v===s.VIDEO?"Upload a video":"Upload a document"}),e(n,{children:v===s.IMAGE?"JPEG/ PNG format • Max 5MB":v===s.VIDEO?"MP4 format video • Max 16MB":"PDF format a document • Max 100MB"})]})),t("div",Object.assign({style:{marginBottom:16}},{children:[e(p,{children:"Media"}),e(i,{noMaxCharCheck:!0,addVarBoxRight:"46px",allowMix:!1,onChange:e=>{},prevVariable:{actualValue:"",variableType:"string"},variablesList:y,showSideVariablePanel:!0,placeHolder:"Enter URL or add variable...",onBlur:(e,t)=>{t&&t.actualValue&&M(t.actualValue)},showAddButton:w!==l.CAMPAIGN||v===s.IMAGE})]})),t("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:4}},{children:[e("hr",{style:{height:"2px",flex:.5,backgroundColor:"black"}}),e(m,Object.assign({style:{flex:1}},{children:"Or upload media from device"})),e("hr",{style:{height:"2px",flex:.5,backgroundColor:"black"}})]})),e("div",Object.assign({style:{display:"flex",width:"100%"}},{children:e(a,{matchParentWidth:!0,buttonText:"Upload",buttonType:"secondary",LeadingIcon:u,onClick:()=>M()})}))]}))]}))}))};export{f as default};
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import{Button as i}from"../../button/Button.js";import{InputWithVariables as a}from"../../input-with-vars/InputWithVariables.js";import{StyledModal as s}from"../../modals/styledModal.js";import"../../template-preview/TemplatePreview.js";import"../../template-preview/WhatsApp/WhatsAppLikePreview.js";import"../../template-preview/WhatsApp/WhatsAppLikePreviewV2.js";import{DEFAULT_THEME as o}from"../../../constants/Theme.js";import{HEADER_TYPES as r}from"../../template-preview/models/TemplateMeta.js";import"../../template-preview/models/WhatsAppTemplate.js";import{TitleMedium as l,BodySecondary as d,BodyRegular as n,BodyCaption as p}from"../../TypographyStyle.js";import m from"../../../assets/icons/file.svg.js";import c from"../../../assets/icons/filePdf.svg.js";import h from"../../../assets/icons/image.svg.js";import g from"../../../assets/icons/upload.svg.js";const u=u=>{let{setOpenEditMedia:b,mediaComponentFormat:f,variableListForImage:j,openEditMedia:v,uploadMedia:y}=u;return e(s,Object.assign({open:v,zIndex:2e3,onClose:()=>b(!1),width:"440px"},{children:t("div",Object.assign({style:{padding:24,borderRadius:4}},{children:[e(l,Object.assign({style:{marginBottom:16}},{children:"Update media"})),t("div",Object.assign({style:{padding:24,border:`1px dashed ${o.colorsV2.stroke.primary}`,backgroundColor:o.colorsV2.surface.subdued}},{children:[t("div",Object.assign({style:{marginBottom:24,display:"flex",justifyContent:"center",flexDirection:"column",alignItems:"center",gap:16}},{children:[e("div",Object.assign({style:{height:80,width:80,borderRadius:"100%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:o.colorsV2.background.base}},{children:f===r.IMAGE?e(h,{width:40,height:40}):f===r.VIDEO?e(m,{width:40,height:40}):e(c,{width:40,height:40})})),e(l,{children:f===r.IMAGE?"Upload an image":f===r.VIDEO?"Upload a video":"Upload a document"}),e(d,{children:f===r.IMAGE?"JPEG/ PNG format • Max 5MB":f===r.VIDEO?"MP4 format video • Max 16MB":"PDF format a document • Max 100MB"})]})),t("div",Object.assign({style:{marginBottom:16}},{children:[e(n,{children:"Media"}),e(a,{addVarBoxRight:"46px",allowMix:!1,onChange:e=>{},prevVariable:{actualValue:"",variableType:"string"},variablesList:j,showSideVariablePanel:!0,placeHolder:"Enter URL or add variable...",onBlur:(e,t)=>{t&&t.actualValue&&y(t.actualValue)},showAddButton:[r.IMAGE,r.VIDEO,r.DOCUMENT].includes(f)})]})),t("div",Object.assign({style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:4}},{children:[e("hr",{style:{height:"2px",flex:.5,backgroundColor:"black"}}),e(p,Object.assign({style:{flex:1}},{children:"Or upload media from device"})),e("hr",{style:{height:"2px",flex:.5,backgroundColor:"black"}})]})),e("div",Object.assign({style:{display:"flex",width:"100%"}},{children:e(i,{matchParentWidth:!0,buttonText:"Upload",buttonType:"secondary",LeadingIcon:g,onClick:()=>y()})}))]}))]}))}))};export{u as default};
@@ -1,8 +1,8 @@
1
- import{jsxs as e,jsx as i,Fragment as t}from"react/jsx-runtime";import o from"../../../assets/icons/document_pdf.svg.js";import r from"../../../assets/icons/edit.svg.js";import s from"../../../assets/icons/refresh.svg.js";import n from"../../../assets/icons/video_camcorder.svg.js";import l from"styled-components";import{ShimmerImage as d}from"../../shimmer-image/ShimmerImage.js";import{Spinner as a}from"../../spinner/Spinner.js";import{HEADER_TYPES as c}from"../../template-preview/models/TemplateMeta.js";import{BodyCaption as m,BodySecondary as p,Caption as h}from"../../TypographyStyle.js";import g from"../../../utils/StringUtils.js";import{COLORS as f}from"../../../constants/Theme.js";import{Container as j,ImageContainer as v,RightComponent as y}from"./EditMediaV2.style.js";const u=l.div`
1
+ import{jsxs as e,jsx as t,Fragment as i}from"react/jsx-runtime";import o from"../../../assets/icons/document_pdf.svg.js";import r from"../../../assets/icons/edit.svg.js";import s from"../../../assets/icons/refresh.svg.js";import n from"../../../assets/icons/video_camcorder.svg.js";import l from"styled-components";import{Spinner as d}from"../../spinner/Spinner.js";import{HEADER_TYPES as a}from"../../template-preview/models/TemplateMeta.js";import{BodyCaption as c,BodySecondary as m,Caption as p}from"../../TypographyStyle.js";import h from"../../../utils/StringUtils.js";import{COLORS as g}from"../../../constants/Theme.js";import{Container as f,ImageContainer as j,RightComponent as v}from"./EditMediaV2.style.js";const y=l.div`
2
2
  padding-left: 14px;
3
3
  padding-right: 6px;
4
4
  width: 44px;
5
5
  height: 24px;
6
- border-left: 1px solid ${f.stroke.primary};
6
+ border-left: 1px solid ${g.stroke.primary};
7
7
  cursor: pointer;
8
- `,b=l=>{const{imageName:b,error:w,isLoading:x,mediaType:O,disableEditVariable:E,selectedVariable:L,setOpenEditMedia:C}=l,M=null==b?void 0:b[0].split("/"),S=null==M?void 0:M[M.length-1];return e(j,{children:[i(v,Object.assign({error:!!w,onClick:()=>null==C?void 0:C(!0)},{children:w?i(s,{color:f.content.brand,width:32,height:32}):x?i(a,{size:"small"}):O===c.IMAGE?i(d,{imageUrl:null==b?void 0:b[0],width:56,height:56,borderRadius:8}):O===c.VIDEO?i(n,{width:18,height:22,color:f.content.placeholder}):i(o,{width:18,height:22,color:f.content.placeholder})})),e(y,{children:[i("div",Object.assign({style:{flex:1}},{children:b&&w?i(t,{}):x?i(m,Object.assign({style:{marginLeft:8}},{children:"Your media is getting loaded..."})):i(p,Object.assign({style:{color:f.content.primary,marginLeft:8}},{children:L||g.toCapitilize(null==O?void 0:O.toLowerCase())||S}))})),!!w&&e("div",Object.assign({style:{display:"flex",flexDirection:"column",marginLeft:8}},{children:[e(p,Object.assign({style:{color:f.content.negative}},{children:["Error loading this ",null==O?void 0:O.toLowerCase(),". Retry"]})),i(h,Object.assign({style:{color:f.content.secondary}},{children:w}))]})),!E&&!w&&!x&&i(u,Object.assign({onClick:()=>null==C?void 0:C(!0),onKeyDown:()=>null==C?void 0:C(!0),role:"presentation"},{children:i(r,{width:24,height:24,color:f.content.placeholder})}))]})]})};export{b as default};
8
+ `,u=l=>{const{imageName:u,error:b,isLoading:x,mediaType:w,handleImageChange:O,disableEditVariable:C,selectedVariable:E,setOpenEditMedia:L}=l,M=null==u?void 0:u[0].split("/"),T=null==M?void 0:M[M.length-1];return e(f,{children:[t(j,Object.assign({error:!!b,onClick:b?O:void 0},{children:b?t(s,{color:g.content.brand,width:32,height:32}):x?t(d,{size:"small"}):w===a.IMAGE?t("img",{alt:"",src:null==u?void 0:u[0],style:{width:"100%",height:"56px",borderRadius:8,objectFit:"cover"}}):w===a.VIDEO?t(n,{width:18,height:22,color:g.content.placeholder}):t(o,{width:18,height:22,color:g.content.placeholder})})),e(v,{children:[t("div",Object.assign({style:{flex:1}},{children:u&&b?t(i,{}):x?t(c,Object.assign({style:{marginLeft:8}},{children:"Your media is getting loaded..."})):t(m,Object.assign({style:{color:g.content.primary,marginLeft:8}},{children:E||h.toCapitilize(null==w?void 0:w.toLowerCase())||T}))})),!!b&&e("div",Object.assign({style:{display:"flex",flexDirection:"column",marginLeft:8}},{children:[e(m,Object.assign({style:{color:g.content.negative}},{children:["Error loading this ",null==w?void 0:w.toLowerCase(),". Retry"]})),t(p,Object.assign({style:{color:g.content.secondary}},{children:b}))]})),!C&&!b&&!x&&t(y,Object.assign({onClick:()=>null==L?void 0:L(!0),onKeyDown:()=>null==L?void 0:L(!0),role:"presentation"},{children:t(r,{width:24,height:24,color:g.content.placeholder})}))]})]})};export{u as default};
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsxs as i,Fragment as o,jsx as t}from"react/jsx-runtime";import n,{useState as a}from"react";import{FileUploaderHelper as l}from"../../helpers/FileUploaderHelper.js";import{BikImageCropper as r}from"../../image-cropper/BikImageCropper.js";import"../../image-compress/ImageCompress.js";import"../../states/StateComponent.js";import"../../../constants/zindex.js";import"../../modals/styledModal.js";import"../../spinner/Spinner.js";import{HEADER_TYPES as d}from"../../template-preview/models/TemplateMeta.js";import{useTemplateModalContext as s}from"../context/templateModalContext.js";import p from"./EditMediaModal.js";import m from"./EditMediaV2.js";const c=e=>/^{{.*}}$/.test(e),u=u=>{let{mediaComponent:v,template:f,updateTemplateImageUrl:g,whatsappSpecificPickerMeta:h,variableListForImage:b}=u;var j,E,M,y,I,C,O,x;const{disableEditVariable:A}=s(),[k,w]=a(void 0),[T,F]=a(),[R,U]=a(),[_,L]=a(!1),N=n.createRef(),[V,D]=a(!1),[G,S]=a(""),{template:B,setTemplate:H}=s();let z;function P(){var e;(null===(e=null==N?void 0:N.current)||void 0===e?void 0:e.click)&&N.current.click()}function W(i){var o;return e(this,void 0,void 0,(function*(){const e=new l;if(i instanceof Blob){const t=e.validate(i);if(t)S(t),D(!1);else{const e=v.format===d.IMAGE,t=yield h.uploadMediaFiles({file:i,fileName:k,isImage:e});if(t.success){const[e]=i.type.split("/");g(null!==(o=t.url)&&void 0!==o?o:"","application"===e?d.DOCUMENT:d[e.toUpperCase()])}else S("An unknown technical error occured");D(!1)}}else S("An unknown technical error occured"),D(!1)}))}return z=v.format===d.IMAGE?"image/png, image/jpeg":v.format===d.VIDEO?"video/mp4":"application/pdf",i(o,{children:[t(p,{mediaComponentFormat:null!==(j=v.format)&&void 0!==j?j:d.IMAGE,uploadMedia:function(i){var o;return e(this,void 0,void 0,(function*(){if(S(""),U(""),L(!1),i)if(i.startsWith("https"))try{D(!0);const e=yield fetch(i),o=yield e.blob();yield W(o)}catch(e){S("An unknown technical error occurred")}else if(c(i)){U(i);const e=Object.assign({},B);if(e.components){const t=null===(o=null==e?void 0:e.components)||void 0===o?void 0:o.findIndex((e=>{if("HEADER"===e.type&&"NONE"!==e.format&&"TEXT"!==e.format)return!0}));if(void 0!==t&&t>-1&&(null==e?void 0:e.components[t])){const o=Object.assign(Object.assign({},e.components[t]),{format:v.format,example:{header_handle:[i]}}),n=[...e.components];n[t]=o,e.components=n}}e.mapping&&(e.mapping=Object.assign(Object.assign({},e.mapping),{header:[i]})),D(!1),null==H||H(Object.assign({},e))}else D(!1),S("Invalid URL or variable");else P()}))},variableListForImage:b||[],setOpenEditMedia:L,openEditMedia:_}),!!T&&t(r,{aspectRatio:15/8,src:T,onCropComplete:function(i){return e(this,void 0,void 0,(function*(){D(!1),S("");const e=yield fetch(i);W(yield e.blob()).then((()=>{F(void 0)}))}))},onCancel:()=>{D(!1),F(""),N.current&&(N.current.value="")}}),t("input",{ref:N,style:{display:"none"},type:"file",onChange:function(e){var i;S(""),D(!0);const o=null===(i=e.target.files)||void 0===i?void 0:i[0];if(v.format===d.IMAGE){const e=new FileReader;F(""),w(""),e.onload=()=>{F(e.result),w(null==o?void 0:o.name)},o&&e.readAsDataURL(o)}else W(o)},accept:z}),t(m,{imageName:null!==(M=null===(E=null==v?void 0:v.example)||void 0===E?void 0:E.header_handle)&&void 0!==M?M:[],handleImageChange:P,mediaType:null==v?void 0:v.format,error:G,isLoading:V,setOpenEditMedia:L,selectedVariable:c(null!==(C=null===(I=null===(y=null==v?void 0:v.example)||void 0===y?void 0:y.header_handle)||void 0===I?void 0:I[0])&&void 0!==C?C:"")?null===(x=null===(O=null==v?void 0:v.example)||void 0===O?void 0:O.header_handle)||void 0===x?void 0:x[0]:R,disableEditVariable:A})]})};export{u as default};
1
+ import{__awaiter as e}from"../../../_virtual/_tslib.js";import{jsxs as t,Fragment as i,jsx as o}from"react/jsx-runtime";import n,{useState as a}from"react";import{FileUploaderHelper as r}from"../../helpers/FileUploaderHelper.js";import{BikImageCropper as l}from"../../image-cropper/BikImageCropper.js";import"../../image-compress/ImageCompress.js";import"../../states/StateComponent.js";import"../../../constants/zindex.js";import"../../modals/styledModal.js";import"../../spinner/Spinner.js";import{DEFAULT_IMAGE as s}from"../../shimmer-image/ShimmerImage.js";import{HEADER_TYPES as m}from"../../template-preview/models/TemplateMeta.js";import{useTemplateModalContext as d}from"../context/templateModalContext.js";import p from"./EditMediaModal.js";import c from"./EditMediaV2.js";const f=f=>{let{mediaComponent:u,template:v,updateTemplateImageUrl:g,whatsappSpecificPickerMeta:h,variableListForImage:j}=f;var b,E,M;const{disableEditVariable:I}=d(),[y,C]=a(void 0),[O,A]=a(),[x,k]=a(),[w,T]=a(!1),F=n.createRef(),[R,U]=a(!1),[L,N]=a(""),{template:V,setTemplate:D}=d();let G;function S(){var e;(null===(e=null==F?void 0:F.current)||void 0===e?void 0:e.click)&&F.current.click()}function _(t){var i;return e(this,void 0,void 0,(function*(){const e=new r;if(t instanceof Blob){const o=e.validate(t);if(o)N(o),U(!1);else{const e=u.format===m.IMAGE,o=yield h.uploadMediaFiles({file:t,fileName:y,isImage:e});if(o.success){const[e]=t.type.split("/");g(null!==(i=o.url)&&void 0!==i?i:"","application"===e?m.DOCUMENT:m[e.toUpperCase()])}else N("An unknown technical error occured");U(!1)}}else N("An unknown technical error occured"),U(!1)}))}return G=u.format===m.IMAGE?"image/png, image/jpeg":u.format===m.VIDEO?"video/mp4":"application/pdf",t(i,{children:[o(p,{mediaComponentFormat:null!==(b=u.format)&&void 0!==b?b:m.IMAGE,uploadMedia:function(t){var i;return e(this,void 0,void 0,(function*(){if(N(""),k(""),T(!1),t)if(t.startsWith("https"))try{U(!0);const e=yield fetch(t),i=yield e.blob();yield _(i)}catch(e){N("An unknown technical error occurred")}else if(/^{{.*}}$/.test(t)){k(t);const e=Object.assign({},V);if(e.components){const t=null===(i=null==e?void 0:e.components)||void 0===i?void 0:i.findIndex((e=>{if("HEADER"===e.type&&"NONE"!==e.format&&"TEXT"!==e.format)return!0}));if(void 0!==t&&t>-1&&(null==e?void 0:e.components[t])){const i=Object.assign(Object.assign({},e.components[t]),{format:u.format,example:{header_handle:[s]}}),o=[...e.components];o[t]=i,e.components=o}}e.mapping&&(e.mapping=Object.assign(Object.assign({},e.mapping),{header:[t]})),U(!1),null==D||D(Object.assign({},e))}else U(!1),N("Invalid URL or variable");else S()}))},variableListForImage:j||[],setOpenEditMedia:T,openEditMedia:w}),!!O&&o(l,{aspectRatio:15/8,src:O,onCropComplete:function(t){return e(this,void 0,void 0,(function*(){U(!1),N("");const e=yield fetch(t);_(yield e.blob()).then((()=>{A(void 0)}))}))},onCancel:()=>{U(!1),A(""),F.current&&(F.current.value="")}}),o("input",{ref:F,style:{display:"none"},type:"file",onChange:function(e){var t;N(""),U(!0);const i=null===(t=e.target.files)||void 0===t?void 0:t[0];if(u.format===m.IMAGE){const e=new FileReader;A(""),C(""),e.onload=()=>{A(e.result),C(null==i?void 0:i.name)},i&&e.readAsDataURL(i)}else _(i)},accept:G}),o(c,{imageName:null!==(M=null===(E=null==u?void 0:u.example)||void 0===E?void 0:E.header_handle)&&void 0!==M?M:[],handleImageChange:S,mediaType:null==u?void 0:u.format,error:L,isLoading:R,setOpenEditMedia:T,selectedVariable:x,disableEditVariable:I})]})};export{f as default};
@@ -1 +1 @@
1
- import{jsxs as t,jsx as o}from"react/jsx-runtime";import{useState as e,useEffect as i}from"react";import{POD as n}from"../../template-preview/models/WhatsAppTemplate.js";import{useTemplateModalContext as a}from"../context/templateModalContext.js";import{useAdditionalVariables as l}from"../custom-hooks/useAdditionalVariables.js";import{getAllDataFromTemplateComponent as s}from"../utils/getDataFromTemplateComponent.js";import{BackTrackComponent as d}from"./BackTrackComponent.js";import{DiscountCodeComponent as r}from"./DiscountCodeComponent.js";import{EditTemplateMediaContainer as p}from"./EditMediaV2.style.js";import c from"./EditWhatsAppTemplateMediaV2.js";import u from"./VariableConnector.js";import{Container as m}from"./VariableConnectorsPanel.js";import v from"./VariableConnectorWhatsApp.js";import b from"./VariableEditorHeader.js";import g from"./WhatsAppTemplateCardButtonV2.js";const h=h=>{let{template:f,onTemplateChange:T,whatsappSpecificPickerMeta:j,showVariableModal:x,variableList:C,variableListForImage:O,discountCode:y,setDiscountCode:V}=h;var E,k,L,w,B,I,A,M,U,D,N,R,H,S,P,Q,W;const{originalVariableList:_,pod:F,extras:Y}=a(),{descriptionComponents:K,urlBtns:$,qrbBtns:q,imageComponent:X,bodyVariables:z,headerVariables:G}=s(f),[J,Z]=e(!1);function tt(t,o){var e,i,n,a,l;const s=Object.assign({},f),d=null==s?void 0:s.components.findIndex((t=>"BUTTONS"===t.type));if(void 0!==d&&d>-1){const l=null===(e=null==s?void 0:s.components[d].buttons)||void 0===e?void 0:e.findIndex((t=>"URL"===t.type));if(void 0!==l&&l>-1){const e="custom"===o&&"string"==typeof t,r=[...null!==(a=null===(n=null===(i=s.components)||void 0===i?void 0:i[d])||void 0===n?void 0:n.buttons)&&void 0!==a?a:[]];r[l]=Object.assign(Object.assign({},r[l]),{url:"https://d.bik.ai/{{1}}",example:[e?t:"string"!=typeof t?t.defaultValue:""]});const p=Object.assign(Object.assign({},s.components[d]),{buttons:r}),c=Object.assign(Object.assign({},s.mapping),{buttons:e?["((customBtnPlaceholder))"]:"string"!=typeof t?[t.placeHolder]:void 0});s.mapping=c;const u=[...s.components];u[d]=p,s.components=u}}if("string"!=typeof t){"checkout.checkoutUrl"===(null===(l=t.placeHolder)||void 0===l?void 0:l.slice(2,-2))?Z(!0):(Z(!1),null==V||V(""))}null==T||T(s)}function ot(t,o,e){var i;const n=Object.assign({},f),a=null==n?void 0:n.components.findIndex((t=>"BUTTONS"===t.type));if(void 0!==a&&a>-1){const o=null===(i=null==n?void 0:n.components[a].buttons)||void 0===i?void 0:i.filter((t=>"QUICK_REPLY"===t.type));o&&(o[e]=Object.assign(Object.assign({},o[e]),{flowId:t.flowId,flowName:t.flowName}));const l=Object.assign(Object.assign({},n.components[a]),{buttons:o}),s=[...n.components];s[a]=l,n.components=s}null==T||T(n)}i((()=>{var t;const o=null===(t=f.mapping.buttons)||void 0===t?void 0:t[0];"checkout.checkoutUrl"===(null==o?void 0:o.slice(2,-2))?Z(!0):(Z(!1),null==V||V(""))}),[f]);const et=l({variableList:C,categoryDisplayName:"Custom Variables",variableDisplayName:"Custom Text",variableValue:"{{custom.text}}"});return t(m,Object.assign({style:{flexDirection:"column",maxWidth:400,maxHeight:460}},{children:[!!X&&o(p,{children:o(c,{whatsappSpecificPickerMeta:j,mediaComponent:X,updateTemplateImageUrl:function(t,o){var e;let i=Object.assign({},f);const n=null===(e=null==i?void 0:i.components)||void 0===e?void 0:e.findIndex((t=>{if("HEADER"===t.type&&"NONE"!==t.format&&"TEXT"!==t.format)return!0}));if(void 0!==n&&n>-1&&(null==i?void 0:i.components[n])){const e=Object.assign(Object.assign({},i.components[n]),{format:o,example:{header_handle:[t]}}),a=[...i.components];a[n]=e,i=Object.assign(Object.assign({},i),{components:a})}i.mapping&&(i.mapping=Object.assign(Object.assign({},i.mapping),{header:void 0})),null==T||T(Object.assign({},i))},template:f,variableListForImage:O})}),(z.length>0||G.length>0)&&o(b,{containerStyle:{paddingTop:X?24:8},headerText:"Edit variable values",subText:"Edit values for the variables used in template",toolTipInfo:"Variables are placeholder texts which can either be filled through data or custom texts. These can be edited through the dropdowns below"}),null==K?void 0:K.map(((t,e)=>o(v,{originalVariableList:_,type:t.type,descriptionComponent:t.component,variableMapping:"HEADER"===t.type?f.mapping.header:f.mapping.body,showVariableModal:x,variableList:C},e))),(null===(k=null===(E=$[0])||void 0===E?void 0:E.component)||void 0===k?void 0:k.buttons)&&(null===(B=null===(w=null===(L=$[0])||void 0===L?void 0:L.component)||void 0===w?void 0:w.buttons)||void 0===B?void 0:B.length)>0&&o(b,{headerText:"Edit buttons",subText:"Edit the link connected to the CTA button"}),null===(I=null==_?void 0:_.buttons)||void 0===I?void 0:I.map(((t,e)=>{if("URL"===t.type)return o(g,{variableListIndex:e,CTAoptions:null==j?void 0:j.CTAoptions,button:t,originalVariableList:_,updateSelectedURLTemplateBtn:tt,variableList:C},`${e}`)})),(null===(M=null===(A=q[0])||void 0===A?void 0:A.component)||void 0===M?void 0:M.buttons)&&(null===(N=null===(D=null===(U=q[0])||void 0===U?void 0:U.component)||void 0===D?void 0:D.buttons)||void 0===N?void 0:N.length)>0&&(F!==n.CHATBOT?o(b,{headerText:"Edit buttons",subText:"Edit the chatflows triggered on clicking the buttons",toolTipInfo:"There is an option to trigger chatflows through the buttons which can keep the user engaged"}):o(d,{backTrackMessage:null===(R=null==Y?void 0:Y.backTrackExtra)||void 0===R?void 0:R[0],setBackTrackMessage:null===(H=null==Y?void 0:Y.backTrackExtra)||void 0===H?void 0:H[1]})),null===(S=null==_?void 0:_.buttons)||void 0===S?void 0:S.map(((t,e)=>{if("QUICK_REPLY"===t.type)return o(g,{variableListIndex:e,QRBoptions:null==j?void 0:j.QRBoptions,button:t,originalVariableList:_,updateSelectedQRBTemplateBtn:ot},`${e}`)})),F===n.CHATBOT&&J&&o(r,{discountCode:null===(P=null==Y?void 0:Y.discountCodeExtra)||void 0===P?void 0:P[0],setDiscountCode:null===(Q=null==Y?void 0:Y.discountCodeExtra)||void 0===Q?void 0:Q[1],variableList:C}),null===(W=null==_?void 0:_.buttons)||void 0===W?void 0:W.map(((t,e)=>{var i,n,a;if("COPY_CODE"===t.type)return o(u,{index:e,variable:{variableName:null!==(i=t.text)&&void 0!==i?i:"",updatedValue:null!==(n=t.buttonVariable)&&void 0!==n?n:"",type:"string",isEditableVariable:!0,index:null!==(a=t.index)&&void 0!==a?a:0},showVariableModal:!0,variableList:et,componentType:"BUTTONS"},e)}))]}))};export{h as default};
1
+ import{jsxs as t,jsx as o}from"react/jsx-runtime";import{useState as e,useEffect as n}from"react";import{POD as i}from"../../template-preview/models/WhatsAppTemplate.js";import{useTemplateModalContext as l}from"../context/templateModalContext.js";import{getAllDataFromTemplateComponent as a}from"../utils/getDataFromTemplateComponent.js";import{BackTrackComponent as s}from"./BackTrackComponent.js";import{DiscountCodeComponent as d}from"./DiscountCodeComponent.js";import{EditTemplateMediaContainer as r}from"./EditMediaV2.style.js";import p from"./EditWhatsAppTemplateMediaV2.js";import{Container as c}from"./VariableConnectorsPanel.js";import u from"./VariableConnectorWhatsApp.js";import m from"./VariableEditorHeader.js";import v from"./WhatsAppTemplateCardButtonV2.js";const b=b=>{let{template:g,onTemplateChange:h,whatsappSpecificPickerMeta:f,showVariableModal:T,variableList:j,variableListForImage:C,discountCode:O,setDiscountCode:x}=b;var E,k,y,V,w,B,L,I,A,M,R,U,H,D,S,N;const{originalVariableList:P,pod:Q,extras:W}=l(),{descriptionComponents:F,urlBtns:_,qrbBtns:K,imageComponent:Y,bodyVariables:$,headerVariables:q}=a(g),[X,z]=e(!1);function G(t,o){var e,n,i,l,a;const s=Object.assign({},g),d=null==s?void 0:s.components.findIndex((t=>"BUTTONS"===t.type));if(void 0!==d&&d>-1){const a=null===(e=null==s?void 0:s.components[d].buttons)||void 0===e?void 0:e.findIndex((t=>"URL"===t.type));if(void 0!==a&&a>-1){const e="custom"===o&&"string"==typeof t,r=[...null!==(l=null===(i=null===(n=s.components)||void 0===n?void 0:n[d])||void 0===i?void 0:i.buttons)&&void 0!==l?l:[]];r[a]=Object.assign(Object.assign({},r[a]),{url:"https://d.bik.ai/{{1}}",example:[e?t:"string"!=typeof t?t.defaultValue:""]});const p=Object.assign(Object.assign({},s.components[d]),{buttons:r}),c=Object.assign(Object.assign({},s.mapping),{buttons:e?["((customBtnPlaceholder))"]:"string"!=typeof t?[t.placeHolder]:void 0});s.mapping=c;const u=[...s.components];u[d]=p,s.components=u}}if("string"!=typeof t){"checkout.checkoutUrl"===(null===(a=t.placeHolder)||void 0===a?void 0:a.slice(2,-2))?z(!0):(z(!1),null==x||x(""))}null==h||h(s)}function J(t,o,e){var n;const i=Object.assign({},g),l=null==i?void 0:i.components.findIndex((t=>"BUTTONS"===t.type));if(void 0!==l&&l>-1){const o=null===(n=null==i?void 0:i.components[l].buttons)||void 0===n?void 0:n.filter((t=>"QUICK_REPLY"===t.type));o&&(o[e]=Object.assign(Object.assign({},o[e]),{flowId:t.flowId,flowName:t.flowName}));const a=Object.assign(Object.assign({},i.components[l]),{buttons:o}),s=[...i.components];s[l]=a,i.components=s}null==h||h(i)}return n((()=>{var t;const o=null===(t=g.mapping.buttons)||void 0===t?void 0:t[0];"checkout.checkoutUrl"===(null==o?void 0:o.slice(2,-2))?z(!0):(z(!1),null==x||x(""))}),[g]),t(c,Object.assign({style:{flexDirection:"column",maxHeight:460}},{children:[!!Y&&o(r,{children:o(p,{whatsappSpecificPickerMeta:f,mediaComponent:Y,updateTemplateImageUrl:function(t,o){var e;let n=Object.assign({},g);const i=null===(e=null==n?void 0:n.components)||void 0===e?void 0:e.findIndex((t=>{if("HEADER"===t.type&&"NONE"!==t.format&&"TEXT"!==t.format)return!0}));if(void 0!==i&&i>-1&&(null==n?void 0:n.components[i])){const e=Object.assign(Object.assign({},n.components[i]),{format:o,example:{header_handle:[t]}}),l=[...n.components];l[i]=e,n=Object.assign(Object.assign({},n),{components:l})}n.mapping&&(n.mapping=Object.assign(Object.assign({},n.mapping),{header:void 0})),null==h||h(Object.assign({},n))},template:g,variableListForImage:C})}),($.length>0||q.length>0)&&o(m,{containerStyle:{paddingTop:Y?24:8},headerText:"Edit variable values",subText:"Edit values for the variables used in template",toolTipInfo:"Variables are placeholder texts which can either be filled through data or custom texts. These can be edited through the dropdowns below"}),null==F?void 0:F.map(((t,e)=>o(u,{originalVariableList:P,type:t.type,descriptionComponent:t.component,variableMapping:"HEADER"===t.type?g.mapping.header:g.mapping.body,showVariableModal:T,variableList:j},e))),(null===(k=null===(E=_[0])||void 0===E?void 0:E.component)||void 0===k?void 0:k.buttons)&&(null===(w=null===(V=null===(y=_[0])||void 0===y?void 0:y.component)||void 0===V?void 0:V.buttons)||void 0===w?void 0:w.length)>0&&o(m,{headerText:"Edit buttons",subText:"Edit the link connected to the CTA button"}),null===(B=null==P?void 0:P.buttons)||void 0===B?void 0:B.map(((t,e)=>{if("URL"===t.type)return o(v,{CTAoptions:null==f?void 0:f.CTAoptions,button:t,originalVariableList:P,updateSelectedURLTemplateBtn:G,variableList:j},`${e}`)})),(null===(I=null===(L=K[0])||void 0===L?void 0:L.component)||void 0===I?void 0:I.buttons)&&(null===(R=null===(M=null===(A=K[0])||void 0===A?void 0:A.component)||void 0===M?void 0:M.buttons)||void 0===R?void 0:R.length)>0&&(Q!==i.CHATBOT?o(m,{headerText:"Edit buttons",subText:"Edit the chatflows triggered on clicking the buttons",toolTipInfo:"There is an option to trigger chatflows through the buttons which can keep the user engaged"}):o(s,{backTrackMessage:null===(U=null==W?void 0:W.backTrackExtra)||void 0===U?void 0:U[0],setBackTrackMessage:null===(H=null==W?void 0:W.backTrackExtra)||void 0===H?void 0:H[1]})),null===(D=null==P?void 0:P.buttons)||void 0===D?void 0:D.map(((t,e)=>{if("QUICK_REPLY"===t.type)return o(v,{QRBoptions:null==f?void 0:f.QRBoptions,button:t,originalVariableList:P,updateSelectedQRBTemplateBtn:J},`${e}`)})),Q===i.CHATBOT&&X&&o(d,{discountCode:null===(S=null==W?void 0:W.discountCodeExtra)||void 0===S?void 0:S[0],setDiscountCode:null===(N=null==W?void 0:W.discountCodeExtra)||void 0===N?void 0:N[1],variableList:j})]}))};export{b as default};
@@ -17,4 +17,4 @@ import{jsx as e,jsxs as t}from"react/jsx-runtime";import i from"react";import o
17
17
  height: calc(100% - 17px);
18
18
  border-radius: 16px;
19
19
  overflow-y: auto;
20
- `,n=i.forwardRef(((i,o)=>{let{display_content:n,channel:h,template:c,showSampleValues:d}=i;const{pod:w}=r();return e("div",{children:t(l,Object.assign({channel:h},{children:[e("img",{alt:"",src:"https://firebasestorage.googleapis.com/v0/b/staging-bikayi.appspot.com/o/bik%2FkNwEVoGlLpVjOsXoO1M8WgvWicP2%2F6f07b850-8b4b-4d58-96cc-8ba6df7b4e4a-Device___Frame.jpg?alt=media&token=253f1bfe-8481-4f54-bdef-3c0a73697d6a",style:{width:s(h),height:443}}),e(m,Object.assign({ref:o},{children:e(a,{showSampleValues:d,template:c,channel:h,smsSpecificMeta:{smsDisplayContent:n},whatsAppSpecificMeta:{showWhatsAppHeader:!0,whatsAppExtras:w!==p.CHATBOT,containerStyle:{border:"none",borderBottomRightRadius:0,borderBottomLeftRadius:0,minHeight:426,width:240}},size:"small",hideHeader:!0,emailSpecificMeta:{emailDisplayContent:n,hideViewButtonForEmail:!0,emailHtmlContainerId:"template_html_mobile",containerStyle:{height:"100%",width:"100%"},templateContainerStyles:{height:"100%"}}})}))]}))})}));n.displayName="MobilePreview";export{n as default};
20
+ `,n=i.forwardRef(((i,o)=>{let{display_content:n,channel:h,template:c,showSampleValues:d}=i;const{pod:w}=r();return e("div",{children:t(l,Object.assign({channel:h},{children:[e("img",{alt:"",src:"https://firebasestorage.googleapis.com/v0/b/staging-bikayi.appspot.com/o/bik%2FkNwEVoGlLpVjOsXoO1M8WgvWicP2%2F6f07b850-8b4b-4d58-96cc-8ba6df7b4e4a-Device___Frame.jpg?alt=media&token=253f1bfe-8481-4f54-bdef-3c0a73697d6a",style:{width:s(h),height:443}}),e(m,Object.assign({ref:o},{children:e(a,{showSampleValues:d,template:c,channel:h,smsSpecificMeta:{smsDisplayContent:n},whatsAppSpecificMeta:{showWhatsAppHeader:!0,whatsAppExtras:w!==p.CHATBOT,containerStyle:{border:"none",borderBottomRightRadius:0,borderBottomLeftRadius:0,minHeight:426,width:236}},size:"small",hideHeader:!0,emailSpecificMeta:{emailDisplayContent:n,hideViewButtonForEmail:!0,emailHtmlContainerId:"template_html_mobile",containerStyle:{height:"100%",width:"100%"},templateContainerStyles:{height:"100%"}}})}))]}))})}));n.displayName="MobilePreview";export{n as default};
@@ -14,7 +14,7 @@ export interface VariableConnectorProps {
14
14
  showVariableModal?: boolean;
15
15
  variableList?: VariableListInterfaceV2[];
16
16
  setShowDiscountCheckBox?: any;
17
- componentType?: 'HEADER' | 'BODY' | 'BUTTONS' | 'FOOTER' | 'limited_time_offer';
17
+ componentType?: 'HEADER' | 'BODY' | 'BUTTONS' | 'FOOTER';
18
18
  CTAoptions?: ButtonPlaceHolderOptions[];
19
19
  }
20
20
  declare const VariableConnector: React.FC<VariableConnectorProps>;
@@ -1,7 +1,7 @@
1
- import{jsxs as e,jsx as t}from"react/jsx-runtime";import l from"../../../assets/icons/edit.svg.js";import{format as a}from"date-fns";import{useState as i,useEffect as n}from"react";import o from"styled-components";import{AddVariableV2SideModal as s}from"../../add-variableV2/AddVariableV2SideModal.js";import{CustomDateTime as u}from"../../custom-date-time/CustomDateTime.js";import{Dropdown as d}from"../../dropdown/Dropdown.js";import{Input as r}from"../../input/Input.js";import{truncate as c}from"../../product-picker-v2/collectionScreen.js";import{placeHolderNamePattern as p}from"../../template-preview/constants/regexPatterns.js";import{CHANNEL_TYPE as m}from"../../template-preview/models/Channels.js";import{POD as v}from"../../template-preview/models/WhatsAppTemplate.js";import{BodySecondary as b,BodyPrimary as g}from"../../TypographyStyle.js";import h from"../../../utils/StringUtils.js";import{COLORS as x}from"../../../constants/Theme.js";import{useTemplateModalContext as j}from"../context/templateModalContext.js";import{getVariableNameForEmailByIndex as _}from"../utils/getVariableNameEmail.js";const f=o.div`
1
+ import{jsxs as e,jsx as t}from"react/jsx-runtime";import l from"../../../assets/icons/edit.svg.js";import{useState as a,useEffect as i}from"react";import n from"styled-components";import{AddVariableV2SideModal as o}from"../../add-variableV2/AddVariableV2SideModal.js";import{Dropdown as s}from"../../dropdown/Dropdown.js";import{Input as u}from"../../input/Input.js";import{truncate as d}from"../../product-picker-v2/collectionScreen.js";import{placeHolderNamePattern as r}from"../../template-preview/constants/regexPatterns.js";import{CHANNEL_TYPE as c}from"../../template-preview/models/Channels.js";import{POD as p}from"../../template-preview/models/WhatsAppTemplate.js";import{BodySecondary as m,BodyPrimary as v}from"../../TypographyStyle.js";import b from"../../../utils/StringUtils.js";import{COLORS as g}from"../../../constants/Theme.js";import{useTemplateModalContext as h}from"../context/templateModalContext.js";import{getVariableNameForEmailByIndex as x}from"../utils/getVariableNameEmail.js";const j=n.div`
2
2
  /* surface/$color-background-warning-light */
3
3
 
4
- background: ${e=>e.focused&&e.channel===m.EMAIL?x.background.warning.light:"transparent"};
4
+ background: ${e=>e.focused&&e.channel===c.EMAIL?g.background.warning.light:"transparent"};
5
5
  border-radius: 4px;
6
6
  padding: 8px 10px;
7
- `,O={value:"custom_link",label:"Custom URL"},y={value:"custom_text",label:"Custom text"},T={value:"static_expiry",label:"Static Expiry"},V=o=>{let{onFocus:V,variable:k,index:A,showVariableModal:E,variableList:S,setShowDiscountCheckBox:w,componentType:P,CTAoptions:C}=o;var D,B;const[L,H]=i(!1),[N,M]=i(""),[W,$]=i([]),[I,R]=i(),[U,z]=i(!1),[Y,Z]=i(!1),{device:G,channel:q,isError:F,originalVariableList:J,template:K,templateSelectionTriggered:Q,setTemplate:X,setDisplayContent:ee,setOriginalVariableList:te,globalNormalizedPlaceholders:le,enabledCustomText:ae,pod:ie}=j();function ne(e,t){var l,a,i;const n=e;M(""),console.log("vj: single option",n),R(n),q===m.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value&&"static_expiry"!==n.value?(se(null!==(l=n.value)&&void 0!==l?l:"","string"),null==ue||ue(null!==(a=k.index)&&void 0!==a?a:0,n.value,!0)):(null==ue||ue(null!==(i=k.index)&&void 0!==i?i:0,N,!0,n.value),se("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?se(n.value,"url"===n.bikPlaceholderType?"link":"string"):(M(""),se("",n.value))}function oe(e,t){var l;M(t);const a="custom_link"===(null==I?void 0:I.value)&&t?t.includes("https")?t:`https://${t}`:t;se(a,"static_expiry"===e?"string":e),q===m.WHATSAPP&&(null==ue||ue(null!==(l=k.index)&&void 0!==l?l:0,a,"custom_link"===e,e))}function se(e,t){var l,a,i,n;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(q!==m.WHATSAPP){const a=_(A+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===G?"template_html_mobile":"template_html_desktop"),n=q===m.EMAIL?null===(l=null==i?void 0:i.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:k.variableName);const s=J.map(((t,l)=>l===A?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==te||te(s)}if(q===m.WHATSAPP){const l=J;let s=l.body,u=l.header,d=l.buttons;"BODY"===P?s=null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>l===A?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"HEADER"===P?u=null===(i=l.header)||void 0===i?void 0:i.map(((t,l)=>l===A?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"BUTTONS"===P&&(d=null===(n=l.buttons)||void 0===n?void 0:n.map(((l,a)=>a===A?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:[e]}):l))),null==te||te((e=>Object.assign(Object.assign({},e),{header:u,body:s,buttons:d})))}}function ue(e,t,l,a){var i,n,o,s;const u=Object.assign({},K);console.log("vj: update",{index:e,newValue:t,type:a});const d=null===(i=null==u?void 0:u.components)||void 0===i?void 0:i.map((l=>{var a,i,n,o,s,u,d,r,c,p;const m=Object.assign({},l);if("BODY"===l.type&&"BODY"===P){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const l=[...null!==(s=null===(o=null===(n=m.example)||void 0===n?void 0:n.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{body_text:[l]});return Object.assign(Object.assign({},m),{example:a})}}else if("HEADER"===l.type&&"HEADER"===P){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=m.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{header_text:l});return Object.assign(Object.assign({},m),{example:a})}}else if("BUTTONS"===l.type&&"BUTTONS"===P){if(null===(p=null===(c=l.buttons)||void 0===c?void 0:c[e])||void 0===p?void 0:p.example){const a=l.buttons.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return Object.assign(Object.assign({},m),{buttons:a})}}else if("limited_time_offer"===l.type&&"limited_time_offer"===P)return Object.assign(Object.assign({},m),{example:Object.assign(Object.assign({},m.example),{limited_time_offer:t})});return l}));console.log("vj: update components",d),u.components=d,l&&("BODY"===P&&(null===(n=null==u?void 0:u.mapping)||void 0===n?void 0:n.body)?u.mapping=Object.assign(Object.assign({},u.mapping),{body:u.mapping.body.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))}):"HEADER"===P&&(null===(o=null==u?void 0:u.mapping)||void 0===o?void 0:o.header)?u.mapping=Object.assign(Object.assign({},u.mapping),{header:u.mapping.header.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+20}))`:t:l))}):"BUTTONS"===P&&(null===(s=null==u?void 0:u.mapping)||void 0===s?void 0:s.buttons)&&(u.mapping=Object.assign(Object.assign({},u.mapping),{buttons:u.mapping.buttons.map(((l,i)=>i===e?"custom_link"===a?"((customPlaceholderName))":t:l))}))),null==X||X(Object.assign({},u))}return n((()=>{L&&(null==V||V())}),[L]),n((()=>{!function(){var e,t,l,a,i;const n="mobile"===G?"template_html_mobile":"template_html_desktop",o=document.getElementById(n),s=(null!==(a=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(i=null==o?void 0:o.contentWindow)||void 0===i?void 0:i.document.head.innerHTML);q===m.EMAIL&&(null==ee||ee(s))}()}),[Q]),n((()=>{var e;const t=[];let l=[];if(q!==m.MESSAGE||ae){"link"===(null==k?void 0:k.type)?(t.push({label:"",options:[O,y]}),R(O)):"date_time"===(null==k?void 0:k.type)?(t.push({label:"",options:[O,y]}),R(T)):(t.push({label:"",options:[O,y,T]}),R(y));const e=null!=le?le:[];$([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:h.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}else{const e=null!=le?le:[];$([{label:"",options:[y,O]},...e]),l=[{label:"",options:[y,O]},...e]}if((q===m.WHATSAPP||q===m.EMAIL||q===m.MESSAGE)&&k.updatedValue)if(p.test(k.updatedValue)&&q===m.WHATSAPP||k.updatedValue.startsWith("{{")&&q!==m.WHATSAPP){const e=function(e,t,l){var a;let i={label:"",value:""};const n=l===m.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(E){let t=e.updatedValue;if(ie===v.CHATBOT&&"BUTTONS"===P){const l=null==C?void 0:C.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}i={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(i=e)}))}));return i}(k,l,q);e.value&&R(e)}else"date_time"===k.type?(R(T),M(k.updatedValue)):(null===(e=k.updatedValue)||void 0===e?void 0:e.startsWith("https"))?(R(O),M(k.updatedValue.split("https://")[1])):(R(y),M(k.updatedValue))}),[]),n((()=>{G&&I&&N&&setTimeout((()=>{se("custom_link"===(null==I?void 0:I.value)&&N?N.includes("https")?N:`https://${N}`:N,I.value)}),100)}),[G]),n((()=>{!Y&&I&&k.updatedValue&&setTimeout((()=>{se("custom_link"===(null==I?void 0:I.value)&&k.updatedValue?k.updatedValue.includes("https")?k.updatedValue:`https://${k.updatedValue}`:k.updatedValue,I.value),Z(!0)}),100)}),[I]),e(f,Object.assign({channel:q,focused:L,onMouseEnter:()=>H(!0),onMouseLeave:()=>H(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(b,Object.assign({style:{color:F&&!I?x.content.negative:x.content.primary}},{children:[null===(D=k.variableName)||void 0===D?void 0:D.replace("{{","").replace("}}","")," ","link"===(null==k?void 0:k.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:E?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==I?void 0:I.label)?"space-between":"flex-end"}},{children:[t(g,{children:c(null!==(B=null==I?void 0:I.label)&&void 0!==B?B:"",20,!0)}),t(l,{onClick:()=>{z(!U)},width:24,height:24,color:x.content.primary})]})):t(d,{options:W,isSearchable:!1,onSelect:ne,defaultOptions:I?[Object.assign(Object.assign({},I),{selected:!0})]:[]})})),("custom_text"===(null==I?void 0:I.value)||"custom_link"===(null==I?void 0:I.value))&&t(r,{labelText:"custom_text"===(null==I?void 0:I.value)?"Custom text value":"custom_link"===(null==I?void 0:I.value)?"Custom URL value":"",id:`variable-value-${null==I?void 0:I.value}-${A}`,value:N,errorMessage:F?N&&0!==N.trim().length?"custom_link"!==I.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${N.trim()}`)&&0!==N.trim().length?"custom_link"!==I.value&&N.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==I?void 0:I.value)?2e3:30,prefixText:"custom_link"===(null==I?void 0:I.value)?"https://":"",placeholder:"link"===k.type||"custom_link"===I.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{oe(I.value,e)}}),"static_expiry"===(null==I?void 0:I.value)&&t(u,{placement:"auto",time:a(N?new Date(N):new Date,"hh:mm a"),date:N?new Date(N):new Date,minDate:new Date,error:"",setError:function(e){},onChange:e=>{console.log("vj: change date",e),oe("static_expiry",e.toISOString())}}),U&&t(s,{zIndex:2e3,data:null!=S?S:[],showVariable:U,setShowVariable:z,placeholder:"Add a variable",customTrigger:e=>{null==w||w(!1),"{{custom.url}}"===e.actualValue?ne({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?ne({label:e.displayName,selected:!0,value:"custom_text"}):"{{static.expiry}}"==e.actualValue?ne({label:e.displayName,selected:!0,value:"static_expiry"}):ne({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{f as Container,V as default};
7
+ `,O={value:"custom_link",label:"Custom URL"},_={value:"custom_text",label:"Custom text"},f=n=>{let{onFocus:f,variable:y,index:T,showVariableModal:k,variableList:A,setShowDiscountCheckBox:V,componentType:E,CTAoptions:S}=n;var P,w;const[C,B]=a(!1),[L,H]=a(""),[N,M]=a([]),[W,$]=a(),[D,I]=a(!1),[R,U]=a(!1),{device:z,channel:Y,isError:Z,originalVariableList:G,template:q,templateSelectionTriggered:F,setTemplate:J,setDisplayContent:K,setOriginalVariableList:Q,globalNormalizedPlaceholders:X,enabledCustomText:ee,pod:te}=h();function le(e,t){var l,a,i;const n=e;H(""),$(n),Y===c.WHATSAPP?"custom_text"!==n.value&&"custom_link"!==n.value?(ae(null!==(l=n.value)&&void 0!==l?l:"","string"),null==ie||ie(null!==(a=y.index)&&void 0!==a?a:0,n.value,!0)):(null==ie||ie(null!==(i=y.index)&&void 0!==i?i:0,y.variableName,!0,"custom_text"),ae("","url"===n.bikPlaceholderType?"link":"string")):"custom_text"!==n.value&&"custom_link"!==n.value?ae(n.value,"url"===n.bikPlaceholderType?"link":"string"):(H(""),ae("",n.value))}function ae(e,t){var l,a,i,n;const o="custom_link"===t?"link":"custom_text"===t?"string":t;if(Y!==c.WHATSAPP){const a=x(T+1),i=null===document||void 0===document?void 0:document.getElementById("mobile"===z?"template_html_mobile":"template_html_desktop"),n=Y===c.EMAIL?null===(l=null==i?void 0:i.contentWindow)||void 0===l?void 0:l.document.getElementById(a):document.getElementById(a);n&&(n.textContent="custom_text"!==t&&"custom_link"!==t||e?e:y.variableName);const s=G.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t));null==Q||Q(s)}if(Y===c.WHATSAPP){const l=G;let s=l.body,u=l.header,d=l.buttons;"BODY"===E?s=null===(a=l.body)||void 0===a?void 0:a.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"HEADER"===E?u=null===(i=l.header)||void 0===i?void 0:i.map(((t,l)=>l===T?Object.assign(Object.assign({},t),{type:o,updatedValue:e}):t)):"BUTTONS"===E&&(d=null===(n=l.buttons)||void 0===n?void 0:n.map(((l,a)=>a===T?Object.assign(Object.assign({},l),{buttonVariable:"custom_link"===t?"((customPlaceholderName))":e,example:[e]}):l))),null==Q||Q((e=>Object.assign(Object.assign({},e),{header:u,body:s,buttons:d})))}}function ie(e,t,l,a){var i,n,o,s;const u=Object.assign({},q),d=null===(i=null==u?void 0:u.components)||void 0===i?void 0:i.map((l=>{var a,i,n,o,s,u,d,r,c,p;const m=Object.assign({},l);if("BODY"===l.type&&"BODY"===E){if(null===(i=null===(a=l.example)||void 0===a?void 0:a.body_text)||void 0===i?void 0:i[0]){const l=[...null!==(s=null===(o=null===(n=m.example)||void 0===n?void 0:n.body_text)||void 0===o?void 0:o[0])&&void 0!==s?s:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{body_text:[l]});return Object.assign(Object.assign({},m),{example:a})}}else if("HEADER"===l.type&&"HEADER"===E){if(null===(u=l.example)||void 0===u?void 0:u.header_text){const l=[...null!==(r=null===(d=m.example)||void 0===d?void 0:d.header_text)&&void 0!==r?r:[]];l[e]=t.replace("{{","").replace("}}","").replace("((","").replace("))","");const a=Object.assign(Object.assign({},m.example),{header_text:l});return Object.assign(Object.assign({},m),{example:a})}}else if("BUTTONS"===l.type&&"BUTTONS"===E&&(null===(p=null===(c=l.buttons)||void 0===c?void 0:c[e])||void 0===p?void 0:p.example)){const a=l.buttons.map(((l,a)=>a===e?Object.assign(Object.assign({},l),{example:[t]}):l));return Object.assign(Object.assign({},m),{buttons:a})}return l}));u.components=d,l&&("BODY"===E&&(null===(n=null==u?void 0:u.mapping)||void 0===n?void 0:n.body)?u.mapping=Object.assign(Object.assign({},u.mapping),{body:u.mapping.body.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+10}))`:t:l))}):"HEADER"===E&&(null===(o=null==u?void 0:u.mapping)||void 0===o?void 0:o.header)?u.mapping=Object.assign(Object.assign({},u.mapping),{header:u.mapping.header.map(((l,i)=>e===i?"custom_text"===a?`((editableVariable${i+20}))`:t:l))}):"BUTTONS"===E&&(null===(s=null==u?void 0:u.mapping)||void 0===s?void 0:s.buttons)&&(u.mapping=Object.assign(Object.assign({},u.mapping),{buttons:u.mapping.buttons.map(((e,l)=>0===l?"custom_link"===a?"((customPlaceholderName))":t:e))}))),null==J||J(Object.assign({},u))}return i((()=>{C&&(null==f||f())}),[C]),i((()=>{!function(){var e,t,l,a,i;const n="mobile"===z?"template_html_mobile":"template_html_desktop",o=document.getElementById(n),s=(null!==(a=null===(l=null===(t=null===(e=null==o?void 0:o.contentWindow)||void 0===e?void 0:e.document)||void 0===t?void 0:t.body)||void 0===l?void 0:l.innerHTML)&&void 0!==a?a:"")+(null===(i=null==o?void 0:o.contentWindow)||void 0===i?void 0:i.document.head.innerHTML);Y===c.EMAIL&&(null==K||K(s))}()}),[F]),i((()=>{var e;const t=[];let l=[];if(Y!==c.MESSAGE||ee){"link"===(null==y?void 0:y.type)?(t.push({label:"",options:[O,_]}),$(O)):(t.push({label:"",options:[O,_]}),$(_));const e=null!=X?X:[];M([...t,...e.map((e=>{var t,l;return Object.assign(Object.assign({},e),{label:b.toCapitilize(null===(l=null===(t=e.label)||void 0===t?void 0:t.replace(/([A-Z])/g," $1"))||void 0===l?void 0:l.toLowerCase())})}))]),l=[...t,...e]}else{const e=null!=X?X:[];M([{label:"",options:[_,O]},...e]),l=[{label:"",options:[_,O]},...e]}if((Y===c.WHATSAPP||Y===c.EMAIL||Y===c.MESSAGE)&&y.updatedValue)if(r.test(y.updatedValue)&&Y===c.WHATSAPP||y.updatedValue.startsWith("{{")&&Y!==c.WHATSAPP){const e=function(e,t,l){var a;let i={label:"",value:""};const n=l===c.WHATSAPP?e.updatedValue.replace("[[","").replace("]]",""):e.updatedValue.replace("{{","").replace("}}","");if(k){let t=e.updatedValue;if(te===p.CHATBOT&&"BUTTONS"===E){const l=null==S?void 0:S.filter((t=>t.placeHolder===e.updatedValue));l&&l.length>0&&(t=l[0].label)}i={label:t?t.replace("{{","").replace("}}","").trim().replace("."," "):"",value:null!==(a=e.updatedValue)&&void 0!==a?a:""}}else t.map((e=>{e.options.map((e=>{var t;(null===(t=e.value)||void 0===t?void 0:t.replace("{{","").replace("}}","").trim())===n.trim()&&(i=e)}))}));return i}(y,l,Y);e.value&&$(e)}else(null===(e=y.updatedValue)||void 0===e?void 0:e.startsWith("https"))?($(O),H(y.updatedValue.split("https://")[1])):($(_),H(y.updatedValue))}),[]),i((()=>{z&&W&&L&&setTimeout((()=>{ae("custom_link"===(null==W?void 0:W.value)&&L?L.includes("https")?L:`https://${L}`:L,W.value)}),100)}),[z]),i((()=>{!R&&W&&y.updatedValue&&setTimeout((()=>{ae("custom_link"===(null==W?void 0:W.value)&&y.updatedValue?y.updatedValue.includes("https")?y.updatedValue:`https://${y.updatedValue}`:y.updatedValue,W.value),U(!0)}),100)}),[W]),e(j,Object.assign({channel:Y,focused:C,onMouseEnter:()=>B(!0),onMouseLeave:()=>B(!1)},{children:[t("div",Object.assign({style:{marginBottom:8}},{children:e(m,Object.assign({style:{color:Z&&!W?g.content.negative:g.content.primary}},{children:[null===(P=y.variableName)||void 0===P?void 0:P.replace("{{","").replace("}}","")," ","link"===(null==y?void 0:y.type)?"link":"variable"]}))})),t("div",Object.assign({style:{marginBottom:12}},{children:k?e("div",Object.assign({style:{display:"flex",border:"#E0E0E0 1px solid",borderRadius:4,padding:10,justifyContent:(null==W?void 0:W.label)?"space-between":"flex-end"}},{children:[t(v,{children:d(null!==(w=null==W?void 0:W.label)&&void 0!==w?w:"",20,!0)}),t(l,{onClick:()=>{I(!D)},width:24,height:24,color:g.content.primary})]})):t(s,{options:N,isSearchable:!1,onSelect:le,defaultOptions:W?[Object.assign(Object.assign({},W),{selected:!0})]:[]})})),("custom_text"===(null==W?void 0:W.value)||"custom_link"===(null==W?void 0:W.value))&&t(u,{labelText:"custom_text"===(null==W?void 0:W.value)?"Custom text value":"custom_link"===(null==W?void 0:W.value)?"Custom URL value":"",id:`variable-value-${null==W?void 0:W.value}-${T}`,value:L,errorMessage:Z?L&&0!==L.trim().length?"custom_link"!==W.value||/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/.test(`https://${L.trim()}`)&&0!==L.trim().length?"custom_link"!==W.value&&L.length>30?"Length cannot be more than 30":"":"Enter valid URL":"Required field":"",maxCharLimit:"custom_link"===(null==W?void 0:W.value)?void 0:30,prefixText:"custom_link"===(null==W?void 0:W.value)?"https://":"",placeholder:"link"===y.type||"custom_link"===W.value?"Enter custom URL here":"Enter custom text here",onChangeText:e=>{!function(e,t){var l;H(t);const a="custom_link"===(null==W?void 0:W.value)&&t?t.includes("https")?t:`https://${t}`:t;ae(a,e),Y===c.WHATSAPP&&(null==ie||ie(null!==(l=y.index)&&void 0!==l?l:0,a,"custom_link"===e,e))}(W.value,e)}}),D&&t(o,{zIndex:2e3,data:null!=A?A:[],showVariable:D,setShowVariable:I,placeholder:"Add a variable",customTrigger:e=>{null==V||V(!1),"{{custom.url}}"===e.actualValue?le({label:e.displayName,selected:!0,value:"custom_link"}):"{{custom.text}}"==e.actualValue?le({label:e.displayName,selected:!0,value:"custom_text"}):le({label:e.displayName.replace("{{","").replace("}}","").trim().replace("."," "),selected:!0,value:e.actualValue,bikPlaceholderType:"string"})}})]}))};export{j as Container,f as default};