1import{j as e,aE as Q,B as I,cf as le,T as h,s as T,eM as de,d2 as ce,F as S,am as me,o as V,M as F,b as q,r as M,e_ as ue,ae as he,e$ as O,f as K,f0 as N,eE as xe,a2 as be,d3 as pe,bT as ge,a3 as Ce,H as X,E as J,bR as ee,f1 as W,a$ as je,f2 as fe,G as C,eQ as we,b3 as ye,b0 as ve,a9 as Se,e1 as se,f3 as Me,cY as Ie,f4 as Pe,an as _e,a5 as Ae,b2 as Re,n as ke,eh as Te,eR as De,cS as Ee,f5 as Z,cT as G,eS as Oe,a1 as te,eT as Fe}from"./index-6arvOuHO.js";import{u as L}from"./usePermission-CpMGgk24.js";import{a as oe}from"./useRoleQueries-BcdFSwGc.js";import{A as Be}from"./AddCircleOutline-BupnuKrY.js";const Ue=e.jsxs(e.Fragment,{children:[e.jsx(h,{variant:"body-sm",component:"p",sx:{mb:1,fontWeight:600,color:"inherit"},children:"Role access"}),e.jsx(h,{variant:"body-sm",component:"p",sx:{mb:1,color:"inherit"},children:"Admin has access to all pages, can view data, and can change any setting."}),e.jsx(h,{variant:"body-sm",component:"p",sx:{color:"inherit"},children:"Session Manager can work on sessions only. They can open pages needed for session activity, but cannot view data or change any settings."})]}),ne=()=>e.jsx(Q,{title:Ue,placement:"bottom-start",arrow:!0,slotProps:{tooltip:{sx:{maxWidth:320,p:1.5,bgcolor:"colors.system.white",color:"colors.neutral.700",border:"1px solid",borderColor:"colors.neutral.200",boxShadow:3,"& .MuiTooltip-arrow":{color:"colors.system.white","&::before":{border:"1px solid",borderColor:"colors.neutral.200",backgroundColor:"colors.system.white"}}}}},children:e.jsx(I,{component:"span",onMouseDown:s=>s.preventDefault(),onClick:s=>s.stopPropagation(),sx:{display:"inline-flex",alignItems:"center",mr:.5},children:e.jsx(le,{fontSize:"small",sx:{color:"colors.neutral.400",cursor:"pointer"},"aria-label":"About role access"})})}),ze=T(I)(({theme:{palette:s,spacing:n,breakpoints:o,customBorderRadius:r},minwidth:i,width:d})=>({position:"fixed",top:"50%",left:"50%",maxHeight:"90vh",transform:"translate(-50%, -50%)",minWidth:i||"30vw",width:d||"fit-content",background:s.colors.system.white,boxShadow:"1px 2px",padding:n(4),borderRadius:r.lg,overflowY:"auto",scrollbarWidth:"thin",outline:"none",[o.down("sm")]:{position:"relative",maxWidth:"90vw"}})),Le=T(de)(({theme:{palette:s}})=>({color:s.error.main})),qe=T(ce)(({theme:{palette:s,spacing:n,breakpoints:o,customBorderRadius:r}})=>({borderRadius:r.sm,border:"1px solid",borderColor:s.colors.neutral[300],outline:"none",[o.down("md")]:{width:"100%"}})),We=T(I)(({theme:{palette:s,spacing:n,customBorderRadius:o}})=>({padding:n(2),border:"1px solid",borderColor:s.colors.neutral[300],borderRadius:o.sm,background:s.colors.system.white,marginBottom:n(2),boxShadow:"0px 1px 3px 1px #00000026"})),$e=T(S)(({theme:{palette:s,spacing:n,breakpoints:o}})=>({alignItems:"center",justifyContent:"space-between",[o.down("md")]:{justifyContent:"space-between"},[o.down("sm")]:{flexDirection:"column",alignItems:"flex-start"}})),Ne=T(me)(({theme:{palette:s}})=>({position:"absolute",top:-5,left:0})),Ze=({handleClose:s,onMemberSwitch:n,roles:o})=>{const{register:r,handleSubmit:i,control:d,formState:{errors:x},reset:p,setValue:b}=V(),{chatbotId:g,orgId:v}=F(),f=q(),[w,P]=M.useState(!1),y=5,{data:{data:A=[]}={}}=ue(v),{botUsers:c=[]}=he(),a=new Set(c.map(t=>t.user.id)),l=A?.filter(t=>!t.is_org_admin&&!t.is_org_staff&&!a.has(t.user.id)).map(t=>({label:t.user.email,key:t.user.id,value:t.user.email,first_name:t.user.first_name,last_name:t.user.last_name}));let j=o?.data?.map(t=>({label:O(t.role_name),key:t.id,value:t.role_name}));const R=(t,_)=>_?.find(u=>t===u.value),{mutateAsync:D,isPending:k}=K(`bot/bot-user/add/?bot_id=${g}`,[[W]]),B=async t=>{try{const m=R(t?.member,l)?.key,E=R(t?.role,j).key;if(!m||!E){f("Please select a member and a role",{error:!0});return}const z=await D({role:E,user:m,bot:g});f(z),z?.success&&s(),p()}catch{f()}},U=t=>{b("member",t)};return e.jsxs(e.Fragment,{children:[e.jsx(S,{alignItems:"center",justifyContent:"space-between",mb:3,children:e.jsx(h,{variant:"h5-semibold",children:"Add collaborator"})}),e.jsxs("form",{onSubmit:i(B),children:[e.jsxs(S,{flexDirection:"column",gap:2.5,children:[e.jsx(I,{width:"100%",children:e.jsx(N,{id:"member",name:"member",label:"Email",options:l,register:r,errors:x,control:d,multiple:!1,validation:{required:"Email is required"}})}),e.jsx(I,{width:"100%",children:e.jsx(N,{id:"role",name:"role",label:"Role",options:j,register:r,errors:x,control:d,val
1idation:{required:"Role is required"},endAdornment:e.jsx(ne,{})})})]}),e.jsxs(I,{mt:2,children:[e.jsxs(h,{mb:1,variant:"body-semibold",children:[" ","Suggested members:"," "]}),e.jsxs(S,{alignItems:"center",gap:1,children:[l.slice(0,w?l.length:y).map((t,_)=>e.jsx(Q,{title:t.value,placement:"top",children:e.jsx(xe,{label:t?.first_name?t?.first_name:t?.value,onClick:()=>U(t?.value),sx:{borderRadius:pe.xs,cursor:"pointer",backgroundColor:be.colors.neutral[100]}})},_)),l.length>y&&e.jsx(ge,{variant:"body-sm",color:"secondary",sx:{cursor:"pointer"},onClick:()=>{P(!w)},children:w?"Show Less":"Show More"})]})]}),e.jsx(Ce,{sx:{my:2}}),e.jsxs($e,{children:[e.jsxs(h,{color:"primary",sx:{cursor:"pointer",display:"flex",alignItems:"center",gap:.5},onClick:()=>n(!1),variant:"body-sm-medium",children:[e.jsx(Be,{fontSize:"small"})," Add someone new"]}),e.jsxs(S,{alignItems:"center",sx:{width:{xs:"100%",sm:"auto"}},children:[e.jsx(X,{md:!0,type:"button",variant:"outlined",onClick:s,width:"100%",sx:{flex:1,width:{xs:"100%",sm:122}},children:"Discard"}),e.jsx(J,{type:"submit",variant:"contained",md:!0,isPending:k,sx:{flex:1,width:{xs:"100%",sm:122}},startIcon:e.jsx(ee,{}),children:"Add"})]})]})]})]})},Ge=({handleClose:s,onMemberSwitch:n,roles:o})=>{const r=q(),{orgId:i,chatbotId:d}=F(),{register:x,handleSubmit:p,control:b,formState:{errors:g},reset:v}=V(),f=o?.data?.map(c=>({label:O(c.role_name),key:c.id,value:c.role_name})),{mutateAsync:w,isPending:P}=K(`bot/bot-user/add-user-to-org-and-bot/?org_id=${i}`,[[W]]),y=(c,a)=>a?.find(j=>c===j.value),A=async({email:c,first_name:a,last_name:l,role:j})=>{try{const D=y(j,f).key,k=await w({email:c,first_name:a,last_name:l,bots:[{bot_id:d,role_id:D}]});r(k),s(),v()}catch{r()}};return e.jsxs(e.Fragment,{children:[e.jsxs(S,{alignItems:"center",justifyContent:"flex-start",mb:2,sx:{position:"relative"},children:[e.jsx(Ne,{onClick:()=>n(!0),children:e.jsx(je,{})}),e.jsx(h,{variant:"h5-semibold",sx:{flex:1,textAlign:"center"},children:"Add collaborator"})]}),e.jsx(h,{variant:"body-sm",mb:2,sx:{flex:1,textAlign:"center"},children:"An email will be sent to the user with a link to set their password and access the dashboard."}),e.jsxs("form",{onSubmit:p(A),children:[e.jsxs(S,{flexDirection:"column",gap:2.5,children:[fe.map(({id:c,component:a,...l})=>e.jsx(I,{width:"100%",children:e.jsx(a,{id:c,register:x,errors:g,control:b,...l})},c)),e.jsx(I,{width:"100%",children:e.jsx(N,{id:"role",name:"role",label:"Role",options:f,register:x,errors:g,control:b,validation:{required:"Role is required"},endAdornment:e.jsx(ne,{})})})]}),e.jsxs(C,{container:!0,spacing:2,mt:3,children:[e.jsx(C,{size:{xs:6},children:e.jsx(X,{md:!0,type:"button",variant:"outlined",onClick:s,width:"100%",children:"Discard"})}),e.jsx(C,{size:{xs:6},children:e.jsx(J,{md:!0,type:"submit",variant:"contained",width:"100%",isPending:P,startIcon:e.jsx(ee,{}),children:"Add"})})]})]})]})},He=({open:s,handleClose:n})=>{const{chatbotId:o,orgId:r}=F(),[i,d]=M.useState(!0),x=g=>{d(g)},{data:p,isError:b}=oe(o);return b&¬ify(),e.jsx(we,{open:s,onClose:n,children:e.jsxs(ze,{minwidth:"20vw",width:"600px",children:[i&&e.jsx(Ze,{handleClose:n,onMemberSwitch:x,roles:p}),!i&&e.jsx(Ge,{handleClose:n,onMemberSwitch:x,roles:p})]})})},H=({id:s,name:n,handleDeleteClick:o})=>{const r=L("delete_bot_user");return e.jsx(S,{justifyContent:"flex-end",gap:4,children:r&&e.jsx(ye,{onClick:()=>o(s,n),children:e.jsx(Le,{})})})},Ye="data:image/svg+xml,%3csvg%20width='56'%20height='57'%20viewBox='0%200%2056%2057'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cmask%20id='mask0_5649_7127'%20style='mask-type:alpha'%20maskUnits='userSpaceOnUse'%20x='0'%20y='0'%20width='56'%20height='57'%3e%3crect%20y='0.181641'%20width='56'%20height='56'%20fill='%23D9D9D9'/%3e%3c/mask%3e%3cg%20mask='url(%23mask0_5649_7127)'%3e%3cpath%20d='M13.6435%2040.0751C15.6268%2038.5585%2017.8435%2037.3626%2020.2935%2036.4876C22.7435%2035.6126%2025.3102%2035.1751%2027.9935%2035.1751C30.6768%2035.1751%2033.2435%2035.6126%2035.6935%2036.4876C38.1435%2037.3626%2040.3602%2038.5585%2042.3435%2040.0751C43.7046%2038.4807%2044.7643%2036.6724%2045.5227%2034.6501C46.281%2032.6279%2046.6602%2030.4696%2046.6602%2028.1751C46.6602%2023.0029%2044.8421%2018.5987%2041.206%2014.9626C37.5699
1%2011.3265%2033.1657%209.50846%2027.9935%209.50846C22.8213%209.50846%2018.4171%2011.3265%2014.781%2014.9626C11.1449%2018.5987%209.32682%2023.0029%209.32682%2028.1751C9.32682%2030.4696%209.70599%2032.6279%2010.4643%2034.6501C11.2227%2036.6724%2012.2824%2038.4807%2013.6435%2040.0751ZM27.9935%2030.5085C25.6991%2030.5085%2023.7643%2029.721%2022.1893%2028.146C20.6143%2026.571%2019.8268%2024.6362%2019.8268%2022.3418C19.8268%2020.0474%2020.6143%2018.1126%2022.1893%2016.5376C23.7643%2014.9626%2025.6991%2014.1751%2027.9935%2014.1751C30.2879%2014.1751%2032.2227%2014.9626%2033.7977%2016.5376C35.3727%2018.1126%2036.1602%2020.0474%2036.1602%2022.3418C36.1602%2024.6362%2035.3727%2026.571%2033.7977%2028.146C32.2227%2029.721%2030.2879%2030.5085%2027.9935%2030.5085ZM27.9935%2051.5085C24.7657%2051.5085%2021.7324%2050.896%2018.8935%2049.671C16.0546%2048.446%2013.5852%2046.7835%2011.4852%2044.6835C9.38516%2042.5835%207.72266%2040.114%206.49766%2037.2751C5.27266%2034.4363%204.66016%2031.4029%204.66016%2028.1751C4.66016%2024.9474%205.27266%2021.914%206.49766%2019.0751C7.72266%2016.2362%209.38516%2013.7668%2011.4852%2011.6668C13.5852%209.5668%2016.0546%207.9043%2018.8935%206.6793C21.7324%205.4543%2024.7657%204.8418%2027.9935%204.8418C31.2213%204.8418%2034.2546%205.4543%2037.0935%206.6793C39.9324%207.9043%2042.4018%209.5668%2044.5018%2011.6668C46.6018%2013.7668%2048.2643%2016.2362%2049.4893%2019.0751C50.7143%2021.914%2051.3268%2024.9474%2051.3268%2028.1751C51.3268%2031.4029%2050.7143%2034.4363%2049.4893%2037.2751C48.2643%2040.114%2046.6018%2042.5835%2044.5018%2044.6835C42.4018%2046.7835%2039.9324%2048.446%2037.0935%2049.671C34.2546%2050.896%2031.2213%2051.5085%2027.9935%2051.5085ZM27.9935%2046.8418C30.0546%2046.8418%2031.9991%2046.5404%2033.8268%2045.9376C35.6546%2045.3349%2037.3268%2044.4696%2038.8435%2043.3418C37.3268%2042.214%2035.6546%2041.3488%2033.8268%2040.746C31.9991%2040.1432%2030.0546%2039.8418%2027.9935%2039.8418C25.9324%2039.8418%2023.9879%2040.1432%2022.1602%2040.746C20.3324%2041.3488%2018.6602%2042.214%2017.1435%2043.3418C18.6602%2044.4696%2020.3324%2045.3349%2022.1602%2045.9376C23.9879%2046.5404%2025.9324%2046.8418%2027.9935%2046.8418ZM27.9935%2025.8418C29.0046%2025.8418%2029.8407%2025.5112%2030.5018%2024.8501C31.1629%2024.189%2031.4935%2023.3529%2031.4935%2022.3418C31.4935%2021.3307%2031.1629%2020.4946%2030.5018%2019.8335C29.8407%2019.1724%2029.0046%2018.8418%2027.9935%2018.8418C26.9824%2018.8418%2026.1463%2019.1724%2025.4852%2019.8335C24.8241%2020.4946%2024.4935%2021.3307%2024.4935%2022.3418C24.4935%2023.3529%2024.8241%2024.189%2025.4852%2024.8501C26.1463%2025.5112%2026.9824%2025.8418%2027.9935%2025.8418Z'%20fill='%23FF5722'/%3e%3c/g%3e%3c/svg%3e",Y=({id:s,role:n,data:o})=>{const r=L("update_bot_user"),i=q(),{chatbotId:d}=F(),[x,p]=M.useState(!1),[b,g]=M.useState(null),{mutateAsync:v}=ve("bot/bot-user/update-role/",[[W]],{idInPath:!0}),f=async(a,l)=>{try{const j=await v({id:a,bot_id:d,data:{role:l}});i(j)}catch{i()}},w=a=>{const l=a.target.value;l!==n?.id&&(g(l),p(!0))},P=()=>{b&&f(s,b),y()},y=()=>{p(!1),g(null)},A=O(o?.data?.find(a=>a.id===n?.id)?.role_name)||"Current Role",c=O(o?.data?.find(a=>a.id===b)?.role_name)||"New Role";return e.jsxs(e.Fragment,{children:[e.jsx(qe,{value:n?.id??"",onChange:w,variant:"outlined",size:"small",disabled:!r,children:o?.data?.map(({id:a,role_name:l})=>e.jsx(Se,{value:a,children:O(l)},a))}),x&&e.jsx(se,{openModal:x,handleConfirm:P,handleModalClose:y,type:"update",title:"Change Team Member Role?",subtitle:`Are you sure you want to change this member's role from "${A}" to "${c}"?`,customLogo:Ye})]})},Qe=({users:s})=>s?.map(({member:n,role:o,email:r,action:i},d)=>e.jsx(We,{children:e.jsxs(C,{container:!0,alignItems:"center",rowSpacing:2,children:[e.jsx(C,{size:{xs:4},children:e.jsx(h,{variant:"body-semibold",children:"Member"})}),e.jsx(C,{size:{xs:8},children:n}),e.jsx(C,{size:{xs:4},mt:1,mb:.5,children:e.jsx(h,{variant:"body-semibold",children:"Email"})}),e.jsx(C,{size:{xs:8},children:e.jsx(h,{variant:"body",sx:{overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"},children:r})}),e.jsx(C,{size:{xs:4},children:e.jsx(h,{variant:"body-semibold",children:"Role"})}),e.jsx(C,{size:{xs:8},children:e.jsx(h,{variant:"body-semibold",children:o})}),e.jsx(C,{size:{xs:4},children:e.jsx(h,{variant:"body-semibold",children:"Actions"})}),e.jsx(C,{size:{xs:8},children:i})]})},d)),Ve=({mt:s=0,mb:n=0})=>{const o=q(),[r,i]=M.useState(!1),[d,x]=M.useState(null),{chatbotId:p}
1=F(),[b,g]=M.useState(1),[v,f]=M.useState(5),w=[5,10,25],{data:{data:P=[],meta_data:{total:y=0}={}}={},isError:A}=Me(p,b,v),c=(m,u)=>{i(!0),x({id:m,name:u})},{mutateAsync:a}=Ie("bot/bot-user/remove/",[[W]],{idInPath:!0}),{data:l,isLoading:j,isError:R}=oe(p);R&&o();const D=async()=>{try{const m=d?.id;if(!m){o("Invalid user selected. Please try again.",{error:!0});return}const u=await a({id:m,bot_id:p});o(u),u?.success&&k()}catch{o()}},k=()=>{i(!1),x(null)},B=(m,u)=>{g(u+1)},U=m=>{const u=parseInt(m.target.value,10);f(u),g(1)},t=P?.map(({id:m,user:{first_name:u,last_name:E,profile_icon_url:z,email:re},role:$,is_org_staff:ae,is_org_admin:ie})=>({member:e.jsx(Pe,{first_name:u||"",last_name:E||"",img:z}),email:re,role:$?e.jsx(Y,{id:m,role:$,data:l}):ie?"Admin":ae?"Staff":"User",action:$?e.jsx(H,{id:m,name:u,handleDeleteClick:c}):null})),_=_e();return Ae(_.breakpoints.down("sm")),j?e.jsx(Re,{height:"40vh",children:e.jsx(ke,{})}):e.jsxs(Te,{mt:s,mb:n,children:[t?.length?e.jsxs(e.Fragment,{children:[e.jsx(De,{children:e.jsx(Ee,{columns:Z,data:t,mt:s,mb:n,children:e.jsx(G,{component:"div",count:y,rowsPerPage:v,page:b-1,onPageChange:B,onRowsPerPageChange:U,rowsPerPageOptions:w})})}),e.jsxs(Oe,{children:[e.jsx(Qe,{columns:Z,users:t,dropdown:Y,delete:H,handleDeleteClick:c}),e.jsx(G,{component:"div",count:y,rowsPerPage:v,page:b-1,onPageChange:B,onRowsPerPageChange:U,rowsPerPageOptions:w})]})]}):e.jsx(te,{}),r&&e.jsx(se,{openModal:r,handleConfirm:D,handleModalClose:k,title:"Remove team member?",subtitle:"Are you sure you want to remove this team member? This will permanently delete this user from your team."})]})},ss=()=>{const s=L("add_bot_user"),n=L("view_bot_user"),[o,r]=M.useState(!1),i=()=>r(!0),d=()=>r(!1);return n?e.jsxs(e.Fragment,{children:[e.jsxs(S,{justifyContent:"space-between",mb:3,children:[e.jsx(h,{variant:"h5-semibold",children:"Team Management"}),s&&e.jsx(Fe,{onClick:i,children:"Add Collaborator"})]}),e.jsx(Ve,{}),o&&e.jsx(He,{open:o,handleClose:d})]}):e.jsx(te,{content:"Access Denied"})};export{ss 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.