1import{j as a,A as z}from"./vendor-ui-bootstrap-613dad89.js";import{u as oe,r as c}from"./vendor-react-4c7f50f2.js";import{u as te,$ as re,o as N,U as v,q as ne}from"./main-722823a7.js";import{S as A}from"./SmartInput-37432b19.js";import{i as O}from"./vendor-firebase-7ea6fd91.js";import{C as ie}from"./CRUDComponent-503de448.js";import{S as le}from"./StrUtil-dc9607e5.js";/* empty css *//* empty css */import{E as q}from"./Entidades.Service-1ce6eeb3.js";import{f as B}from"./vendor-utils-de6b936e.js";import"./vendor-ui-material-b69ee68f.js";/* empty css */import"./KeysUtil-aee16e59.js";import"./BusySpinner-44ad2170.js";import"./portaisUtil-9f3a950e.js";/* empty css */const de=W=>{for(var i="0123456789",R=7,m="",t=0;t<=R;t++){var h=Math.floor(Math.random()*i.length);m+=i.substring(h,h+1)}return m};function Se(){const{signup:W,currentUser:i,domainDetails:R}=te();let m=oe();const[t,h]=c.useState(re(i)),[p,b]=c.useState(void 0),[M,$]=c.useState(!1),u=c.useRef([]),[y,_]=c.useState([]),[j,k]=c.useState({row:null,col:null}),d=new URLSearchParams(window.location.search),[g,l]=c.useState(""),[H,J]=c.useState(!1),D=200,T=201,I=202,L=203,G=204,S=()=>E(D),w=()=>E(T),P=()=>E(I),V=()=>E(L),Y=()=>E(G),E=e=>i&&i.rulesOwned?i.rulesOwned.includes(e):!1;c.useEffect(()=>{i.uid&&!M&&($(!0),i.rulesOwned.includes(D)||i.rulesOwned.includes(T)||i.rulesOwned.includes(I)||i.rulesOwned.includes(L)||i.rulesOwned.includes(G)?(K(),Q()):m("/unauthorized"))},[i]),c.useEffect(()=>{y.length>0&&p&&u.current.length>0&&(console.log("Marcando checkboxes com userGroupsToCheck=",y),setTimeout(()=>{let e=document.getElementsByClassName("chkUsersGroup");console.log("Total de checkboxes encontrados:",e.length);for(let s=0;s<e.length;s++)if(e[s]){let[r,o]=e[s].value.split(";");y.forEach(n=>{n.portalID===r&&n.groupsOwned.includes(o)&&(e[s].checked=!0,console.log("Checkbox marcado - Federação:",r,"Grupo:",o))})}},100))},[y,p,u.current]);const K=()=>{console.log("loadFederacoes called!!!"),q.getAllActiveByTipoEntidade("Confederação").then(e=>{q.getAllActiveByTipoEntidade("Federação").then(s=>{s&&(u.current=[...e,...s],p===void 0&&N.getAll().then(r=>{r&&b(r)}).catch(r=>{console.log(r),l(r.message)}))}).catch(s=>{console.log(s),l(s.message)})}).catch(e=>{console.log(e),l(e.message)})};function Q(){if(!w())return!1;d.get("id")!==void 0?d.get("id")&&w()?X():N.getAll().then(e=>{e&&b(e)}).catch(e=>{l(e.message)}):N.getAll().then(e=>{e&&b(e)}).catch(e=>{l(e.message)})}function X(){if(!w())return!1;N.getAll().then(e=>{e&&b(e),v.getOne(d.get("id")).then(s=>{var r,o,n,x,f,C;console.log("retData=",s),s&&(J(!0),h({...s,metadados:{...s.metadados,creation:(o=(r=s.metadados)==null?void 0:r.creation)!=null&&o.toDate?B(s.metadados.creation.toDate(),"dd/MM/yyyy 'à s' hh:mm:ss"):((n=s.metadados)==null?void 0:n.creation)||"",date:(f=(x=s.metadados)==null?void 0:x.date)!=null&&f.toDate?B(s.metadados.date.toDate(),"dd/MM/yyyy 'à s' hh:mm:ss"):((C=s.metadados)==null?void 0:C.date)||""}}),s.usersgroupsowned&&Array.isArray(s.usersgroupsowned)&&(console.log("Grupos do usuário carregados:",s.usersgroupsowned),_(s.usersgroupsowned)))}).catch(s=>{console.log(s),l(s.message)})}).catch(e=>{console.log(e),l(e.message)})}function Z(){if(!S()&&!P()||!F())return!1;let e=[];try{u.current.forEach(n=>{e.push({portalID:n.id,groupsOwned:[]})});let o=document.getElementsByClassName("chkUsersGroup");for(var s=0;s<o.length;++s)o[s]!==void 0&&(o[s].checked?e=e.map(n=>{if(n!==void 0){let x=o[s].value.split(";")[0],f=o[s].value.split(";")[1];n.portalID===x&&n.groupsOwned.push(f)}return n}):e=e.map(n=>{if(n!==void 0){let x=o[s].value.split(";")[0],f=o[s].value.split(";")[1];if(n.portalID===x&&n.groupsOwned.includes(f)){let C=n.groupsOwned.indexOf(f);n.groupsOwned=n.groupsOwned.slice(C,1)}}return n}));console.log("groupsMember=",e)}catch(o){console.log("saveData() => Error:",o)}let r={...t,dadosPessoais:{...t.dadosPessoais,name:t.dadosPessoais.name.trim(),searchableName:ne(t.dadosPessoais.name)},metadados:{...t.metadados,ownerid:i.uid,owner:i.displayName,creation:t.metadados.creation===void 0?O.fromDate(new Date):O.fromDate(new Date(t.metadados.creation)),date:O.fromDate(new Date),version:t.metadados.version+1},usersgroupsowned:[...e]};d.get("id")?v.update(d.get("id"),r).then(()=>{m("/sie/administracao/users")}).catch(o=>{l(o.message)}):v.checkIfEmailExists(t.dadosContato.email).then(o=>{if(o)return l("Já existe um usuário com este e-mail. Informe outro e-mail."),!1;v.create(r).then(()=>{m("/sie/administracao/users")}).catch(n=>{console.log(n),l(n.message)})}).catch(o=>{console.log(o),l(o.message)})}function ee(){d&&d.get("id")&&v.delete(d.get("id")).then(()=>{m("/usersgroups")}).catch(e=>{l(e.message)})}function F(){if(t.metadados.protected&&t.dadosContato.email!==i.email)return l("Usuário protegido. Não é possÃvel alterar as permissões deste usuário."),!1;if(t.dadosPessoais.name.length>0)return l(""),!0;{let e=[];return t.dadosPessoais.name.length===0&&(e[e.length]="nome do usuário"),l(le("Para concluir este cadastro, informe: ",e)),!1}}const se=e=>{h(s=>({...s,metadados:{...s.metadados,active:e.target.checked}}))},U=e=>{const{id:s,value:r}=e.target;switch(s){case"email":case"celular":h(o=>({...o,dadosContato:{...o.dadosContato,[s]:r}}));break;default:h(o=>({...o,dadosPessoais:{...o.dadosPessoais,[s]:r}}))}},ae=e=>{if(e.preventDefault(),console.log("handleRedefinirSenha"),d.get("id")){let s=de();v.redefinePassword(d.get("id"),t.dadosContato.email,s).then(()=>{console.log("Senha redefinida com sucesso! Nova senha: "+s),l("Senha redefinida com sucesso! Nova senha: "+s)}).catch(r=>{l(r.message)})}};return i===null?a.jsx("div",{children:"Carregando..."}):!S()&&!P()&&!w()?a.jsx("div",{children:"Carregando..."}):u.current.length===0?a.jsx("div",{children:"Carregando..."}):p===void 0||p.length===0?a.jsx("div",{children:"Carregando..."}):a.jsx(a.Fragment,{children:a.jsxs(ie,{id:"UsersRegister",dataId:d.get("id"),title:"Criar um usuário",titleEdit:"Editar um usuário",help:d.get("id")?["Para criar um usuário preencha os campos abaixo e clique em [Salvar].","Para excluir um usuário clique em [Excluir]."]:["Para criar um usuário preencha os campos abaixo e clique em [Salvar]."],navPath:[{parent:"Usuários",urlparent:"/sie/administracao/users"}],saveData:Z,deleteData:ee,validateData:F,createdDate:t.metadados.creation,udatedDate:t.metadados.date,owner:t.metadados.owner,saveEnabled:d.get("id")?P():S(),retrieveEnabled:w(),deleteEnabled:V(),stateEnabled:Y(),children:[g&&g.indexOf("sucesso")!==-1&&a.jsxs(z,{variant:"success",className:"d-flex flex-nowrap",children:[a.jsx("span",{className:"material-icons-outlined me-2",children:"check_circle"}),a.jsx("div",{children:g})]}),g&&g.indexOf("sucesso")===-1&&a.jsxs(z,{variant:"danger",className:"d-flex flex-nowrap",children:[a.jsx("span",{className:"material-icons-outlined me-2",children:"error"}),a.jsx("div",{children:g})]}),a.jsxs("div",{className:"form-check form-switch registerState",children:[a.jsx("label",{className:"registerLabel-left text-muted",children:"Situação cadastral:"}),a.jsx("input",{className:"form-check-input",type:"checkbox",role:"switch",id:"chkMetadataActive",onClick:se,checked:t.metadados.active})]}),a.jsx(A,{id:"name",value:t.dadosPessoais.name,onChange:U,type:"text",className:"form-control form-input middlePosition inputBox",placeholder:"Nome do usuário",required:!0,disabled:H,style:{"max-width":"calc(100% - 60px)"}}),a.jsxs("div",{className:"d-inline-flex flex-row flex-nowrap align-middle w-100 gap-2",children:[a.jsx("div",{className:"col w-100",children:a.jsx(A,{id:"email",value:t.dadosContato.email,onChange:U,type:"email",className:"form-control form-input middlePosition inputBox",autoComplete:"email",placeholder:"E-mail (somente leitura - sincronizado do cadastro de pessoa)",required:!0,disabled:!0,readOnly:!0})}),a.jsx("div",{children:a.jsx("button",{id:"btnNovaSenha",type:"button",className:"btn btn-primary p-1 ps-3 pe-3",onClick:ae,children:a.jsxs("div",{className:"d-flex align-middle",children:[a.jsx("span",{className:"material-icons-outlined",style:{fontSize:"1.25em",paddingTop:"2px"},children:"key_off"}),a.jsx("span",{className:"ms-1",style:{fontSize:"1em"},children:"Redefinir senha"})]})})})]}),a.jsx(A,{id:"celular",value:t.dadosContato.celular,onChange:U,type:"phone",className:"form-control form-input middlePosition inputBox",autoComplete:"phone",placeholder:"Celular (somente leitura - sincronizado do cadastro de pessoa)",required:!0,disabled:!0,readOnly:!0}),a.jsx("div",{className:"card mb-2",style:{minWidth:"934px"},children:a.jsxs("div",{className:"table mb-0",children:[a.jsxs("div",{style:{position:"sticky",top:0,zIndex:10,backgroundColor:"#f8f9fa"},children:[a.jsx("div",{className:"card-header py-2",children:"Participa dos seguintes grupos de usuários"}),a.jsxs("div",{className:"d-flex flex-row flex-nowrap border-bottom border-2",style:{padding:0,backgroundColor:"#f8f9fa"},children:[a.jsx("div",{className:"col p-0 ps-2"}),u.current&&u.current.map((e,s)=>a.jsx("div",{className:"border-start border-1",style:{minWidth:"28px",maxWidth:"28px",height:"70px",position:"relative",overflow:"hidden",backgroundColor:j.col===s?"rgba(13, 110, 253, 0.15)":"transparent",transition:"background-color 0.15s ease"},children:a.jsx("div",{style:{position:"absolute",width:"70px",height:"28px",to
1p:"50%",left:"50%",transform:"translate(-50%, -50%) rotate(270deg)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"small",whiteSpace:"nowrap"},children:a.jsx("span",{title:e.data().dadosPessoais.name,children:e.data().dadosPessoais.sigla})})},e.id)),a.jsx("div",{className:"p-0",style:{minWidth:"14px",maxWidth:"14px"}})]})]}),a.jsx("div",{className:"d-flex col col-grow w-100 flex-column",style:{minHeight:"150px",maxHeight:"420px",overflowY:"auto"},onMouseLeave:()=>k({row:null,col:null}),children:p&&p.map((e,s)=>a.jsx(c.Fragment,{children:a.jsxs("div",{className:"d-flex flex-row flex-nowrap border-bottom border-1",style:{backgroundColor:j.row===s?"rgba(13, 110, 253, 0.15)":"transparent",transition:"background-color 0.15s ease"},children:[a.jsx("div",{className:"col p-0 ps-2",onMouseEnter:()=>k({row:s,col:null}),children:a.jsx("label",{className:"ms-2",style:{fontSize:"small"},children:e.data().name})}),u.current&&u.current.map((r,o)=>a.jsx("div",{className:"d-flex justify-content-center align-items-center col-auto border-start border-1 p-0",style:{minWidth:"28px",maxWidth:"28px",backgroundColor:j.row===s||j.col===o?"rgba(13, 110, 253, 0.15)":"transparent",transition:"background-color 0.15s ease"},onMouseEnter:()=>k({row:s,col:o}),children:a.jsx("input",{type:"checkbox","aria-label":r.data().name,className:"chkUsersGroup",value:`${r.id};${e.id}`})},`${r.id}_${e.id}`))]})},`Linha_${e.id}`))})]})})]})})}export{Se as default}; 2//# sourceMappingURL=AddUserPage-cc626f17.js.map
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.