@hiver/connector-agent 4.11.2-eventChange-beta.0 → 4.11.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFormDefaultValues.d.ts","sourceRoot":"","sources":["../../../../src/features/write-form/api/getFormDefaultValues.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB;IACnE,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAUD,eAAO,MAAM,sBAAsB,yCAIhC,mBAAmB,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBvD,CAAC;AAEF,eAAO,MAAM,yBAAyB,yCAA0C,mBAAmB,0DAOlG,CAAC;AAEF,eAAO,MAAM,4BAA4B,gEAMtC,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"getFormDefaultValues.d.ts","sourceRoot":"","sources":["../../../../src/features/write-form/api/getFormDefaultValues.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB;IACnE,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAUD,eAAO,MAAM,sBAAsB,yCAIhC,mBAAmB,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBvD,CAAC;AAEF,eAAO,MAAM,yBAAyB,yCAA0C,mBAAmB,0DAOlG,CAAC;AAEF,eAAO,MAAM,4BAA4B,gEAMtC,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B1B,CAAC"}
|
package/index.es.js
CHANGED
|
@@ -18690,22 +18690,24 @@ const zI = S(vl)`
|
|
|
18690
18690
|
enabled: r,
|
|
18691
18691
|
fetchOnMount: o = !0
|
|
18692
18692
|
}) => {
|
|
18693
|
-
const i = ve(!0), s =
|
|
18693
|
+
const i = ve(!0), s = ve();
|
|
18694
|
+
e !== s.current && (i.current = !0, s.current = e);
|
|
18695
|
+
const a = dn({
|
|
18694
18696
|
queryKey: Jh({ formId: e, conversationId: t, inboxIds: n }),
|
|
18695
18697
|
queryFn: async () => {
|
|
18696
|
-
const
|
|
18697
|
-
return i.current = !1,
|
|
18698
|
+
const l = await s_({ formId: e, conversationId: t, inboxIds: n });
|
|
18699
|
+
return i.current = !1, l;
|
|
18698
18700
|
},
|
|
18699
18701
|
refetchOnMount: o,
|
|
18700
18702
|
enabled: i.current && !!e && !!t && Yh(n) && r,
|
|
18701
18703
|
staleTime: 0
|
|
18702
|
-
}),
|
|
18703
|
-
if (Object.keys(
|
|
18704
|
-
}, [
|
|
18704
|
+
}), c = be(() => {
|
|
18705
|
+
if (Object.keys(a.data ?? {}).length === 0 && a.isSuccess) return !0;
|
|
18706
|
+
}, [a.data, a.isSuccess]);
|
|
18705
18707
|
return {
|
|
18706
18708
|
enabledRef: i,
|
|
18707
|
-
isNudgeRequired:
|
|
18708
|
-
...
|
|
18709
|
+
isNudgeRequired: c,
|
|
18710
|
+
...a
|
|
18709
18711
|
};
|
|
18710
18712
|
}, a_ = async ({ formId: e, data: t }) => {
|
|
18711
18713
|
try {
|
package/index.umd.js
CHANGED
|
@@ -1377,7 +1377,7 @@ Do you want to continue?`,_v="Select an object to create",Sv="Select an object t
|
|
|
1377
1377
|
height: 20px;
|
|
1378
1378
|
flex-shrink: 0;
|
|
1379
1379
|
}
|
|
1380
|
-
`,Tp=({cardData:e,cardDataApiStatus:t,objectToLink:n,args:r})=>{const o=Qt(),[s,a]=I.useState(!1),[i,c]=I.useState(!0),{id:l="",cardTitle:f="",logoUrl:g}=e||{},y=t===K.LOADING,E=h=>{h.stopPropagation();const p=h.currentTarget.offsetWidth<h.currentTarget.scrollWidth;a(!!p)},m=h=>{var b;o(co({id:n,args:r,isRefresh:!0}));const p=h.target.tagName==="BUTTON"?(b=h.target)==null?void 0:b.firstChild:h.target;p.className&&(p.className=""),setTimeout(()=>p.className="selected",1)};return d.jsxs(cI,{children:[d.jsxs(lI,{direction:"row",justifyContent:"space-between",children:[y?d.jsxs(u.Stack,{gap:"6px",direction:"row",children:[d.jsx(jn,{width:"16px",height:"24px"}),d.jsx(jn,{width:"100px",height:"24px"})]}):d.jsxs(dI,{children:[g&&d.jsx("img",{src:g,alt:f}),d.jsx(u.Tooltip,{title:s?f:"",children:d.jsx(u.Typography,{variant:"h4",onMouseOver:h=>E(h),onMouseLeave:h=>E(h),children:f})})]}),d.jsxs(u.Stack,{direction:"row",alignItems:"center",children:[i?d.jsx(u.Tooltip,{title:Dd,placement:"bottom",children:d.jsx(Ur,{onClick:h=>m(h),children:d.jsx("img",{src:mp})})}):null,d.jsx(u.Tooltip,{title:i?Nd:$i,placement:"bottom",children:d.jsx(Ur,{onClick:()=>c(h=>!h),children:d.jsx(ac,{className:i?"":"hiver-up"})})})]})]}),d.jsx(fp,{id:l,cardTitle:f,specificCardData:{[l]:e},specificConnectorApiStatus:{[l]:t},isOpen:i})]})},Lp={values:{},errors:{}},wt={SET_FIELD_VALUE:"SET_FIELD_VALUE",CLEAR_ERROR:"CLEAR_ERROR",SET_FIELD_ERROR:"SET_FIELD_ERROR",SET_FIELDS:"SET_FIELDS",SET_FORM_DEFAULTS:"SET_FORM_DEFAULTS",CLEAR_FIELDS:"CLEAR_FIELDS",RESET_STATE:"RESET_STATE"},fI=(e,t)=>{const{type:n,payload:r}=t;switch(n){case wt.SET_FIELD_VALUE:{if(!(r!=null&&r.value))return e;const{name:o,value:s}=r.value;return{...e,values:{...e.values,[o]:s}}}case wt.SET_FIELD_ERROR:{if(!(r!=null&&r.value))return e;const{name:o,value:s}=r.value;return typeof s=="boolean"||typeof s=="string"?{...e,errors:{...e.errors,[o]:s}}:e}case wt.CLEAR_ERROR:{if(!(r!=null&&r.value))return e;const{name:o}=r.value;return{...e,errors:{...e.errors,[o]:""}}}case wt.SET_FIELDS:{if(!(r!=null&&r.values))return e;const{values:o}=r;return{...e,values:o}}case wt.SET_FORM_DEFAULTS:{if(!(r!=null&&r.values))return e;const{values:o}=r,s={...e.errors};for(const a in o??{})o[a]&&delete s[a];return{...e,errors:s,values:{...e.values,...o}}}case wt.CLEAR_FIELDS:{const{fieldNames:o}=r??{};if(!Array.isArray(o))return e;const s={...e.values},a={...e.errors};for(const i of o)delete s[i],delete a[i];return{...e,values:s,errors:a}}case wt.RESET_STATE:return Lp}return e},Op=()=>I.useReducer(fI,Lp),Fp=({state:e,dispatch:t,validations:n,dynamicFields:r})=>{const o=e.errors,s=(E,m)=>{t({type:wt.SET_FIELD_VALUE,payload:{value:{value:m,name:E}}})},a=I.useCallback(E=>{t({type:wt.SET_FORM_DEFAULTS,payload:{values:E}})},[t]),i=I.useCallback(()=>Object.keys(o).filter(m=>!!o[m]).length>0,[o]),c=E=>{E.stopPropagation();const{name:m,value:h}=(E==null?void 0:E.target)||{};s(m,h)},l=(E,m)=>{E.stopPropagation();const{name:h}=(E==null?void 0:E.target)||{};s(h,m)},f=(E,m)=>{s(E,m||"")},g=(E,m)=>{e.errors[E]!==m&&t({type:wt.SET_FIELD_ERROR,payload:{value:{name:E,value:m}}})},y=(E,m)=>{if(m){const h=m[E];h==null||h.forEach(p=>{var b;s(p,""),m[p]&&y(p,m),(b=n[p])!=null&&b.isRequired&&g(p,!0)})}};return I.useEffect(()=>{if(Array.isArray(r))return()=>{const E=r.map(m=>m.name);t({type:wt.CLEAR_FIELDS,payload:{fieldNames:E}})}},[r,t]),{setValue:s,setFormDefaults:a,isErrorInValidations:i,inputChangeHandler:c,checkboxChangeHandler:l,dateChangeHandler:f,handleValidationError:g,clearDependentFields:y}},kp=({formFields:e,formId:t,formState:n,appDispatch:r})=>e.reduce((o,s)=>{if(s.type!=="async-select"||!s.interfaceDetails)return o;const a=s.interfaceDetails,i={loadOptions:(c,l,f,g)=>{let y=a;s.searchInterfaceDetails&&typeof c=="string"&&c.trim().length>0&&!f&&(y=s.searchInterfaceDetails);const E=GE(n,y==null?void 0:y.args),m=Object.values((y==null?void 0:y.args)||{});if(E.length===m.length){r(Ir({fieldName:s.name,formId:String(t),searchTerm:c,fieldConfig:s,interfaceId:y==null?void 0:y.id,pagination:y==null?void 0:y.pagination,callback:l,args:{...rs(n,y==null?void 0:y.args),...rs(n,y==null?void 0:y.optionalArgs)},isScrollToBottomEvent:f,controller:g}));return}return l([])}};return{...o,[s.name]:i}},{}),Dp=({formFields:e,formId:t,formState:n,conversationId:r,appDispatch:o})=>e.reduce((s,a)=>{if(!a.createOptionInterfaceDetails)return s;const i=a.createOptionInterfaceDetails;return{...s,[a.name]:{createOption:(c,l)=>{var g,y;if(!c)return;const f={values:{name:a.name,value:c},errors:{}};o(Ra({fieldName:a.name,formId:String(t),interfaceId:i.id,conversationId:r,label:c,callback:l,args:{...rs(n,(g=a==null?void 0:a.interfaceDetails)==null?void 0:g.args),...rs(n,(y=a==null?void 0:a.interfaceDetails)==null?void 0:y.optionalArgs)},createArgs:{...rs(f,i.args)}}))}}}},{}),Np=({formFields:e,formState:t,formId:n,conversationId:r})=>{const o=Qt(),s=I.useMemo(()=>{if(e&&e.length){const i=kp({formFields:e,formId:n,formState:t,appDispatch:o});return e.reduce((l,f)=>{const g=f.columns;if(!g)return l;const y=kp({formFields:g,formId:n,formState:t,appDispatch:o});return{...l,[f.name]:{loadOptionsList:y}}},i)}return null},[e,t,n,o]),a=I.useMemo(()=>{const i=Dp({formFields:e,formId:n,formState:t,conversationId:r,appDispatch:o});return e.reduce((l,f)=>{const g=f.columns;if(!g)return l;const y=Dp({formFields:g,formId:n,formState:t,conversationId:r,appDispatch:o});return{...l,[f.name]:{createOptionList:y}}},i)},[e,n,t,r,o]);return{fetchConfig:s,createConfig:a}},pI=async({formId:e})=>{try{const t=await Ee({url:rt(ep,{formId:e}),method:Oe.GET}),n=t==null?void 0:t.data;return n.enabled?sf(n.defaults):{}}catch(t){throw console.error(t),t}},Rp=({formId:e})=>["Global","WriteForm","FormDefaults",e],hI=({formId:e,enabled:t})=>{const n=I.useRef(!1),r=I.useRef(void 0);e&&e!==r.current&&(n.current=!0,r.current=e);const o=Zt({queryKey:Rp({formId:e}),queryFn:async()=>{const s=await pI({formId:e});return n.current=!1,s},refetchOnMount:!0,enabled:n.current&&t,staleTime:0});return{enabledRef:n,...o}},Mp=e=>Array.isArray(e)&&e.length>0,gI=async({formId:e,conversationId:t,inboxIds:n})=>{try{const r=new URLSearchParams;if(t&&r.set("conversation_id",String(t)),Mp(n))for(const a of n)r.append("inbox_id",String(a));const o=await Ee({url:rt(lv,{formId:e})+"?"+r.toString(),method:Oe.GET}),s=o==null?void 0:o.data;if(!s.enabled)throw new Error("Form default values are not enabled");return sf(s.defaults,!0)}catch(r){throw console.error(r),r}},Pp=({formId:e,conversationId:t,inboxIds:n})=>["Global","WriteForm","FormDefaults",e,t,n],jp=({formId:e,conversationId:t,inboxIds:n,enabled:r,fetchOnMount:o=!0})=>{const s=I.useRef(!0),a=Zt({queryKey:Pp({formId:e,conversationId:t,inboxIds:n}),queryFn:async()=>{const c=await gI({formId:e,conversationId:t,inboxIds:n});return s.current=!1,c},refetchOnMount:o,enabled:s.current&&!!e&&!!t&&Mp(n)&&r,staleTime:0}),i=I.useMemo(()=>{if(Object.keys(a.data??{}).length===0&&a.isSuccess)return!0},[a.data,a.isSuccess]);return{enabledRef:s,isNudgeRequired:i,...a}},mI=async({formId:e,data:t})=>{try{return await Ee({url:rt(ep,{formId:e}),data:{defaults:t},method:Oe.PUT}),{formId:e,data:t}}catch(n){throw console.error(n),n}},bI=({formId:e,conversationId:t,inboxIds:n,onSuccess:r,onError:o})=>{const s=Zr();return Xt({mutationFn:a=>mI({formId:e,data:a}),onSuccess:a=>{s.invalidateQueries({queryKey:Rp({formId:e})}),s.invalidateQueries({queryKey:Pp({formId:e,conversationId:t,inboxIds:n})}),r==null||r(a),Se({message:"Form defaults updated successfully",type:Ut})},onError:()=>{o==null||o(),Se({message:"Failed to update form defaults",type:qe})}})},yI=({open:e,isEdit:t,formId:n,fields:r,connectorLogo:o,variables:s,customFormArgsEnabled:a,customFormArgsMap:i,title:c="Map fields",isLoading:l=!1,onSuccess:f,onClose:g})=>{const[y,E]=I.useState({}),{conversationId:m,currentSmIds:h}=I.useContext(He),{data:p}=w6({formId:n,formData:y,argsMap:i??{},enabled:!!n&&!!a,delay:500}),{data:b,isLoading:x,enabledRef:C}=hI({formId:n,enabled:!t&&!!e&&!!n}),{mutate:w,isPending:v}=bI({formId:n,conversationId:m,inboxIds:h,onSuccess:N=>{C.current=!0,f==null||f(N)}}),_=I.useMemo(()=>p!=null&&p.length?[...r,...p]:r,[r,p]);I.useEffect(()=>{b&&E(b)},[b]);const A=N=>{const D=_.map(M=>({name:M.name,type:M.isMultiSelect?"multi-select":M.type})),k=M6(N,D);w(k)},S=async({args:N,pagination:D},{formId:k,fieldName:M})=>{const B=await $1({formId:k,fieldName:M},{pagination:D,args:N}),Y=Array.isArray(B==null?void 0:B.data.data)?B.data.data:[];return{options:Y,hasMore:!!Y.length}},L=N=>{const D=nf(N.value)?N.value.value:N.value,k=D&&N.type==="multi-select"?[D]:D;E(M=>({...M,[N.name]:k}))};return d.jsx(ME,{open:e,defaultValues:b,formId:n,fields:_,connectorLogo:o,variables:s,title:c,isLoading:l||x,isSaving:v,fetchOptions:S,onSave:A,onClose:()=>g==null?void 0:g(),onCancel:()=>g==null?void 0:g(),onFieldChange:L})},xI=async({formId:e,args:t})=>{try{const n=await Ee({url:rt(cv,{formId:e}),data:{args:t},method:Oe.POST});return(n==null?void 0:n.data).fieldList.map(o=>ll(o))}catch(n){throw console.error(n),n}},CI=({formId:e,args:t,enabled:n,delay:r=500})=>{const[o,s]=I.useState(t);return I.useEffect(()=>{const a=setTimeout(()=>s(t),r);return()=>clearTimeout(a)},[t,r]),Zt({queryKey:["Global","WriteForm","CustomFields",e,o],queryFn:()=>xI({formId:e,args:t}),refetchOnMount:!1,enabled:n})},Bp="connector-agent_auto_fill_nudge",EI=e=>T.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 275 81",fill:"none","aria-hidden":"true",...e},T.createElement("defs",null,T.createElement("filter",{id:"autofillCardShadow",x:"-30%",y:"-30%",width:"160%",height:"160%"},T.createElement("feDropShadow",{dx:0,dy:1,stdDeviation:2,floodColor:"#000",floodOpacity:.08})),T.createElement("linearGradient",{id:"autofillHoneycomb",x1:0,y1:0,x2:1,y2:1,gradientUnits:"objectBoundingBox"},T.createElement("stop",{offset:0,stopColor:"#FFD54F"}),T.createElement("stop",{offset:1,stopColor:"#FFB300"}))),T.createElement("g",{transform:"translate(14 10) rotate(-2.75 44 29)",filter:"url(#autofillCardShadow)"},T.createElement("rect",{width:88,height:56,rx:6,fill:"#fff",stroke:"#EEE",strokeWidth:.75}),T.createElement("circle",{cx:14,cy:6,r:8,fill:"#fff",stroke:"#EEE",strokeWidth:.6}),T.createElement("path",{d:"M10.5 6l2.2 2.5L15.5 4",stroke:"#506DFF",strokeWidth:1.1,strokeLinecap:"round",strokeLinejoin:"round"}),T.createElement("rect",{x:10,y:18,width:68,height:14,rx:7,fill:"#fff",stroke:"#D1D8FA",strokeWidth:.5}),T.createElement("text",{x:14,y:27.5,fill:"#334155",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:5.5,fontWeight:600},"Source field 1"),T.createElement("rect",{x:10,y:36,width:68,height:14,rx:7,fill:"#fff",stroke:"#F5F5F5",strokeWidth:.5}),T.createElement("text",{x:14,y:45.5,fill:"#6F7C90",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:5.5,fontWeight:500},"Source field 2")),T.createElement("path",{d:"M108 40H175",stroke:"#9CA3AF",strokeWidth:.9,strokeDasharray:"3 3",strokeLinecap:"round"}),T.createElement("circle",{cx:142,cy:40,r:9,fill:"#fff",stroke:"#E5E7EB",strokeWidth:.75}),T.createElement("path",{d:"M137.5 40h9M135 40l2.5-2M135 40l2.5 2M149.5 40l-2.5-2M149.5 40l-2.5 2",stroke:"#506DFF",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),T.createElement("g",{transform:"translate(186 18)",filter:"url(#autofillCardShadow)"},T.createElement("rect",{width:72,height:46,rx:5,fill:"#fff",stroke:"#EEE",strokeWidth:.75}),T.createElement("circle",{cx:12,cy:5,r:7,fill:"#fff",stroke:"#EEE",strokeWidth:.6}),T.createElement("circle",{cx:12,cy:5,r:4,fill:"url(#autofillHoneycomb)"}),T.createElement("rect",{x:8,y:16,width:56,height:13,rx:6.5,fill:"#fff",stroke:"#D1D8FA",strokeWidth:.5}),T.createElement("text",{x:12,y:24.5,fill:"#334155",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:5.5,fontWeight:600},"Target field"))),vI=u.styled(u.Stack)`
|
|
1380
|
+
`,Tp=({cardData:e,cardDataApiStatus:t,objectToLink:n,args:r})=>{const o=Qt(),[s,a]=I.useState(!1),[i,c]=I.useState(!0),{id:l="",cardTitle:f="",logoUrl:g}=e||{},y=t===K.LOADING,E=h=>{h.stopPropagation();const p=h.currentTarget.offsetWidth<h.currentTarget.scrollWidth;a(!!p)},m=h=>{var b;o(co({id:n,args:r,isRefresh:!0}));const p=h.target.tagName==="BUTTON"?(b=h.target)==null?void 0:b.firstChild:h.target;p.className&&(p.className=""),setTimeout(()=>p.className="selected",1)};return d.jsxs(cI,{children:[d.jsxs(lI,{direction:"row",justifyContent:"space-between",children:[y?d.jsxs(u.Stack,{gap:"6px",direction:"row",children:[d.jsx(jn,{width:"16px",height:"24px"}),d.jsx(jn,{width:"100px",height:"24px"})]}):d.jsxs(dI,{children:[g&&d.jsx("img",{src:g,alt:f}),d.jsx(u.Tooltip,{title:s?f:"",children:d.jsx(u.Typography,{variant:"h4",onMouseOver:h=>E(h),onMouseLeave:h=>E(h),children:f})})]}),d.jsxs(u.Stack,{direction:"row",alignItems:"center",children:[i?d.jsx(u.Tooltip,{title:Dd,placement:"bottom",children:d.jsx(Ur,{onClick:h=>m(h),children:d.jsx("img",{src:mp})})}):null,d.jsx(u.Tooltip,{title:i?Nd:$i,placement:"bottom",children:d.jsx(Ur,{onClick:()=>c(h=>!h),children:d.jsx(ac,{className:i?"":"hiver-up"})})})]})]}),d.jsx(fp,{id:l,cardTitle:f,specificCardData:{[l]:e},specificConnectorApiStatus:{[l]:t},isOpen:i})]})},Lp={values:{},errors:{}},wt={SET_FIELD_VALUE:"SET_FIELD_VALUE",CLEAR_ERROR:"CLEAR_ERROR",SET_FIELD_ERROR:"SET_FIELD_ERROR",SET_FIELDS:"SET_FIELDS",SET_FORM_DEFAULTS:"SET_FORM_DEFAULTS",CLEAR_FIELDS:"CLEAR_FIELDS",RESET_STATE:"RESET_STATE"},fI=(e,t)=>{const{type:n,payload:r}=t;switch(n){case wt.SET_FIELD_VALUE:{if(!(r!=null&&r.value))return e;const{name:o,value:s}=r.value;return{...e,values:{...e.values,[o]:s}}}case wt.SET_FIELD_ERROR:{if(!(r!=null&&r.value))return e;const{name:o,value:s}=r.value;return typeof s=="boolean"||typeof s=="string"?{...e,errors:{...e.errors,[o]:s}}:e}case wt.CLEAR_ERROR:{if(!(r!=null&&r.value))return e;const{name:o}=r.value;return{...e,errors:{...e.errors,[o]:""}}}case wt.SET_FIELDS:{if(!(r!=null&&r.values))return e;const{values:o}=r;return{...e,values:o}}case wt.SET_FORM_DEFAULTS:{if(!(r!=null&&r.values))return e;const{values:o}=r,s={...e.errors};for(const a in o??{})o[a]&&delete s[a];return{...e,errors:s,values:{...e.values,...o}}}case wt.CLEAR_FIELDS:{const{fieldNames:o}=r??{};if(!Array.isArray(o))return e;const s={...e.values},a={...e.errors};for(const i of o)delete s[i],delete a[i];return{...e,values:s,errors:a}}case wt.RESET_STATE:return Lp}return e},Op=()=>I.useReducer(fI,Lp),Fp=({state:e,dispatch:t,validations:n,dynamicFields:r})=>{const o=e.errors,s=(E,m)=>{t({type:wt.SET_FIELD_VALUE,payload:{value:{value:m,name:E}}})},a=I.useCallback(E=>{t({type:wt.SET_FORM_DEFAULTS,payload:{values:E}})},[t]),i=I.useCallback(()=>Object.keys(o).filter(m=>!!o[m]).length>0,[o]),c=E=>{E.stopPropagation();const{name:m,value:h}=(E==null?void 0:E.target)||{};s(m,h)},l=(E,m)=>{E.stopPropagation();const{name:h}=(E==null?void 0:E.target)||{};s(h,m)},f=(E,m)=>{s(E,m||"")},g=(E,m)=>{e.errors[E]!==m&&t({type:wt.SET_FIELD_ERROR,payload:{value:{name:E,value:m}}})},y=(E,m)=>{if(m){const h=m[E];h==null||h.forEach(p=>{var b;s(p,""),m[p]&&y(p,m),(b=n[p])!=null&&b.isRequired&&g(p,!0)})}};return I.useEffect(()=>{if(Array.isArray(r))return()=>{const E=r.map(m=>m.name);t({type:wt.CLEAR_FIELDS,payload:{fieldNames:E}})}},[r,t]),{setValue:s,setFormDefaults:a,isErrorInValidations:i,inputChangeHandler:c,checkboxChangeHandler:l,dateChangeHandler:f,handleValidationError:g,clearDependentFields:y}},kp=({formFields:e,formId:t,formState:n,appDispatch:r})=>e.reduce((o,s)=>{if(s.type!=="async-select"||!s.interfaceDetails)return o;const a=s.interfaceDetails,i={loadOptions:(c,l,f,g)=>{let y=a;s.searchInterfaceDetails&&typeof c=="string"&&c.trim().length>0&&!f&&(y=s.searchInterfaceDetails);const E=GE(n,y==null?void 0:y.args),m=Object.values((y==null?void 0:y.args)||{});if(E.length===m.length){r(Ir({fieldName:s.name,formId:String(t),searchTerm:c,fieldConfig:s,interfaceId:y==null?void 0:y.id,pagination:y==null?void 0:y.pagination,callback:l,args:{...rs(n,y==null?void 0:y.args),...rs(n,y==null?void 0:y.optionalArgs)},isScrollToBottomEvent:f,controller:g}));return}return l([])}};return{...o,[s.name]:i}},{}),Dp=({formFields:e,formId:t,formState:n,conversationId:r,appDispatch:o})=>e.reduce((s,a)=>{if(!a.createOptionInterfaceDetails)return s;const i=a.createOptionInterfaceDetails;return{...s,[a.name]:{createOption:(c,l)=>{var g,y;if(!c)return;const f={values:{name:a.name,value:c},errors:{}};o(Ra({fieldName:a.name,formId:String(t),interfaceId:i.id,conversationId:r,label:c,callback:l,args:{...rs(n,(g=a==null?void 0:a.interfaceDetails)==null?void 0:g.args),...rs(n,(y=a==null?void 0:a.interfaceDetails)==null?void 0:y.optionalArgs)},createArgs:{...rs(f,i.args)}}))}}}},{}),Np=({formFields:e,formState:t,formId:n,conversationId:r})=>{const o=Qt(),s=I.useMemo(()=>{if(e&&e.length){const i=kp({formFields:e,formId:n,formState:t,appDispatch:o});return e.reduce((l,f)=>{const g=f.columns;if(!g)return l;const y=kp({formFields:g,formId:n,formState:t,appDispatch:o});return{...l,[f.name]:{loadOptionsList:y}}},i)}return null},[e,t,n,o]),a=I.useMemo(()=>{const i=Dp({formFields:e,formId:n,formState:t,conversationId:r,appDispatch:o});return e.reduce((l,f)=>{const g=f.columns;if(!g)return l;const y=Dp({formFields:g,formId:n,formState:t,conversationId:r,appDispatch:o});return{...l,[f.name]:{createOptionList:y}}},i)},[e,n,t,r,o]);return{fetchConfig:s,createConfig:a}},pI=async({formId:e})=>{try{const t=await Ee({url:rt(ep,{formId:e}),method:Oe.GET}),n=t==null?void 0:t.data;return n.enabled?sf(n.defaults):{}}catch(t){throw console.error(t),t}},Rp=({formId:e})=>["Global","WriteForm","FormDefaults",e],hI=({formId:e,enabled:t})=>{const n=I.useRef(!1),r=I.useRef(void 0);e&&e!==r.current&&(n.current=!0,r.current=e);const o=Zt({queryKey:Rp({formId:e}),queryFn:async()=>{const s=await pI({formId:e});return n.current=!1,s},refetchOnMount:!0,enabled:n.current&&t,staleTime:0});return{enabledRef:n,...o}},Mp=e=>Array.isArray(e)&&e.length>0,gI=async({formId:e,conversationId:t,inboxIds:n})=>{try{const r=new URLSearchParams;if(t&&r.set("conversation_id",String(t)),Mp(n))for(const a of n)r.append("inbox_id",String(a));const o=await Ee({url:rt(lv,{formId:e})+"?"+r.toString(),method:Oe.GET}),s=o==null?void 0:o.data;if(!s.enabled)throw new Error("Form default values are not enabled");return sf(s.defaults,!0)}catch(r){throw console.error(r),r}},Pp=({formId:e,conversationId:t,inboxIds:n})=>["Global","WriteForm","FormDefaults",e,t,n],jp=({formId:e,conversationId:t,inboxIds:n,enabled:r,fetchOnMount:o=!0})=>{const s=I.useRef(!0),a=I.useRef();e!==a.current&&(s.current=!0,a.current=e);const i=Zt({queryKey:Pp({formId:e,conversationId:t,inboxIds:n}),queryFn:async()=>{const l=await gI({formId:e,conversationId:t,inboxIds:n});return s.current=!1,l},refetchOnMount:o,enabled:s.current&&!!e&&!!t&&Mp(n)&&r,staleTime:0}),c=I.useMemo(()=>{if(Object.keys(i.data??{}).length===0&&i.isSuccess)return!0},[i.data,i.isSuccess]);return{enabledRef:s,isNudgeRequired:c,...i}},mI=async({formId:e,data:t})=>{try{return await Ee({url:rt(ep,{formId:e}),data:{defaults:t},method:Oe.PUT}),{formId:e,data:t}}catch(n){throw console.error(n),n}},bI=({formId:e,conversationId:t,inboxIds:n,onSuccess:r,onError:o})=>{const s=Zr();return Xt({mutationFn:a=>mI({formId:e,data:a}),onSuccess:a=>{s.invalidateQueries({queryKey:Rp({formId:e})}),s.invalidateQueries({queryKey:Pp({formId:e,conversationId:t,inboxIds:n})}),r==null||r(a),Se({message:"Form defaults updated successfully",type:Ut})},onError:()=>{o==null||o(),Se({message:"Failed to update form defaults",type:qe})}})},yI=({open:e,isEdit:t,formId:n,fields:r,connectorLogo:o,variables:s,customFormArgsEnabled:a,customFormArgsMap:i,title:c="Map fields",isLoading:l=!1,onSuccess:f,onClose:g})=>{const[y,E]=I.useState({}),{conversationId:m,currentSmIds:h}=I.useContext(He),{data:p}=w6({formId:n,formData:y,argsMap:i??{},enabled:!!n&&!!a,delay:500}),{data:b,isLoading:x,enabledRef:C}=hI({formId:n,enabled:!t&&!!e&&!!n}),{mutate:w,isPending:v}=bI({formId:n,conversationId:m,inboxIds:h,onSuccess:N=>{C.current=!0,f==null||f(N)}}),_=I.useMemo(()=>p!=null&&p.length?[...r,...p]:r,[r,p]);I.useEffect(()=>{b&&E(b)},[b]);const A=N=>{const D=_.map(M=>({name:M.name,type:M.isMultiSelect?"multi-select":M.type})),k=M6(N,D);w(k)},S=async({args:N,pagination:D},{formId:k,fieldName:M})=>{const B=await $1({formId:k,fieldName:M},{pagination:D,args:N}),Y=Array.isArray(B==null?void 0:B.data.data)?B.data.data:[];return{options:Y,hasMore:!!Y.length}},L=N=>{const D=nf(N.value)?N.value.value:N.value,k=D&&N.type==="multi-select"?[D]:D;E(M=>({...M,[N.name]:k}))};return d.jsx(ME,{open:e,defaultValues:b,formId:n,fields:_,connectorLogo:o,variables:s,title:c,isLoading:l||x,isSaving:v,fetchOptions:S,onSave:A,onClose:()=>g==null?void 0:g(),onCancel:()=>g==null?void 0:g(),onFieldChange:L})},xI=async({formId:e,args:t})=>{try{const n=await Ee({url:rt(cv,{formId:e}),data:{args:t},method:Oe.POST});return(n==null?void 0:n.data).fieldList.map(o=>ll(o))}catch(n){throw console.error(n),n}},CI=({formId:e,args:t,enabled:n,delay:r=500})=>{const[o,s]=I.useState(t);return I.useEffect(()=>{const a=setTimeout(()=>s(t),r);return()=>clearTimeout(a)},[t,r]),Zt({queryKey:["Global","WriteForm","CustomFields",e,o],queryFn:()=>xI({formId:e,args:t}),refetchOnMount:!1,enabled:n})},Bp="connector-agent_auto_fill_nudge",EI=e=>T.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 275 81",fill:"none","aria-hidden":"true",...e},T.createElement("defs",null,T.createElement("filter",{id:"autofillCardShadow",x:"-30%",y:"-30%",width:"160%",height:"160%"},T.createElement("feDropShadow",{dx:0,dy:1,stdDeviation:2,floodColor:"#000",floodOpacity:.08})),T.createElement("linearGradient",{id:"autofillHoneycomb",x1:0,y1:0,x2:1,y2:1,gradientUnits:"objectBoundingBox"},T.createElement("stop",{offset:0,stopColor:"#FFD54F"}),T.createElement("stop",{offset:1,stopColor:"#FFB300"}))),T.createElement("g",{transform:"translate(14 10) rotate(-2.75 44 29)",filter:"url(#autofillCardShadow)"},T.createElement("rect",{width:88,height:56,rx:6,fill:"#fff",stroke:"#EEE",strokeWidth:.75}),T.createElement("circle",{cx:14,cy:6,r:8,fill:"#fff",stroke:"#EEE",strokeWidth:.6}),T.createElement("path",{d:"M10.5 6l2.2 2.5L15.5 4",stroke:"#506DFF",strokeWidth:1.1,strokeLinecap:"round",strokeLinejoin:"round"}),T.createElement("rect",{x:10,y:18,width:68,height:14,rx:7,fill:"#fff",stroke:"#D1D8FA",strokeWidth:.5}),T.createElement("text",{x:14,y:27.5,fill:"#334155",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:5.5,fontWeight:600},"Source field 1"),T.createElement("rect",{x:10,y:36,width:68,height:14,rx:7,fill:"#fff",stroke:"#F5F5F5",strokeWidth:.5}),T.createElement("text",{x:14,y:45.5,fill:"#6F7C90",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:5.5,fontWeight:500},"Source field 2")),T.createElement("path",{d:"M108 40H175",stroke:"#9CA3AF",strokeWidth:.9,strokeDasharray:"3 3",strokeLinecap:"round"}),T.createElement("circle",{cx:142,cy:40,r:9,fill:"#fff",stroke:"#E5E7EB",strokeWidth:.75}),T.createElement("path",{d:"M137.5 40h9M135 40l2.5-2M135 40l2.5 2M149.5 40l-2.5-2M149.5 40l-2.5 2",stroke:"#506DFF",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),T.createElement("g",{transform:"translate(186 18)",filter:"url(#autofillCardShadow)"},T.createElement("rect",{width:72,height:46,rx:5,fill:"#fff",stroke:"#EEE",strokeWidth:.75}),T.createElement("circle",{cx:12,cy:5,r:7,fill:"#fff",stroke:"#EEE",strokeWidth:.6}),T.createElement("circle",{cx:12,cy:5,r:4,fill:"url(#autofillHoneycomb)"}),T.createElement("rect",{x:8,y:16,width:56,height:13,rx:6.5,fill:"#fff",stroke:"#D1D8FA",strokeWidth:.5}),T.createElement("text",{x:12,y:24.5,fill:"#334155",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:5.5,fontWeight:600},"Target field"))),vI=u.styled(u.Stack)`
|
|
1381
1381
|
gap: 12px;
|
|
1382
1382
|
align-items: stretch;
|
|
1383
1383
|
background-color: #f3f8ff;
|