1 2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1abc5ca0-71ba-56a8-a104-67c99204e0e7")}catch(e){}}(); 3import{A as te,r as se,Q as B,e as Re,f as Ie,g as Ae,h as Oe,i as le,hu as Te,aJ as ke,$ as H,R as e,j8 as O,cC as De,bg as Pe,ax as Ue,j9 as W,a6 as D,Y as R,gC as We,M as Fe,ah as P,ja as J,k as I,d0 as Le,bk as q,s as $,d1 as Me,jb as Be,bw as _e,bx as Ve,c$ as ze,W as Y,x as K,cP as ne,o as re,D as oe,q as ie,I as ce,bh as me,aN as L,bD as de,bT as ue,bU as pe,b0 as fe,C as M,aj as Ge,aT as _,bY as qe,bi as je,bj as He,c9 as $e,ai as Ee,v as Ye,a0 as Ke,cJ as Qe,a$ as Je,aG as Xe}from"./index-Cs-In7Vx.js";import{u as Ze,V as ea}from"./useEnsure2FA-DZrn0S1r.js";import{I as j}from"./InfoRounded-DDD1KJPn.js";import{D as aa}from"./DoneRounded-DPMKgf-4.js";import{F as ta}from"./FlagPermission-Dumh5c7L.js";import{D as sa}from"./Done-CqMP_G1M.js";import{S as la}from"./SearchInput-6k8qtIIx.js";const he=te(se.createElement("path",{d:"M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"})),ge=te(se.createElement("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-8.29 13.29c-.39.39-1.02.39-1.41 0L5.71 12.7a.9959.9959 0 010-1.41c.39-.39 1.02-.39 1.41 0L10 14.17l6.88-6.88c.39-.39 1.02-.39 1.41 0 .39.39.39 1.02 0 1.41l-7.58 7.59z"})),na="[OWNER USERS] GET_USERS",be="[OWNER USERS] SET SEARCH TEXT",ra="[OWNER USERS] SET LOADING",oa="[OWNER USERS] RESET LOADING",ia="[OWNER USERS] OPEN NEW USER DIALOG",ca="[OWNER USERS] CLOSE NEW USER DIALOG",ma="[OWNER USERS] OPEN EDIT USER DIALOG",da="[OWNER USERS] CLOSE EDIT USER DIALOG";function ua(a){return{type:be,searchText:a}}const pa={users:null,userDialog:{type:"new",props:{open:!1},data:null},searchText:"",loading:!1},fa=function(a=pa,t){switch(t.type){case na:return{...a,users:t.payload};case be:return{...a,searchText:t.searchText};case ra:return{...a,loading:!0};case oa:return{...a,loading:!1};case ia:return{...a,userDialog:{type:"new",props:{open:!0},data:null}};case ca:return{...a,userDialog:{type:"new",props:{open:!1},data:null}};case ma:return{...a,userDialog:{type:"edit",props:{open:!0},data:t.data}};case da:return{...a,userDialog:{type:"edit",props:{open:!1},data:null}};default:return a}};async function Ea(a){return(await B.post("/api/v2/owner/user_companies",a)).data}async function ha(a,t){return(await B.put(`/api/v2/owner/user_companies/${a}`,t)).data}async function ga(a){return(await B.delete(`/api/v2/owner/user_companies/${a}`)).data}var F={},X;function ba(){if(X)return F;X=1;var a=Re(),t=Ie();Object.defineProperty(F,"__esModule",{value:!0}),F.default=void 0;var n=t(Ae()),o=a(Oe()),f=(0,o.default)(n.createElement("path",{d:"M12 7V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V9c0-1.1-.9-2-2-2h-8zM6 19H4v-2h2v2zm0-4H4v-2h2v2zm0-4H4V9h2v2zm0-4H4V5h2v2zm4 12H8v-2h2v2zm0-4H8v-2h2v2zm0-4H8V9h2v2zm0-4H8V5h2v2zm9 12h-7v-2h2v-2h-2v-2h2v-2h-2V9h7c.55 0 1 .45 1 1v8c0 .55-.45 1-1 1zm-1-8h-2v2h2v-2zm0 4h-2v2h2v-2z"}),"BusinessRounded");return F.default=f,F}var va=ba();const ve=le(va);var z,Z;function xa(){if(Z)return z;Z=1;var a=Te();function t(n){return typeof n=="number"&&n==a(n)}return z=t,z}var ya=xa();const Na=le(ya),Ca=a=>B.get(a).then(t=>t.data);function V(){const{data:a,error:t,mutate:n,isLoading:o}=ke("/api/v2/owner/user_companies",Ca,{revalidateOnFocus:!1,revalidateOnReconnect:!1,dedupingInterval:3e4});return{data:a,loading:o,error:t,mutate:n}}function Sa(){const{hasModule:a}=H();return e.useCallback(t=>t?.filter(n=>!(!O[n]||O[n].requiredModules?.length>0&&!a(O[n].requiredModules)))||[],[a])}function wa({label:a,name:t,checkPermission:n,permissions:o,addPermission:f,removePermissions:i,modulesRequired:u}){const{hasModule:p}=H(),h=()=>{i([...o||[],t])};if(u?.length>0&&!p(u))return null;const r=n(t);return e.createElement("div",{className:"flex w-full flex-col rounded-8 border border-solid border-gray-200"},e.createElement("div",{className:"flex items-center justify-between space-x-28 rounded-8 py-8 pl-16 pr-12"},e.createElement(De,{component:"legend",className:"text-18 font-bold text-gray-600"},a),e.createElement(Pe,{color:"primary",name:t,checked:r,onChange:m=>{m.target.checked?f(t):h()}})),o?.length>0&&e.createElement(Ue,{in:r},e.createElement("div",{className:"w-full space-y-6 pb-12 pl-16 pr-12"},o.map(m=>e.createElement(ta,{key:m,name:m,label:O[m].label,checked:n(m),onChange:x=>{x.target.checked?f(m):i([m])},modulesRequired:O[m]?.requiredModules})))))}const Ra=e.memo(wa),ee=({length:a,label:t,onClick:n})=>e.createElement(I,{className:"flex items-center space-x-12 py-8 text-16",onClick:n},e.createElement("div",{className:"space-y-1 text-15 text-gray-600"},e.createElement("div",{title:t,className:"max-w-256 truncate font-bold"},t),e.createElement("div",{className:"flex-1 text-left font-light text-gray-500"},e.createElement("strong",null,a)," permissões concedidas")));function xe({user:a,setInForm:t}){const{data:n}=V(),[o,f]=e.useState(null),i=Sa(),u=e.useMemo(()=>[{key:"MANAGER",label:"Gerente",length:i(W.MANAGER).length},{key:"EMPLOYEE",label:"Funcionário",length:i(W.EMPLOYEE).length},{key:"WAITER",label:"Garçom",length:i(W.WAITER).length},{key:"ACCOUNTANT",label:"Contador",length:i(W.ACCOUNTANT).length}].filter(l=>l.length>0),[i]),p=l=>{if(l)if(Na(l)){const b=n.find(w=>w.id===l);b?.companies[0]?.permissions&&t("permissions",i(b?.companies[0]?.permissions))}else t("permissions",i(W[l]));x()},h=l=>{t("permissions",[...a.permissions||[],l])},r=l=>{t("permissions",(a.permissions||[]).filter(b=>l.indexOf(b)===-1))};function m(l){f(l.currentTarget)}function x(){f(null)}const y=a.permissions?.length||0,N=l=>!!a.permissions.find(b=>l===b);if(a.profile==="OWNER")return e.createElement("div",{className:"flex flex-1 flex-col md:overflow-hidden"},e.createElement("div",{className:"px-20 pt-10 text-20 font-bold text-gray-700"},"Permissões"),e.createElement("div",{className:D("flex flex-1 flex-col items-center justify-center space-y-8 py-68 text-gray-300")},e.createElement(aa,{className:"h-88 w-88 fill-current"}),e.createElement("h3",{className:"text-center text-20 font-semibold"},"O proprietário possui todas as permissões")));const s=n?.filter(l=>l.id!==a?.id&&l.profile!=="OWNER");return e.createElement("div",{className:"flex flex-1 flex-col md:overflow-hidden"},e.createElement("div",{className:"px-20 pt-24 text-20 font-bold text-gray-700"},"Permissões"),e.createElement("div",{className:"flex flex-row items-center space-x-20 p-20"},e.createElement("div",{className:"flex-1 rounded-8 border border-solid border-blue-light bg-blue-lightest px-8 py-6 text-center text-16 text-blue-dark"},e.createElement("span",{className:"font-bold"},y," ")," Permissões concedidas"),e.createElement("div",{className:"flex-1"},e.createElement(R,{variant:"outlined",startIcon:e.createElement(We,null),fullWidth:!0,onClick:m}
3,"Copiar Permissões"),e.createElement(Fe,{anchorEl:o,open:!!o,onClose:x,className:"max-h-512",classes:{paper:"border-1 border-solid border-grey-border shadow rounded-8 mt-8 text-gray-600",list:"py-0"},getContentAnchorEl:null,elevation:0,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"}},e.createElement("div",{className:"mb-8 border-0 border-b-1 border-solid border-gray-200 bg-gray-100 px-16 py-16 text-16 font-bold text-gray-700"},"Copiar de um modelo padrão"),u.map(l=>e.createElement(ee,{key:l.key,label:l.label,length:l.length,onClick:()=>p(l.key)})),s.length>0&&e.createElement(e.Fragment,null,e.createElement("div",{className:"my-8 border-0 border-b-1 border-t-1 border-solid border-gray-200 bg-gray-100 px-16 py-16 text-16 font-bold text-gray-700"},"Copiar de outro usuário"),s.map(l=>e.createElement(ee,{key:l.id,label:l.name,length:l?.companies[0]?.permissions?.length||0,onClick:()=>p(l.id)})))))),e.createElement(P,null),e.createElement("div",{className:"flex flex-1 flex-col space-y-16 p-20 md:overflow-auto"},Object.keys(J).map(l=>e.createElement(Ra,{key:l,name:l,label:O[l].label,permissions:J[l],checkPermission:N,addPermission:h,removePermissions:r,modulesRequired:O[l]?.requiredModules}))))}const Ia=ze(a=>({inputBase:{paddingTop:14,paddingBottom:14,paddingRight:14,paddingLeft:2,width:"100%","& input":{borderRadius:4,backgroundColor:a.palette.common.white,padding:4,transition:a.transitions.create(["border-color","box-shadow"]),fontSize:14}},option:{minHeight:"auto",alignItems:"flex-start",padding:12,paddingRight:8,cursor:"pointer",display:"flex"}}));function ye({value:a=[],onChange:t,options:n=[],buttonClass:o,error:f=!1,helperText:i="",placement:u="bottom-start"}){const p=Ia(),[h,r]=e.useState(null),[m,x]=e.useState(""),[y,N]=e.useState(0),s=e.useRef(null),l=E=>{r(E.currentTarget),s.current&&N(s.current.offsetWidth)},b=()=>{r(null),x("")},w=E=>{const U=a.some(A=>A.id===E.id);t(U?a.filter(A=>A.id!==E.id):[...a,E])},T=E=>{E.preventDefault(),E.stopPropagation(),t([])},d=e.useMemo(()=>n.filter(E=>E.label.toLowerCase().includes(m.toLowerCase())),[n,m]),v=!!h,S=v?"company-selector":void 0,k=()=>n.length===a.length&&n.length>0?"Todos estabelecimentos selecionados":a.length>0?`${a.length} estabelecimento${a.length>1?"s":""} selecionado${a.length>1?"s":""}`:"Nenhum estabelecimento selecionado";return e.createElement("div",{className:"relative"},e.createElement("div",{ref:s,className:`${o} ${f?"border-red-500":""}`,onClick:l},e.createElement(Le,null),e.createElement("span",null,k()),e.createElement(q,{tooltip:"Desmarcar Todos",padding:"p-0",onClick:T,color:"default"},e.createElement($,{className:"p-0"}))),f&&i&&e.createElement("div",{className:"text-red-500 mt-4 px-12 text-12"},i),e.createElement(Me,{id:S,open:v,anchorEl:h,placement:u,style:{width:y},className:D("z-9999 mt-8 rounded-8 border-1 border-solid border-grey-border bg-white text-16 shadow")},e.createElement(Be,{onClickAway:b},e.createElement("div",{style:{width:"100%"}},e.createElement("div",{className:"flex items-center space-x-2 pl-5"},e.createElement(_e,null),e.createElement(Ve,{autoFocus:!0,placeholder:"Pesquise o estabelecimento",className:p.inputBase,value:m,onChange:E=>x(E.target.value)})),e.createElement(P,null),e.createElement("div",{className:"max-h-320 overflow-auto"},d.length===0?e.createElement("div",{className:"p-16 text-center text-gray-500"},"Estabelecimento não encontrado"):d.map(E=>{const U=a.some(A=>A.id===E.id);return e.createElement("div",{key:E.id,className:D(p.option,"hover:bg-gray-50"),onClick:()=>w(E)},e.createElement(sa,{className:"ml-2 mr-6 h-20 flex-shrink-0 opacity-60",style:{visibility:U?"visible":"hidden"}}),e.createElement("div",{title:E.label,className:"flex-grow truncate text-15"},E.label))}))))))}function Aa({open:a,onClose:t,user:n}){const o=Y(),[f,i]=e.useState(!1),[u,p]=e.useState({}),h=K(({auth:d})=>d.user.user.companies),{form:r,handleChange:m,setForm:x,setInForm:y}=ne({id:"",name:"",email:"",phone:"",profile:"",companies:[],permissions:[]}),{mutate:N}=V(),s=re("(max-width:600px)");e.useEffect(()=>{a&&n&&(x({id:n.id,name:n.name||"",email:n.email||"",phone:n.phone||"",profile:n.profile||"EMPLOYEE",companies:n.companies?.map(d=>d.id)||[],permissions:n?.companies[0]?.permissions||[]}),p({}))},[a,n,x]);const l=d=>{const{name:v}=d.target;u[v]&&p(S=>({...S,[v]:""})),m(d)},b=()=>{const d=h.map(S=>S.id);h.every(S=>r.companies.includes(S.id))?y("companies",[]):y("companies",d),u.companies&&p({...u,companies:""})},w=e.useCallback(d=>{const v={},{companies:S,permissions:k,profile:E}=d;if(!S.length){o.warning("Selecione pelo menos um estabelecimento");return}if(!k?.length&&E!=="OWNER"){o.warning("à necessário ao menos uma permissão selecionada");return}return Object.keys(v).length?(p(v),!1):!0},[o]),T=e.useCallback(async()=>
3{if(!(!w(r)||f))try{i(!0);const d={companies:r.companies,permissions:r.permissions,profile:r.profile};await ha(r.id,d),o.success("Usuário atualizado com sucesso"),await N(),t()}catch(d){o.error(d?.response?.data?.message||"Não foi possÃvel atualizar os acessos do usuário")}finally{i(!1)}},[r,w,f,o,N,t]);return e.createElement(oe,{open:a,onClose:()=>!f&&t(),PaperProps:{className:s?"":"shadow-md rounded-12"},disableEnforceFocus:!0,disableRestoreFocus:!0,maxWidth:"lg",fullScreen:s,fullWidth:!0},e.createElement(ie,null,e.createElement("div",{className:"flex items-center justify-between"},e.createElement("span",null,"Editar usuário"),e.createElement(ce,{onClick:t,disabled:f,size:"small"},e.createElement($,null)))),e.createElement(P,null),e.createElement("div",{className:"flex flex-col divide-x-0 divide-y-1 divide-solid divide-gray-200 overflow-auto sm:flex-row sm:overflow-hidden md:flex-row md:divide-x-1 md:divide-y-0"},e.createElement("div",{className:"flex flex-1 flex-col space-y-28 p-20 sm:overflow-auto"},e.createElement("div",{className:"space-y-24"},e.createElement("div",{className:"flex items-center space-x-12 text-16 font-bold text-gray-500"},e.createElement(me,null)," ",e.createElement("span",null,"Informações do usuário")),e.createElement("div",{className:"flex w-full items-center rounded-8 border border-orange-light bg-orange-lightest p-12"},e.createElement(j,{className:"mr-8 text-orange-dark",fontSize:"small"}),e.createElement("span",{className:"text-14 text-orange-dark"},"As informações pessoais só podem ser editadas pelo próprio usuário.")),e.createElement("div",{className:"space-y-20"},e.createElement(L,{name:"email",label:"E-mail",value:r.email,variant:"outlined",fullWidth:!0,disabled:!0}),e.createElement(L,{name:"name",label:"Nome",value:r.name,variant:"outlined",fullWidth:!0,disabled:!0}))),e.createElement("div",{className:"space-y-24"},e.createElement("div",{className:"flex items-center space-x-12 text-16 font-bold text-gray-500"},e.createElement(ve,null)," ",e.createElement("span",null,"Acesso aos estabelecimentos")),e.createElement(de,{variant:"outlined",fullWidth:!0,required:!0},e.createElement(ue,{id:"profile-label"},"Cargo"),e.createElement(pe,{labelId:"profile-label",name:"profile",value:r.profile,onChange:l,label:"Cargo"},e.createElement(I,{value:"MANAGER"},"Gerente"),e.createElement(I,{value:"EMPLOYEE"},"Funcionário"),e.createElement(I,{value:"WAITER"},"Garçom"),e.createElement(I,{value:"ACCOUNTANT"},"Contador"))),e.createElement("div",{className:"space-y-20"},e.createElement("div",{className:"flex items-center space-x-24"},e.createElement("div",{className:"flex-1"},e.createElement(R,{variant:"outlined",startIcon:h.length>0&&h.every(d=>r.companies.includes(d.id))?e.createElement(ge,null):e.createElement(he,null),className:"text-gray-700",fullWidth:!0,onClick:b},"Selecionar todos estabelecimentos"))),e.createElement(ye,{buttonClass:"flex items-center justify-between w-full py-12 px-16 space-x-8 font-medium text-gray-600 border border-gray-300 border-solid cursor-pointer hover:bg-gray-50 bg-white text-16 rounded-4",value:r.companies.map(d=>({id:d,label:h.find(v=>v.id===d)?.name||"Desconhecido"})),onChange:d=>{y("companies",d.map(v=>v.id)),u.companies&&p({...u,companies:""})},options:h.map(d=>({id:d.id,label:d.name})),error:!!u.companies,helperText:u.companies,placement:"bottom-start"})))),e.createElement(xe,{user:r,setInForm:y})),e.createElement(P,null),e.createElement(fe,{className:"space-x-12 px-20 py-16"},e.createElement(R,{onClick:t,disabled:f,color:"primary",variant:"outlined"},"Cancelar"),e.createElement(R,{onClick:T,color:"primary",variant:"contained",disabled:f,startIcon:f&&e.createElement(M,{size:20})},"Salvar")),f&&e.createElement("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-white bg-opacity-70"},e.createElement(M,null)))}const G={OWNER:{color:"green",name:"PROPRIETÃRIO"},MANAGER:{color:"blue",name:"GERENTE"},EMPLOYEE:{color:"indigo",name:"FUNCIONÃRIO"},WAITER:{color:"orange",name:"GARÃOM"},ACCOUNTANT:{color:"purple",name:"CONTADOR"}},Oa=a=>{if(a.profile==="OWNER")return"Todas";if(!a.companies||!a.companies.length)return 0;const t=new Set;
3return a.companies.forEach(n=>{n.permissions&&Array.isArray(n.permissions)&&n.permissions.forEach(o=>{t.add(o)})}),t.size};function Ta(){const a=Y(),t=Ge(),{data:n,loading:o,mutate:f}=V(),i=K(({ownerUsers:s})=>s.searchText),[u,p]=e.useState(null),[h,r]=e.useState(!1),[m,x]=e.useState(null);e.useEffect(()=>{if(n)if(i){const s=_(i.toLowerCase());p(n.filter(l=>_(l.name?.toLowerCase()||"").includes(s)||l.email&&_(l.email.toLowerCase()).includes(s)||l.phone&&_(l.phone.toLowerCase()).includes(s)))}else p(n);else p(null)},[i,n]);const y=e.useCallback(s=>{x(s),r(!0)},[]),N=e.useCallback(async s=>{try{await t({title:"Deseja remover o acesso do usuário?",description:"Esta ação não poderá ser desfeita",cancellationText:"Cancelar",confirmationText:"Confirmar"});try{await ga(s),await f(),a.success("Usuário removido com sucesso")}catch{}}catch{}},[a,t,f]);return e.createElement(e.Fragment,null,e.createElement(qe,{data:u,loading:o,loadingRowsQuantity:5,order:"asc",stickyHeader:!0,columns:[{Header:"Nome",accessor:"name",sortable:!1,className:"font-bold min-w-128"},{Header:"E-mail",accessor:"email",sortable:!1,className:"min-w-128"},{Header:"Cargo",accessor:"profile",sortable:!1,className:"min-w-128",Cell:({row:s})=>{const l=s.profile||"EMPLOYEE";return G[l]?e.createElement(je,{color:G[l].color},G[l].name):l}},{Header:"Permissões",accessor:"permissions",sortable:!1,className:"min-w-128",Cell:({row:s})=>Oa(s)},{Header:"Estabelecimentos",accessor:"companies",sortable:!1,className:"min-w-128 max-w-256",Cell:({row:s})=>s.profile==="OWNER"?"Todas":e.createElement("div",{className:"line-clamp-2 min-w-128 max-w-320",title:s.companies.map(l=>l.name).join(", ")},s.companies.map(l=>l.name).join(", "))},{Header:"",sortable:!1,Cell:({row:s})=>e.createElement("div",{className:"flex items-center justify-end space-x-8"},e.createElement(q,{tooltip:"Editar usuário",onClick:()=>y(s)},e.createElement(He,null)),e.createElement(q,{tooltip:"Excluir usuário",onClick:()=>N(s.id)},e.createElement($e,null)))}]}),e.createElement(Aa,{open:h,onClose:()=>{r(!1),x(null)},user:m}))}const ka=localStorage.getItem("active_company_id"),ae={name:"",email:"",phone:"",profile:"",companies:[parseInt(ka)],permissions:[]};function Da({open:a,onClose:t}){const n=Y(),[o,f]=e.useState(!1),[i,u]=e.useState({isValidating:!1,isValid:!1,userFound:!1,isBlocked:!1}),[p,h]=e.useState(!1),[r,m]=e.useState({}),[x,y]=e.useState(!1),N=K(({auth:c})=>c.user.user.companies),{form:s,handleChange:l,setForm:b,setInForm:w}=ne(ae),{mutate:T}=V(),d=re("(max-width:600px)"),v=e.useMemo(()=>Ee(async c=>{if(!c||!/\S+@\S+\.\S+/.test(c)){u({isValidating:!1,isValid:!1,userFound:!1,isBlocked:!1});return}try{u(C=>({...C,isValidating:!0}));const g=await B.get(`/api/v2/owner/user_companies/search_by_email?email=${encodeURIComponent(c)}`);g.data&&g.data.id?(b(C=>({...C,name:g.data.name})),u({isValidating:!1,isValid:!0,userFound:!0,isBlocked:!1})):(b(C=>({...C,name:""})),u({isValidating:!1,isValid:!0,userFound:!1,isBlocked:!1}))}catch(g){b(C=>({...C,name:""})),g.response&&g.response.status===403?(u({isValidating:!1,isValid:!1,userFound:!1,isBlocked:!0}),y(!0)):u({isValidating:!1,isValid:!0,userFound:!1,isBlocked:!1})}},500),[b]);e.useEffect(()=>(s.email?(u(c=>({...c,isValid:!1})),y(!1),v(s.email)):(u({isValidating:!1,isValid:!1,userFound:!1,isBlocked:!1}),y(!1)),()=>{v.cancel()}),[s.email,v]),e.useEffect(()=>{a&&(b(ae),m({}),u({isValidating:!1,isValid:!1,userFound:!1,isBlocked:!1}),h(!1),y(!1))},[a,b]);const S=c=>{const{name:g}=c.target;r[g]&&m(C=>({...C,[g]:""})),l(c)},k=()=>{if(!s.email||!/\S+@\S+\.\S+/.test(s.email)){m({...r,email:"E-mail inválido"});return}h(!0)},E=c=>{c.key==="Enter"&&!p&&i.isValid&&!i.isBlocked&&s.email&&k()},U=()=>{const c=N.map(C=>C.id);N.every(C=>s.companies.includes(C.id))?w("companies",[]):w("companies",c),r.companies&&m({...r,companies:""})},A=e.useCallback(c=>{const g={},{name:C,email:Q,companies:Ce,permissions:Se,profile:we}=c;if(C.trim()||(g.name="Nome é obrigatório"),Q.trim()?/\S+@\S+\.\S+/.test(Q)||(g.email="E-mail inválido"):g.email="E-mail é obrigatório",!Ce.length){n.warning("Selecione pelo menos um estabelecimento");return}if(!Se?.length&&we!=="OWNER"){n.warning("à necessário ao menos uma permissão selecionada");return}return Object.keys(g).length?(m(g),!1):!0},[n]),Ne=e.useCallback(async()=>
3{if(!(!A(s)||o))try{f(!0);const c={name:s.name,email:s.email,phone_number:s.phone,companies:s.companies,permissions:s.permissions};s.profile!==""&&(c.profile=s.profile),await Ea(c),n.success("Usuário convidado com sucesso"),await T(),t()}catch(c){n.error(c?.response?.data?.message||"Não foi possÃvel convidar o usuário")}finally{f(!1)}},[s,A,o,n,T,t]);return e.createElement(oe,{open:a,onClose:()=>!o&&t(),PaperProps:{className:d?"":"shadow-md rounded-12"},disableEnforceFocus:!0,disableRestoreFocus:!0,maxWidth:p?"lg":"xs",fullScreen:p&&d,fullWidth:!0,onKeyPress:E},e.createElement(ie,null,e.createElement("div",{className:"flex items-center justify-between"},e.createElement("span",null,"Adicionar usuário"),e.createElement(ce,{onClick:t,disabled:o,size:"small"},e.createElement($,null)))),e.createElement(P,null),p?e.createElement("div",{className:"flex flex-col divide-x-0 divide-y-1 divide-solid divide-gray-200 overflow-auto sm:flex-row sm:overflow-hidden md:flex-row md:divide-x-1 md:divide-y-0"},e.createElement("div",{className:"flex flex-1 flex-col space-y-24 px-20 pb-20 pt-24 sm:overflow-auto"},e.createElement("div",{className:"space-y-24"},e.createElement("div",{className:"flex items-center space-x-12 text-16 font-bold text-gray-500"},e.createElement(me,null)," ",e.createElement("span",null,"Informações do usuário")),e.createElement("div",{className:D("flex items-center rounded-8 p-12",i?.userFound?"border border-orange-light bg-orange-lightest":"border border-blue-light bg-blue-lightest")},e.createElement(j,{className:D("mr-8",i?.userFound?"text-orange-dark":"text-blue-dark"),fontSize:"small"}),e.createElement("span",{className:D("text-14",i?.userFound?"text-orange-dark":"text-blue-dark")},i?.userFound?"A":"Após a criação, a","s informações pessoais só podem ser editadas pelo próprio usuário.")),e.createElement("div",{className:"space-y-20"},e.createElement(L,{name:"email",label:"E-mail",type:"email",value:s.email,onChange:S,error:!!r.email,helperText:r.email,variant:"outlined",fullWidth:!0,required:!0,disabled:!0}),e.createElement(L,{name:"name",label:"Nome",value:s.name,onChange:S,error:!!r.name,helperText:r.name,variant:"outlined",fullWidth:!0,required:!0,disabled:i.userFound}))),e.createElement("div",{className:"space-y-24"},e.createElement("div",{className:"flex items-center space-x-12 text-16 font-bold text-gray-500"},e.createElement(ve,null)," ",e.createElement("span",null,"Acesso aos estabelecimentos")),!i.userFound&&e.createElement(de,{variant:"outlined",fullWidth:!0,required:!0},e.createElement(ue,{id:"profile-label"},"Cargo"),e.createElement(pe,{labelId:"profile-label",name:"profile",value:s.profile,onChange:S,label:"Cargo"},e.createElement(I,{value:"MANAGER"},"Gerente"),e.createElement(I,{value:"EMPLOYEE"},"Funcionário"),e.createElement(I,{value:"WAITER"},"Garçom"),e.createElement(I,{value:"ACCOUNTANT"},"Contador"))),e.createElement("div",{className:"space-y-20"},e.createElement("div",{className:"flex items-center space-x-24"},e.createElement("div",{className:"flex-1"},e.createElement(R,{variant:"outlined",startIcon:N.length>0&&N.every(c=>s.companies.includes(c.id))?e.createElement(ge,null):e.createElement(he,null),className:"text-gray-700",fullWidth:!0,onClick:U},"Selecionar todos estabelecimentos"))),e.createElement("div",{className:"w-full"},e.createElement(ye,{buttonClass:"flex items-center justify-between w-full py-12 px-16 space-x-8 font-medium text-gray-600 border border-gray-300 border-solid cursor-pointer hover:bg-gray-50 bg-white text-16 rounded-4",value:s.companies.map(c=>({id:c,label:N.find(g=>g.id===c)?.name||"Desconhecido"})),onChange:c=>{w("companies",c.map(g=>g.id)),r.companies&&m({...r,companies:""})},options:N.map(c=>({id:c.id,label:c.name})),error:!!r.companies,helperText:r.companies,placement:"bottom-start"}))))),e.createElement(xe,{user:{...s,id:0},setInForm:w})):e.createElement("div",{className:"flex flex-col space-y-16 p-20"},e.createElement(L,{name:"email",label:"Email do usuário",type:"email",value:s.email,onChange:S,error:!!r.email,helperText:r.email,variant:"outlined",fullWidth:!0,required:!0,autoFocus:!0,InputProps:{endAdornment:i.isValidating&&e.createElement(M,{size:20,color:"inherit"})}}),x&&e.createElement("div",{className:"flex items-center rounded-8 border border-red-light bg-red-lightest p-12"},e.createElement(j,{className:"mr-8 text-red-dark",fontSize:"small"}),e.createElement("span",{className:"text-14 text-red-dark"},"O usuário com esse email não pode ser adicionado."))),e.createElement(P,null),e.createElement(fe,{className:"space-x-12 px-20 py-16"},e.createElement(R,{onClick:p?()=>h(!1):t,disabled:o,color:"primary",variant:"outlined",disableElevation:!0},p?"Voltar":"Cancelar"),!p&&e.createElement("div",{className:"flex items-center"},e.createElement(R,{variant:"contained",color:"primary",onClick:k,disabled:i.isValidating||i.isBlocked||!i.isValid,disableElevation:!0},"Continuar")),p&&e.createElement(R,{onClick:Ne,color:"primary",variant:"contained",disabled:o,startIcon:o&&e.createElement(M,{size:20}),disableElevation:!0},"Convidar")),o&&e.createElement("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-white bg-opacity-70"},e.createElement(M,null)))}function Pa(){const a=Ye(),t=Ze(),{hasModule:n}=H(),[o,f]=e.useState(""),[i,u]=e.useState(!1),p=e.useMemo(()=>Ee(m=>{a(ua(m))},600),[a]);e.useEffect(()=>p(o),[o,p]);const h=()=>{t(()=>u(!0))},r=()=>{u(!1)};return e.createElement("div",{className:"flex w-full flex-col flex-wrap justify-between space-x-0 space-y-16 sm:flex-row sm:items-center sm:space-x-16 sm:space-y-0"},e.createElement(la,{placeholder:"Pesquise pelo nome ou e-mail do usuário",value:o,onChange:m=>f(m.target.value),className:"flex-1 sm:w-400 sm:flex-grow-0"}),n(Ke.USERS_MANAGEMENT_MODULE)&&e.createElement(R,{variant:"contained",color:"primary",disableElevation:!0,startIcon:e.createElement(Qe,null),onClick:h},"Adicionar usuário"),e.createElement(Da,{open:i,onClose:r}))}function Ua(){return e.createElement(Xe,null,e.createElement(ea,null,e.createElement("div",{className:"flex w-full flex-1 flex-col space-y-24 overflow-auto px-12 py-24 sm:px-28"},e.createElement(Pa,null),e.createElement("div",{className:"sm:flex-1 sm:overflow-auto"},e.createElement(Ta,null)))))}const za=Je("ownerUsers",fa)(Ua);export{za as default}; 4 5//# debugId=1abc5ca0-71ba-56a8-a104-67c99204e0e7
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.