PageSourceSearch

https://app.snapto.ai/assets/CreateEditDripCampaign-DQgKEqzY.js

js snapto.ai collected 2026-10-05 15:08:38 UTC 16,099 bytes, 1 lines download raw bytes

1import{D as ee,q as U,r as S,bm as ue,p as e,aj as c,S as b,b1 as me,C as ge,ac as he,bn as fe,x as ye,N as R,L as D,T as V,ag as j,v as z,B as w,a0 as je,a1 as H,af as be,y as J,bj as G}from"./index-C9IH3k-2.js";import{a7 as Ie,a8 as De,as as X,I as Y,J as Se,T as K,Q as Ce,a2 as xe,a4 as Te,a5 as Ee,a6 as ve}from"./TemplateUtil-D1DzmWLm.js";import{A as Fe}from"./AutoSuggestionInputForLabelAndAttributes-CXJJN2fQ.js";import{g as we}from"./HelperMethods-C-ewwU_x.js";import{F as Q}from"./FileUploadComponent-CTRHpuy6.js";import{S as W}from"./DynamicPaymentFields-DAVAs28P.js";import{P as Me}from"./PaymentMessageFields-N0F7aPId.js";import{u as Ae}from"./useTemplateDetails-DA6kn5sZ.js";import"./Wrapper-ChjuDa3w.js";import"./index-Bxup4IDe.js";import"./index-DNqpjC0Z.js";import"./Pagination-D1z-xPUv.js";import"./InboxOutlined-C0X09Vz7.js";import"./index-CmSVNJzc.js";import"./index-Bv3SRNsl.js";import"./CalendarOutlined-DyzsKNdO.js";import"./ClockCircleOutlined-Cym7vptW.js";import"./index-BOwvFOZJ.js";import"./FileImageOutlined-C4CR0Usu.js";import"./VideoCameraOutlined-xB8eoGC4.js";import"./MetaSendMessageConfigs-B3j2uyNp.js";import"./FileAddOutlined-AdYKRQbz.js";const Z=m=>(m||[]).map(I=>({value:I.id,label:I.name})),L={optionFilterProp:"label"},Oe=({interrupt:m})=>{const I=ee(),M=U(h=>h.contactAttributes||[]),T=U(h=>h.contactLabel||[]),E=Z(M),v=Object.values(m||{}).some(h=>h?.length);S.useEffect(()=>{T.length===0&&Ie().then(h=>{h?.data?.results&&I(ue(h.data.results))})},[]);const A=e.jsxs(e.Fragment,{children:[e.jsx(c.Item,{name:["interrupt","skipIfAttributeSet"],label:"Pause while any of these attributes has a value",extra:"Clearing the attribute resumes the drip from the next due message",children:e.jsx(b,{mode:"multiple",allowClear:!0,showSearch:L,options:E,placeholder:"e.g. suppression_status"})}),e.jsx(c.Item,{name:["interrupt","skipIfLabelled"],label:"Pause while the contact has any of these labels",extra:"Removing the label resumes the drip from the next due message",children:e.jsx(b,{mode:"multiple",allowClear:!0,showSearch:L,options:Z(T),placeholder:"Select labels"})}),e.jsx(c.Item,{name:["interrupt","skipIfAttributeChanged"],label:"Stop if any of these attributes changes after the drip starts",extra:"Use this when starting a new drip should retire the previous one, e.g. order_id",children:e.jsx(b,{mode:"multiple",allowClear:!0,showSearch:L,options:E,placeholder:"e.g. order_id"})})]});return e.jsx(me,{bordered:!1,style:{marginTop:16},defaultActiveKey:v?["interrupt"]:[],items:[{key:"interrupt",label:"Pause/Stop condition (optional)",forceRender:!0,children:A}]})},{Text:Re}=V,at=()=>{const[m]=c.useForm(),I=ge(),M=he(),T=ee(),[E,v]=S.useState(!1),[A,h]=S.useState([]),[N,P]=S.useState(!1),[O,te]=S.useState({}),[u,F]=S.useState({}),ae=U(n=>n.contactAttributes||[]),f=M.state?.dripData,x=!!f,{getTemplateDetails:_}=Ae();S.useEffect(()=>{le(),ae.length===0&&De().then(n=>{n?.data?.results&&T(fe(n.data.results))}),x&&f&&se()},[]);const se=async()=>{const n=f.dripItems.map(a=>{const d=a.schedule?.delayInMinutes||0,s=Math.floor(d/1440),i=Math.floor(d%1440/60),p=d%60;let t=a.message?.templateName||"",r=a.message?.language||"en";try{const g=JSON.parse(t);t=g.name,r=g.language||r}catch{}const o={templateName:JSON.stringify({name:t,language:r}),language:r,days:s,hours:i,minutes:p,templateVariables:a.templateVariables||[]};return a.message?.metaMediaId&&(o.metaMediaId=a.message.metaMediaId),a.message?.files&&(o.files=a.message.files),a.message?.products&&(o.products=a.message.products),a.message?.product&&(o.product=a.message.product),a.message?.orderStatus&&(o.orderStatus=a.message.orderStatus),a.message?.orderDetail&&(o.orderDetail=a.message.orderDetail),a.message?.location&&(o.location=a.message.location),o});m.setFieldsValue({name:f.name,dripItems:n,interrupt:f.interrupt});for(let a=0;a<f.dripItems.length;a++){const d=f.dripItems[a];let s=d.message?.templateName||"",i=d.message?.language||"en";try{const p=JSON.parse(s);s=p.name,i=p.language||i}catch{}await re(s,i,a)}},re=async(n,a,d)=>{try{const s=await _(n,a);if(s){const i=X(s),p=s.components;let t=[];if(i==="CAROUSEL")t=p.find(l=>l.type==="CAROUSEL")?.cards.map((l,o)=>{const g=l.components.find(y=>y.type==="HEADER"&&y.format)?.format.toLowerCase()||"file";return{id:o,tabName:g,uploadFile:null}})||[];else{const r=p.find(l=>l.type==="HEADER"&&["IMAGE","VIDEO","DOCUMENT","PRODUCT"].includes(l.format));r&&(t=[{id:0,tabName:r.format.toLowerCase(),uploadFile:null}])}F(r=>({...r,[d]:{previewMessageData:p,fileUpload:t,templateType:i,carouselCatalogData:[]}}))}}catch(s){console.error("Failed to fetch template details for edit:",s)}},le=async()=>{try{P(!0);const n=await ye("/api/v1/messageTemplate/getTemplatesForSendMessage");if(n?.data){const a=n.data.map((d,s)=>({value:JSON.stringify({name:d.name,language:d.language}),label:`${d.name}`,category:d?.category||"",language:d.language}));h(a)}}catch{R.error("Failed to load templates")}
1finally{P(!1)}},oe=async(n,a)=>{try{const{name:d,language:s}=JSON.parse(n),i=await _(d,s);if(i){const p=X(i),t=i.components,r=ve(t)?.length||0;let l=[];if(p==="CAROUSEL")l=t.find(C=>C.type==="CAROUSEL")?.cards.map((C,pe)=>{const ce=C.components.find(B=>B.type==="HEADER"&&B.format)?.format.toLowerCase()||"file";return{id:pe,tabName:ce,uploadFile:null}})||[];else{const y=t.find(C=>C.type==="HEADER"&&["IMAGE","VIDEO","DOCUMENT","PRODUCT"].includes(C.format));y&&(l=[{id:0,tabName:y.format.toLowerCase(),uploadFile:null}])}const g=[...m.getFieldValue("dripItems")||[]];g[a]={...g[a],templateName:n,language:s,templateVariables:Array.from({length:r},()=>({value:"",defaultValue:""})),orderDetail:void 0,orderStatus:void 0,location:void 0,metaMediaId:void 0,files:void 0,products:void 0,product:void 0},m.setFieldsValue({dripItems:g}),F(y=>({...y,[a]:{previewMessageData:t,fileUpload:l,templateType:p,carouselCatalogData:[]}}))}}catch{R.error("Failed to load template details")}},$=(n,a,d,s)=>{const i=`${n}_${a}_${d}`;te({...O,[i]:s})},q=(n,a,d)=>{const s=u[n]||{},i=(s.fileUpload||[]).map((p,t)=>t===a?{...p,uploadFile:d}:p);if(F(p=>({...p,[n]:{...s,fileUpload:i}})),s.templateType==="CAROUSEL"){const p=i.map(t=>({metaMediaId:t.uploadFile?.metaMediaId||""}));m.setFields([{name:["dripItems",n,"files"],value:p}])}else m.setFields([{name:["dripItems",n,"metaMediaId"],value:d?.metaMediaId||""}])},k=(n,a,d)=>{const s=u[n]||{},i=[...s.carouselCatalogData||[]];i[a]=d,F(p=>({...p,[n]:{...s,carouselCatalogData:i}}))},ie=(n,a)=>{switch(u[n]?.templateType){case"ORDER_STATUS":return e.jsxs(e.Fragment,{children:[e.jsx(c.Item,{name:[a,"orderStatus","reference_id"],label:"Reference ID",rules:[{required:!0,message:"Please enter reference ID"}],children:e.jsx(j,{placeholder:"Enter Reference ID"})}),e.jsx(c.Item,{name:[a,"orderStatus","status"],label:"Order Status",rules:[{required:!0,message:"Please select order status"}],children:e.jsx(b,{placeholder:"Select Order Status",options:Ee})}),e.jsx(c.Item,{name:[a,"orderStatus","description"],label:"Description",children:e.jsx(j,{placeholder:"Enter Description (Optional)"})})]});case"ORDER_DETAILS":return e.jsx(Me,{hiddenFields:Te,form:m,hidePreview:!0,fieldPrefix:["dripItems",a]});case"LOCATION":return e.jsxs(e.Fragment,{children:[e.jsx(c.Item,{name:[a,"location","name"],label:"Name",rules:[{required:!0,message:"Please enter name"}],children:e.jsx(j,{placeholder:"Enter Name"})}),e.jsx(c.Item,{name:[a,"location","address"],label:"Address",rules:[{required:!0,message:"Please enter address"}],children:e.jsx(j,{placeholder:"Enter Address"})}),e.jsx(c.Item,{name:[a,"location","latitude"],label:"Latitude",rules:[{required:!0,message:"Please enter latitude"}],children:e.jsx(j,{placeholder:"Enter Latitude"})}),e.jsx(c.Item,{name:[a,"location","longitude"],label:"Longitude",rules:[{required:!0,message:"Please enter longitude"}],children:e.jsx(j,{placeholder:"Enter Longitude"})})]});default:return null}},ne=async n=>{v(!0);try{const a={name:n.name,interrupt:n.interrupt||{},dripItems:n.dripItems.map(s=>{let i=s.templateName,p=s.language||"en";try{const o=JSON.parse(i);i=o.name,p=o.language||p}catch{}const t=(s.days||0)*24*60+(s.hours||0)*60+(s.minutes||0),r=s.templateVariables?.map(o=>{const g={defaultValue:o.defaultValue};return o.value&&o.value.trim()!==""&&(g.value=o.value),g})||[],l={message:{templateName:i,language:p},templateVariables:r,schedule:{delayInMinutes:t}};return s.metaMediaId&&(l.message.metaMediaId=s.metaMediaId),s.files&&Array.isArray(s.files)&&(l.message.files=s.files.map(o=>({metaMediaId:o.metaMediaId||""}))),s.products&&Array.isArray(s.products)&&(l.message.products=s.products),s.product&&(l.message.product=s.product),s.orderStatus&&(l.message.orderStatus=s.orderStatus),s.orderDetail&&(l.message.orderDetail=s.orderDetail),s.location&&(l.message.location=s.location),l})};let d;x?(a.id=f.id,d=await J("/api/v1/whatsapp/drip",a)):d=await J("/api/v1/whatsapp/drip",a),d?.status===200&&(G.success({title:"Success",description:`Drip items ${x?"updated":"created"} successfully`}),I("/DripCampaign"))}catch{G.error({title:"Error",description:`Failed to ${x?"update":"create"} drip items`})}finally{v(!1)}},de=n=>{R.error("Please fill in all required fields correctly")};return e.jsxs(D,{vertical:!0,gap:"large",children:[e.jsx(D,{justify:"space-between",wrap:!0,children:e.jsx(V.Title,{level:4,style:{margin:0},children:"Create Drip"})}),e.jsxs(c,{form:m,layout:"vertical",onFinish:ne,onFinishFailed:de,initialValues:{dripItems:[{days:0,hours:0,minutes:0,templateVariables:[]}]},children:[e.jsxs(Y,{children:[e.jsx(c.Item,{label:"Drip Name",name:"name",rules:[{required:!0,message:"Please enter drip name"}],children:e.jsx(j,{placeholder:"e.g., Customer feedback drip, Onboarding drip",size:"large"})}),e.jsx("div",{style:{textAlign:"center",width:"100%",fontSize:15,marginBottom:8},children:"After Initial Event"}),e.jsx(c.List,{name:"dripItems",children:(n,{add:a,remove:d})=>e.jsxs(e.Fragment,{children:[n.map(({key:s,name:i,...p},t)=>e.jsxs("div",{style:{marginBottom:0,border:"2px dotted blue",padding:"5px",marginTop:t===0?0:20,borderRadius:5},children:[e.jsxs("div",{style:{position:"relative",minHeight:70},children:[e.jsx("div",{style:{position:"absolute",left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center"},children:e.jsxs("svg",{width:"12",height:"65",style:{overflow:"visible"},children:[e.jsx("line",{x1:"6",y1:"0",x2:"6",y2:"60",stroke:"#000000ff",strokeWidth:"2.5"}),e.jsx("path",{d:"M6 65 L1 57 L11 57 Z",fill:"#000000ff"})]})}),e.jsx("div",{style:{position:"absolute",left:"50%",marginLeft:30,display:"flex",alignItems:"center"},children:e.jsx(c.Item,{required:!0,style:{marginBottom:0},label:"Delay from previous item",children:e.jsxs(z.Compact,{children:[e.jsx(c.Item,{...p,name:[i,"days"],noStyle:!0,rules:[{required:!0,message:"Required"}],children:e.jsx(b,{placeholder:"Days",showSearch:!0,style:{width:100},options:Array.from({length:30},(r,l)=>({value:l,label:`${l} day${l!==1?"s":""}`}))})}),e.jsx(c.Item,{...p,name:[i,"hours"],noStyle:!0,rules:[{required:!0,message:"Required"}],children:e.jsx(b,{placeholder:"Hours",showSearch:!0,style:{width:100},options:Array.from({length:24},(r,l)=>({value:l,label:`${l} hr${l!==1?"s":""}`}))})}),e.jsx(c.Item,{...p,name:[i,"minutes"],noStyle:!0,rules:[{required:!0,message:"Required"}],children:e.jsx(b,{placeholder:"Minutes",showSearch:!0,style:{width:100},options:Array.from({length:60},(r,l)=>({value:l,label:`${l} min`}))})})]})})}),e.jsx("div",{style:{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)"},children:n.length>1&&e.jsx(w,{danger:!0,icon:e.jsx(Se,{}),onClick:()=>d(i),children:"Delete"})})]}),e.jsx(Y,{type:"inner",variant:"outlined",children:e.jsxs(je,{gutter:[24,0],children:[e.jsxs(H,{xs:24,lg:16,children:[e.jsx(D,{justify:"space-between",align:"center",style:{marginBottom:16},children:e.jsxs(Re,{strong:!0,style:{fontSize:16},children:["Message ",t+1]})}),e.jsx(c.Item,{...p,name:[i,"templateName"],label:"Select Template",rules:[{required:!0,message:"Please select a template"}],children:e.jsx(b,{loading:N,showSearch:!0,placeholder:"Search and select a template",optionFilterProp:"children",onChange:r=>oe(r,t),options:A,filterOption:(r,l)=>(l?.label??"").toLowerCase().includes(r.toLowerCase()),disabled:N,optionRender:r=>{const{label:l,language:o="en",category:g=""}=r.data;return e.jsxs(D,{gap:"small",align:"center",justify:"space-between",children:[e.jsx(V.Text,{strong:!0,children:l}),e.jsxs(z,{size:4,children:[e.jsx(K,{color:"geekblue",children:o}),e.jsx(K,{color:"cyan",children:we(g)})]})]})}})}),ie(t,i),e.jsx(c.List,{name:[i,"templateVariables"],children:r=>e.jsx(e.Fragment,{children:r.map(({key:l,name:o})=>e.jsxs(D,{justify:"space-between",align:"baseline",children:[e.jsx(c.Item,{name:[o,"value"],label:`Variable [${o+1}]`,style:{width:"48%"},children:e.jsx(Fe,{placeholder:"Enter Value...",value:O[`${t}_${o}_value`]||"",onChange:g=>$(t,o,"value",g.target.value)})}),e.jsx(c.Item,{name:[o,"defaultValue"],label:`Default Value [${o+1}]`,style:{width:"48%"},rules:[{required:!0,message:"Please enter default value"}],children:e.jsx(j,{placeholder:"Enter Value...",value:O[`${t}_${o}_defaultValue`]||"",onChange:g=>$(t,o,"defaultValue",g.target.value)})})]},l))})}
1),u[t]?.fileUpload?.length>0&&e.jsx(e.Fragment,{children:u[t].templateType==="CAROUSEL"?e.jsx(e.Fragment,{children:u[t].fileUpload.map((r,l)=>r.tabName==="product"?e.jsx(c.Item,{label:`${r.tabName} Select ${l+1}`,rules:[{required:!0,message:"Please select product"}],name:[i,"products",l,"productRetailerId"],getValueFromEvent:o=>o.retailer_id,children:e.jsx(W,{onChange:o=>k(t,l,o)})},l):e.jsx(c.Item,{label:`${r.tabName} Upload ${l+1}`,rules:[{required:!0,message:"Please upload file"}],name:[i,"files",l,"metaMediaId"],getValueFromEvent:o=>o?.metaMediaId,children:e.jsx(Q,{fileType:r.tabName,onChange:o=>q(t,l,o),viewType:"list",mediaUse:"OUT",metaMediaIds:m.getFieldValue(["dripItems",t,"files",l,"metaMediaId"])?[m.getFieldValue(["dripItems",t,"files",l,"metaMediaId"])]:[]})},l))}):e.jsx(e.Fragment,{children:u[t].fileUpload[0].tabName==="product"?e.jsx(c.Item,{label:`${u[t].fileUpload[0].tabName} Select`,rules:[{required:!0,message:"Please select product"}],name:[i,"product","productRetailerId"],getValueFromEvent:r=>r.retailer_id,children:e.jsx(W,{onChange:r=>k(t,0,r)})}):e.jsx(c.Item,{label:`${u[t].fileUpload[0].tabName} Upload`,rules:[{required:!0,message:"Please upload file"}],name:[i,"metaMediaId"],getValueFromEvent:r=>r?.metaMediaId,children:e.jsx(Q,{fileType:u[t].fileUpload[0].tabName,onChange:r=>q(t,0,r),viewType:"list",mediaUse:"OUT",metaMediaIds:m.getFieldValue(["dripItems",t,"metaMediaId"])?[m.getFieldValue(["dripItems",t,"metaMediaId"])]:[]})})})})]}),e.jsx(H,{xs:24,lg:8,children:e.jsx(Ce,{type:u[t]?.templateType==="ORDER_DETAILS"?"payment":"template",payload:{isCarouselType:u[t]?.templateType==="CAROUSEL",...u[t]?.templateType!=="ORDER_DETAILS"&&{fileUpload:u[t]?.fileUpload||[]},carouselData:u[t]?.previewMessageData?.find(r=>r.type==="CAROUSEL")?.cards,carouselCatalogData:u[t]?.carouselCatalogData||[],referenceId:m.getFieldValue(["dripItems",t,"orderDetail","reference_id"]),totalAmount:m.getFieldValue(["dripItems",t,"orderDetail","total_amount"]),items:m.getFieldValue(["dripItems",t,"orderDetail","items"]),header:u[t]?.previewMessageData?.find(r=>r.type==="HEADER"&&r.format==="TEXT")?.text,body:u[t]?.previewMessageData?.find(r=>
1r.type==="BODY")?.text,footer:u[t]?.previewMessageData?.find(r=>r.type==="FOOTER")?.text,buttons:u[t]?.previewMessageData?.find(r=>r.type==="BUTTONS")?.buttons}})})]})})]},s)),e.jsx(D,{justify:"center",style:{marginTop:24},children:e.jsx(w,{type:"dashed",onClick:()=>a(),icon:e.jsx(be,{}),size:"large",children:"Add Next Message"})})]})}),e.jsx(Oe,{interrupt:f?.interrupt})]}),e.jsx(xe,{}),e.jsx(c.Item,{children:e.jsxs(D,{justify:"center",gap:"middle",children:[e.jsx(w,{onClick:()=>I("/DripCampaign"),size:"large",children:"Cancel"}),e.jsx(w,{type:"primary",htmlType:"submit",loading:E,size:"large",children:x?"Update Drips":"Create Drips"})]})})]})]})};export{at as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.