shopify-chatbot-widget 1.0.3 → 1.0.4
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.
|
@@ -937,4 +937,4 @@ html body {
|
|
|
937
937
|
userAgent: `).concat(navigator.userAgent,`
|
|
938
938
|
timeBetweenLoadAndGet: `).concat(o-a,`
|
|
939
939
|
visitorId: `).concat(f.visitorId,`
|
|
940
|
-
components: `).concat(Kj(u),"\n```")),[2,f]}})})}}}function ioe(){if(!(window.__fpjs_d_m||Math.random()>=.001))try{var e=new XMLHttpRequest;e.open("get","https://m1.openfpcdn.io/fingerprintjs/v".concat(Oj,"/npm-monitoring"),!0),e.send()}catch(t){console.error(t)}}function ooe(e){var t;return e===void 0&&(e={}),rc(this,void 0,void 0,function(){var a,r,o;return ic(this,function(u){switch(u.label){case 0:return(!((t=e.monitoring)!==null&&t!==void 0)||t)&&ioe(),a=e.delayFallback,r=e.debug,[4,aoe(a)];case 1:return u.sent(),o=Kie({cache:{},debug:r}),[2,roe(o,r)]}})})}var loe={load:ooe,hashComponents:Zj,componentsToDebugString:Kj};const soe=()=>({checkOut:async t=>{try{const a=localStorage.getItem("company_username");if(!a)throw new Error("No company username found.");const r=await fetch(`${oi.apiUrl}checkout/shopify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,company_username:a})});if(!r.ok)throw new Error("Failed to initiate checkout.");const o=await r.json();o?.checkoutUrl?window.parent?.postMessage({type:"JAWEB_CHAT",action:"navigate",target:"_blank",url:o.checkoutUrl},"*"):alert("No checkout URL returned.")}catch(a){console.error("Checkout error:",a)}}}),coe=({colorCode:e,setOpen:t,Opened:a,onBack:r,sessionId:o})=>{const{items:u,loading:f,removeFromCart:m,refresh:g}=Ej(o||""),{checkOut:p}=soe(),[v,x]=S.useState(!1),E=N=>{if(!N)return{symbol:"",value:0};const _=N.match(/[^0-9.,\s]+/),j=_?_[0]:"",L=parseFloat(N.replace(/[^0-9.]/g,""));return{symbol:j,value:isNaN(L)?0:L}},O=S.useMemo(()=>u.length?u.reduce((N,_)=>{const{value:j}=E(_.price);return N+j*_.quantity},0):0,[u]),T=async()=>{if(!o){of.warning("No session found — please start a chat first.");return}x(!0);try{await p(o)}catch(N){of.error("Checkout failed. Please try again."),console.error("Checkout error:",N)}finally{x(!1)}},M=K.jsx(Ho,{style:{fontSize:24,color:e||"#7F28F8"},spin:!0}),R=async N=>{await m(N,1),of.info("Item removed from cart"),await g()};return K.jsxs("div",{style:{maxWidth:"100%",height:"100%",border:"1px solid #f0f0f0",borderRadius:8,display:"flex",flexDirection:"column",backgroundColor:"#fff",overflow:"hidden"},children:[K.jsxs("div",{style:{padding:"16px",display:"flex",alignItems:"center",borderBottom:"1px solid #f5f5f5",boxShadow:"0 2px 6px rgba(0,0,0,0.03)",zIndex:5,height:"8%"},children:[K.jsx(zr,{type:"text",icon:K.jsx(Gd,{}),onClick:r,style:{color:"#333",fontWeight:500},children:"Back"}),K.jsx("div",{style:{marginLeft:"auto"},children:K.jsx(Vd,{onClick:()=>t(!a),style:{fontSize:18,cursor:"pointer",color:"#555",transition:"color 0.2s ease"},onMouseEnter:N=>N.currentTarget.style.color=e||"#7F28F8",onMouseLeave:N=>N.currentTarget.style.color="#555"})})]}),K.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px",height:"66%"},children:[K.jsxs("h3",{style:{fontWeight:600,marginBottom:16},children:[K.jsx(a5,{style:{marginRight:8}}),"Your Cart (",u.length,")"]}),f?K.jsx("div",{style:{textAlign:"center",marginTop:40},children:K.jsx(tc,{indicator:M})}):u.length===0?K.jsx("div",{style:{textAlign:"center",color:"#888",marginTop:60},children:"Your cart is empty 🛒"}):K.jsx("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",height:"80%",gap:"12px",paddingRight:"4px"},children:u.map(N=>{const{symbol:_,value:j}=E(N.price),L=j*N.quantity;return K.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",background:"#fafafa",borderRadius:10,padding:"12px 10px",transition:"all 0.2s ease"},className:"hover:shadow-sm",children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[K.jsx("img",{src:N.variantImage,alt:N.name,style:{width:64,height:64,borderRadius:8,objectFit:"cover",backgroundColor:"#f3f3f3"}}),K.jsxs("div",{children:[K.jsx("p",{style:{fontWeight:600,color:"#222",marginBottom:4},children:N.name}),K.jsxs("p",{style:{fontSize:13,color:"#777",margin:0},children:["Qty: ",N.quantity]})]})]}),K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[K.jsxs("span",{style:{fontWeight:600},children:[_,L.toLocaleString()]}),K.jsx(Z$,{onClick:()=>R(N.variantId),style:{cursor:"pointer",color:"#999",fontSize:16,transition:"color 0.2s ease"},onMouseEnter:z=>z.currentTarget.style.color="#e74c3c",onMouseLeave:z=>z.currentTarget.style.color="#999"})]})]},N.variantId)})})]}),K.jsxs("div",{style:{position:"sticky",bottom:0,left:0,right:0,background:"#fff",borderTop:"1px solid #f0f0f0",padding:"16px 20px",boxShadow:"0 -3px 10px rgba(0,0,0,0.05)",zIndex:10},children:[K.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"10px",fontWeight:600,color:"#222"},children:[K.jsx("span",{children:"Subtotal:"}),K.jsx("span",{children:O.toLocaleString()})]}),K.jsx(zr,{type:"primary",block:!0,size:"large",onClick:T,loading:v,disabled:u.length===0,style:{backgroundColor:e||"black",borderColor:e||"black",borderRadius:10,fontWeight:600},children:K.jsx("span",{style:{color:"white"},children:"CHECKOUT"})})]})]})},uoe=()=>{const[e,t]=S.useState(!
|
|
940
|
+
components: `).concat(Kj(u),"\n```")),[2,f]}})})}}}function ioe(){if(!(window.__fpjs_d_m||Math.random()>=.001))try{var e=new XMLHttpRequest;e.open("get","https://m1.openfpcdn.io/fingerprintjs/v".concat(Oj,"/npm-monitoring"),!0),e.send()}catch(t){console.error(t)}}function ooe(e){var t;return e===void 0&&(e={}),rc(this,void 0,void 0,function(){var a,r,o;return ic(this,function(u){switch(u.label){case 0:return(!((t=e.monitoring)!==null&&t!==void 0)||t)&&ioe(),a=e.delayFallback,r=e.debug,[4,aoe(a)];case 1:return u.sent(),o=Kie({cache:{},debug:r}),[2,roe(o,r)]}})})}var loe={load:ooe,hashComponents:Zj,componentsToDebugString:Kj};const soe=()=>({checkOut:async t=>{try{const a=localStorage.getItem("company_username");if(!a)throw new Error("No company username found.");const r=await fetch(`${oi.apiUrl}checkout/shopify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,company_username:a})});if(!r.ok)throw new Error("Failed to initiate checkout.");const o=await r.json();o?.checkoutUrl?window.parent?.postMessage({type:"JAWEB_CHAT",action:"navigate",target:"_blank",url:o.checkoutUrl},"*"):alert("No checkout URL returned.")}catch(a){console.error("Checkout error:",a)}}}),coe=({colorCode:e,setOpen:t,Opened:a,onBack:r,sessionId:o})=>{const{items:u,loading:f,removeFromCart:m,refresh:g}=Ej(o||""),{checkOut:p}=soe(),[v,x]=S.useState(!1),E=N=>{if(!N)return{symbol:"",value:0};const _=N.match(/[^0-9.,\s]+/),j=_?_[0]:"",L=parseFloat(N.replace(/[^0-9.]/g,""));return{symbol:j,value:isNaN(L)?0:L}},O=S.useMemo(()=>u.length?u.reduce((N,_)=>{const{value:j}=E(_.price);return N+j*_.quantity},0):0,[u]),T=async()=>{if(!o){of.warning("No session found — please start a chat first.");return}x(!0);try{await p(o)}catch(N){of.error("Checkout failed. Please try again."),console.error("Checkout error:",N)}finally{x(!1)}},M=K.jsx(Ho,{style:{fontSize:24,color:e||"#7F28F8"},spin:!0}),R=async N=>{await m(N,1),of.info("Item removed from cart"),await g()};return K.jsxs("div",{style:{maxWidth:"100%",height:"100%",border:"1px solid #f0f0f0",borderRadius:8,display:"flex",flexDirection:"column",backgroundColor:"#fff",overflow:"hidden"},children:[K.jsxs("div",{style:{padding:"16px",display:"flex",alignItems:"center",borderBottom:"1px solid #f5f5f5",boxShadow:"0 2px 6px rgba(0,0,0,0.03)",zIndex:5,height:"8%"},children:[K.jsx(zr,{type:"text",icon:K.jsx(Gd,{}),onClick:r,style:{color:"#333",fontWeight:500},children:"Back"}),K.jsx("div",{style:{marginLeft:"auto"},children:K.jsx(Vd,{onClick:()=>t(!a),style:{fontSize:18,cursor:"pointer",color:"#555",transition:"color 0.2s ease"},onMouseEnter:N=>N.currentTarget.style.color=e||"#7F28F8",onMouseLeave:N=>N.currentTarget.style.color="#555"})})]}),K.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px",height:"66%"},children:[K.jsxs("h3",{style:{fontWeight:600,marginBottom:16},children:[K.jsx(a5,{style:{marginRight:8}}),"Your Cart (",u.length,")"]}),f?K.jsx("div",{style:{textAlign:"center",marginTop:40},children:K.jsx(tc,{indicator:M})}):u.length===0?K.jsx("div",{style:{textAlign:"center",color:"#888",marginTop:60},children:"Your cart is empty 🛒"}):K.jsx("div",{style:{flex:1,overflowY:"auto",display:"flex",flexDirection:"column",height:"80%",gap:"12px",paddingRight:"4px"},children:u.map(N=>{const{symbol:_,value:j}=E(N.price),L=j*N.quantity;return K.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",background:"#fafafa",borderRadius:10,padding:"12px 10px",transition:"all 0.2s ease"},className:"hover:shadow-sm",children:[K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[K.jsx("img",{src:N.variantImage,alt:N.name,style:{width:64,height:64,borderRadius:8,objectFit:"cover",backgroundColor:"#f3f3f3"}}),K.jsxs("div",{children:[K.jsx("p",{style:{fontWeight:600,color:"#222",marginBottom:4},children:N.name}),K.jsxs("p",{style:{fontSize:13,color:"#777",margin:0},children:["Qty: ",N.quantity]})]})]}),K.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[K.jsxs("span",{style:{fontWeight:600},children:[_,L.toLocaleString()]}),K.jsx(Z$,{onClick:()=>R(N.variantId),style:{cursor:"pointer",color:"#999",fontSize:16,transition:"color 0.2s ease"},onMouseEnter:z=>z.currentTarget.style.color="#e74c3c",onMouseLeave:z=>z.currentTarget.style.color="#999"})]})]},N.variantId)})})]}),K.jsxs("div",{style:{position:"sticky",bottom:0,left:0,right:0,background:"#fff",borderTop:"1px solid #f0f0f0",padding:"16px 20px",boxShadow:"0 -3px 10px rgba(0,0,0,0.05)",zIndex:10},children:[K.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"10px",fontWeight:600,color:"#222"},children:[K.jsx("span",{children:"Subtotal:"}),K.jsx("span",{children:O.toLocaleString()})]}),K.jsx(zr,{type:"primary",block:!0,size:"large",onClick:T,loading:v,disabled:u.length===0,style:{backgroundColor:e||"black",borderColor:e||"black",borderRadius:10,fontWeight:600},children:K.jsx("span",{style:{color:"white"},children:"CHECKOUT"})})]})]})},uoe=()=>{const[e,t]=S.useState(!1),[a,r]=S.useState("sessions"),[o,u]=S.useState(null),[f,m]=S.useState(!1),[g,p]=S.useState(""),[v,x]=S.useState(""),[E,O]=S.useState(!1),{chatbotLogo:T,colorCode:M,messagesSuggestions:R,disableForm:N,merchantPhone:_,userType:j,isFetchingDetails:L,calendly:z,disbleCheckout:V,chatbotName:B,setMessagesSuggestions:D}=s7(),[P,H]=S.useState(null),Z=K.jsx(Ho,{style:{fontSize:24,color:M||"#7F28F8"},spin:!0}),X=()=>{if(N&&!f){r("create");return}else{const U=crypto.randomUUID();u(U),x(T),p(B),O(!0),r("messenger")}};S.useEffect(()=>{(async()=>{try{let G=localStorage.getItem("visitor_id");G||(G=(await(await loe.load()).get()).visitorId,localStorage.setItem("visitor_id",G));const se=await(await fetch(`${oi.apiUrl}register-ip/`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({visitor_id:G})})).json();se.visitor&&se.country?(localStorage.setItem("country",se.country),H({visitorId:se.visitor,country:se.country}),m(se.has_user_info||!1)):console.warn("Backend did not return country")}catch(G){console.error("Failed to fetch or send visitor info",G)}})()},[]);const W=(U,G,J)=>{u(U),p(G),x(J),O(!1),r("messenger")};S.useEffect(()=>{const U=G=>{const J=G.data||{};if(J.type==="JAWEB_CHAT")switch(J.action){case"open-ready":t(!0);break;case"closed":t(!1);break;case"start-session":console.log("[Chatbot] start-session message received"),X();break}};return window.addEventListener("message",U),()=>window.removeEventListener("message",U)},[]);const Q=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"open"},"*")},oe=()=>{window.parent?.postMessage({type:"JAWEB_CHAT",action:"close"},"*")};return S.useEffect(()=>{L||window.parent?.postMessage({type:"JAWEB_CHAT",action:"ready-confirm"},"*")},[L]),K.jsx("div",{children:e&&K.jsx("div",{className:"chatbot-box",children:L?K.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:K.jsx(tc,{indicator:Z,tip:"..."})}):K.jsxs(z2,{mode:"sync",children:[a==="sessions"&&K.jsx(Ti.div,{initial:{opacity:0,x:-30},animate:{opacity:1,x:0},exit:{opacity:0,x:30},transition:{duration:.3},style:{height:"100%"},children:K.jsx(AQ,{chatbotLogo:T,Phone:_||"",colorCode:M,visitorId:P?.visitorId||"",Opened:e,setOpen:U=>U?Q():oe(),onNewSession:X,onSessionSelect:W})},"sessions"),a==="create"&&K.jsx(Ti.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-30},transition:{duration:.3},children:K.jsx(dae,{colorCode:M,visitorId:P?.visitorId||"",country:P?.country||"",onBack:()=>r("sessions"),onCreate:U=>{u(U.session_id),m(U.hasInfo),r("messenger")}})},"create"),a==="cartView"&&K.jsx(Ti.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},exit:{opacity:0,y:-30},transition:{duration:.3},style:{height:"100%"},children:K.jsx(coe,{setOpen:U=>U?Q():oe(),sessionId:o,Opened:e,chatbotLogo:T,colorCode:M,onBack:()=>{O(!1),r("messenger")}})},"create"),a==="messenger"&&o&&K.jsx(Ti.div,{initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},transition:{duration:.3},children:K.jsx(Kae,{sessionId:o,chatbotLogo:v||T,agentName:g||B||"Ai Assistant",colorCode:M,messagesSuggestions:R,newSession:E,disableForm:N,calendly:z??"",setOpen:U=>U?Q():oe(),setNewSession:O,Opened:e,setView:r,userType:j,disbleCheckout:V,setMessagesSuggestions:D})},"messenger")]})})})},Qj="jaweb-chatbot-container";if(!document.getElementById(Qj)){const e=document.createElement("div");e.id=Qj,document.body.appendChild(e),fV.createRoot(e).render(K.jsx(uoe,{}))}})();
|
package/package.json
CHANGED
package/src/Chatbot/Chatbot.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { motion, AnimatePresence } from 'framer-motion';
|
|
|
12
12
|
import CartLayout from './components/Cart/Index';
|
|
13
13
|
|
|
14
14
|
const Chatbot: React.FC = () => {
|
|
15
|
-
const [open, setOpen] = useState(
|
|
15
|
+
const [open, setOpen] = useState(false);
|
|
16
16
|
const [viewMode, setViewMode] = useState<'sessions' | 'create' | 'messenger' | 'cartView' >('sessions');
|
|
17
17
|
const [activeSessionId, setActiveSessionId] = useState<string | null>(null);
|
|
18
18
|
const [HasInfo, setHasInfo] = useState(false);
|
|
@@ -41,7 +41,7 @@ const Chatbot: React.FC = () => {
|
|
|
41
41
|
const handleNewSessionClick = () => {
|
|
42
42
|
// console.log(disableForm)
|
|
43
43
|
// console.log(HasInfo)
|
|
44
|
-
if (
|
|
44
|
+
if (disableForm && !HasInfo) {
|
|
45
45
|
setViewMode('create');
|
|
46
46
|
return;
|
|
47
47
|
} else {
|