dappros/ethora

View on GitHub
client-web/build-prod/static/js/50.57553c55.chunk.js

Summary

Maintainability
A
0 mins
Test Coverage
"use strict";(self.webpackChunkweb_app=self.webpackChunkweb_app||[]).push([[50],{32037:function(e,n,t){t.d(n,{Z:function(){return a}});t(72791);var r=t(80184);function a(){return(0,r.jsx)("div",{className:"noDataImg"})}},27669:function(e,n,t){t.d(n,{Z:function(){return Q}});var r=t(74165),a=t(15861),i=t(70885),l=t(72791),s=t(21680),d=t(19773),o=t(24390),c=t(69963),u=t(9827),h=t(60807),p=t(56650),f=t(50228),x=t(4565),m=t(13811),Z=t(91803),g=t(68439),j=t(63381),v=t(70324),b=t(11210),w=t(32037),C=t(42982),k=t(60788),y=t(40464),N=t(29823),A=t(55705),S=t(59911),I=t(81898),U=t(40508),O=t(39709),_=t(47409),B=t(8440),E=t(39571),T=t(17205),R=t(77248),W=t(63818),K=t(80184);function D(e){var n,t=e.open,r=e.setOpen,a=e.setUsers,s=(0,b.K)((function(e){return e.apps})),d=((0,b.K)((function(e){return e.addAppUsers})),(0,l.useState)(!1)),o=(0,i.Z)(d,2),c=o[0],u=o[1],h=(0,A.TA)({initialValues:{firstName:"",lastName:"",username:"",password:"",appId:null===(n=s[0])||void 0===n?void 0:n._id},validate:function(e){var n={};return e.firstName||(n.firstName="Required"),e.lastName||(n.lastName="Required"),e.username||(n.username="Required"),e.password||(n.password="Required"),n},onSubmit:function(e){var n=e.username,t=e.firstName,i=e.lastName,l=e.password,d=e.appId;u(!0);var o=s.find((function(e){return e._id===d}));_.dd(n,l,t,i,null===o||void 0===o?void 0:o.appToken).then((function(e){a((function(n){return[].concat((0,C.Z)(n),[e.data.user])})),r(!1)}))}});return 0===s.length?(0,K.jsxs)(k.Z,{open:t,onClose:function(){},"aria-labelledby":"responsive-dialog-title",children:[(0,K.jsx)(y.Z,{id:"responsive-dialog-title",children:"There is no apps"}),(0,K.jsx)(B.Z,{children:(0,K.jsx)(E.Z,{children:"You should create app first please!"})}),(0,K.jsx)(R.Z,{children:(0,K.jsx)(T.Z,{disabled:c,variant:"contained",autoFocus:!0,onClick:function(){return r(!1)},children:"Close"})})]}):(0,K.jsx)(k.Z,{onClose:function(){},open:t,children:(0,K.jsxs)(f.Z,{style:{width:"400px"},children:[(0,K.jsxs)(y.Z,{style:{display:"flex",justifyContent:"space-between"},children:["New User",(0,K.jsx)(m.Z,{disabled:c,onClick:function(){return r(!1)},children:(0,K.jsx)(N.Z,{})})]}),(0,K.jsx)(f.Z,{sx:{width:"100%",typography:"body1",padding:1},children:(0,K.jsxs)("form",{onSubmit:h.handleSubmit,children:[(0,K.jsx)(f.Z,{children:(0,K.jsxs)(I.Z,{fullWidth:!0,children:[(0,K.jsx)(U.Z,{variant:"standard",htmlFor:"uncontrolled-native",children:"App"}),(0,K.jsx)(W.Z,{inputProps:{name:"appName",id:"uncontrolled-native"},onChange:function(e){h.setFieldValue("appId",e.target.value)},children:s.map((function(e){return(0,K.jsx)("option",{value:e._id,children:e.appName},e._id)}))})]})}),(0,K.jsxs)(f.Z,{children:[(0,K.jsx)(S.Z,{fullWidth:!0,error:!(!h.touched.firstName||!h.errors.firstName),helperText:h.touched.firstName&&h.errors.firstName?h.errors.firstName:"",margin:"dense",label:"First Name",name:"firstName",variant:"standard",onChange:h.handleChange,onBlur:h.handleBlur,value:h.values.firstName}),(0,K.jsx)(S.Z,{fullWidth:!0,error:!(!h.touched.lastName||!h.errors.lastName),helperText:h.touched.lastName&&h.errors.lastName?h.errors.lastName:"",margin:"dense",label:"Last Name",name:"lastName",variant:"standard",onChange:h.handleChange,onBlur:h.handleBlur,value:h.values.lastName}),(0,K.jsx)(S.Z,{fullWidth:!0,error:!(!h.touched.lastName||!h.errors.username),helperText:h.touched.username&&h.errors.username?h.errors.username:"",margin:"dense",label:"Username",name:"username",variant:"standard",onChange:h.handleChange,onBlur:h.handleBlur,value:h.values.username}),(0,K.jsx)(S.Z,{fullWidth:!0,error:!(!h.touched.password||!h.errors.password),helperText:h.touched.password&&h.errors.password?h.errors.password:"",margin:"dense",label:"Password",name:"password",variant:"standard",onChange:h.handleChange,onBlur:h.handleBlur,value:h.values.password})]}),(0,K.jsx)(f.Z,{style:{display:"inline-flex",margin:"0 auto",flexDirection:"column"},children:(0,K.jsx)(O.Z,{loading:c,variant:"contained",style:{marginTop:"15px"},type:"submit",disabled:c,children:"Create New User"})})]})})]})})}var L=t(54585),z=t(4942),F=t(1413),q=t(45473),P=t(52791),V=t(45100),M={inputProps:{"aria-label":"Checkbox"}},X=function(e,n){return!!e&&!!e.find((function(e){return e===n}))},Y=function(e){return!!e&&!!Object.entries(e).find((function(e){return"admin"===e[0]&&!!e[1]}))},G=function(e){var n=e.name,t=e.row,r=e.onChange,a=e.disableAllRow,i=(0,b.K)((function(e){var n;return null===(n=e.user)||void 0===n?void 0:n.ACL.ownerAccess}));return(0,K.jsxs)(h.Z,{sx:{"&:last-child td, &:last-child th":{border:0}},children:[(0,K.jsx)(o.Z,{component:"th",scope:"row",children:n}),(0,K.jsx)(o.Z,{style:{backgroundColor:X(null===t||void 0===t?void 0:t.disabled,"create")?"lightgrey":"white"},align:"left",children:(0,K.jsx)(q.Z,(0,F.Z)({checked:null===t||void 0===t?void 0:t.create,name:"create",disabled:(X(null===t||void 0===t?void 0:t.disabled,"create")||a)&&!i,onChange:function(e){return r(e,n)}},M))}),(0,K.jsx)(o.Z,{style:{backgroundColor:X(null===t||void 0===t?void 0:t.disabled,"read")?"lightgrey":"white"},align:"left",children:(0,K.jsx)(q.Z,(0,F.Z)({name:"read",onChange:function(e){return r(e,n)},disabled:X(null===t||void 0===t?void 0:t.disabled,"read")||a,checked:null===t||void 0===t?void 0:t.read},M))}),(0,K.jsx)(o.Z,{style:{backgroundColor:X(null===t||void 0===t?void 0:t.disabled,"update")?"lightgrey":"white"},align:"left",children:(0,K.jsx)(q.Z,(0,F.Z)({name:"update",onChange:function(e){return r(e,n)},disabled:X(null===t||void 0===t?void 0:t.disabled,"update")||a,checked:null===t||void 0===t?void 0:t.update},M))}),(0,K.jsx)(o.Z,{style:{backgroundColor:X(null===t||void 0===t?void 0:t.disabled,"delete")?"lightgrey":"white"},align:"left",children:(0,K.jsx)(q.Z,(0,F.Z)({name:"delete",onChange:function(e){return r(e,n)},disabled:X(null===t||void 0===t?void 0:t.disabled,"delete")||a,checked:null===t||void 0===t?void 0:t.delete},M))}),(0,K.jsx)(o.Z,{style:{backgroundColor:X(null===t||void 0===t?void 0:t.disabled,"admin")?"lightgrey":"white"},align:"left",children:(0,K.jsx)(q.Z,(0,F.Z)({name:"admin",onChange:function(e){return r(e,n)},disabled:X(null===t||void 0===t?void 0:t.disabled,"admin")||a,checked:null===t||void 0===t?void 0:t.admin},M))})]})},H=function(e){var n=e.userId,t=e.updateData,f=(0,l.useState)(),m=(0,i.Z)(f,2),Z=m[0],g=m[1],j=(0,l.useState)([]),v=(0,i.Z)(j,2),w=v[0],C=v[1],k=(0,l.useState)([]),y=(0,i.Z)(k,2),N=y[0],A=y[1],S=(0,b.K)((function(e){return e.ACL})),I=(0,l.useState)(!1),U=(0,i.Z)(I,2),O=U[0],B=U[1];(0,l.useEffect)((function(){console.log("userAclApplicationKeys ",w)}),[w]);var E=function(){var e=(0,a.Z)((0,r.Z)().mark((function e(){var t,a,i,l;return(0,r.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return B(!0),e.prev=1,e.next=4,(0,_.wX)(n);case 4:t=e.sent,a=t.data,console.log("getAcl ",a),g(a),i=Object.keys(a.result.application),l=Object.keys(a.result.network),C(i),A(l),e.next=17;break;case 14:e.prev=14,e.t0=e.catch(1),console.log(e.t0);case 17:B(!1);case 18:case"end":return e.stop()}}),e,null,[[1,14]])})));return function(){return e.apply(this,arguments)}}(),R=function(e,n){g((function(t){return{result:(0,F.Z)((0,F.Z)({},t.result),{},{application:(0,F.Z)((0,F.Z)({},t.result.application),{},(0,z.Z)({},n,(0,F.Z)((0,F.Z)({},t.result.application[n]),{},(0,z.Z)({},e.target.name,e.target.checked))))})}}))},W=function(e,n){g((function(n){return{result:(0,F.Z)((0,F.Z)({},n.result),{},{network:(0,F.Z)((0,F.Z)({},n.result.network),{},{netStats:(0,F.Z)((0,F.Z)({},n.result.network.netStats),{},(0,z.Z)({},e.target.name,e.target.checked))})})}}))},D=function(){var e=(0,a.Z)((0,r.Z)().mark((function e(){var a,i,l,s,d;return(0,r.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return B(!0),e.prev=1,a=Object.fromEntries(Object.entries(Z.result.application).map((function(e){return delete e[1].disabled,e}))),i=Object.fromEntries(Object.entries(Z.result.network).map((function(e){return delete e[1].disabled,e}))),l={application:a,network:i},e.next=7,(0,_.eU)(n,l);case 7:s=e.sent,d=s.data,t&&t(d),e.next=15;break;case 12:e.prev=12,e.t0=e.catch(1),console.log(e.t0);case 15:B(!1);case 16:case"end":return e.stop()}}),e,null,[[1,12]])})));return function(){return e.apply(this,arguments)}}();return(0,l.useEffect)((function(){E()}),[]),O?(0,K.jsx)(V.A,{}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(x.Z,{marginBottom:"10px",fontWeight:"bold",children:"Applications"}),(0,K.jsx)(c.Z,{component:p.Z,children:(0,K.jsxs)(s.Z,{size:"small",sx:{minWidth:650},"aria-label":"simple table",children:[(0,K.jsx)(u.Z,{children:(0,K.jsxs)(h.Z,{children:[(0,K.jsx)(o.Z,{children:"Name"}),(0,K.jsx)(o.Z,{children:"Create"}),(0,K.jsx)(o.Z,{align:"left",children:"Read"}),(0,K.jsx)(o.Z,{align:"left",children:"Update"}),(0,K.jsx)(o.Z,{align:"left",children:"Delete"}),(0,K.jsx)(o.Z,{align:"left",children:"Admin"})]})}),(0,K.jsx)(d.Z,{children:S.result&&w.map((function(e){var n=Z.result.application[e],t=S.result.application[e];return(0,K.jsx)(G,{disableAllRow:!Y(t),onChange:R,name:e,row:n},e)}))})]})}),(0,K.jsx)(x.Z,{marginBottom:"10px",marginTop:"10px",fontWeight:"bold",children:"Networks"}),(0,K.jsx)(c.Z,{component:p.Z,children:(0,K.jsxs)(s.Z,{size:"small",sx:{minWidth:650},"aria-label":"simple table",children:[(0,K.jsx)(u.Z,{children:(0,K.jsxs)(h.Z,{children:[(0,K.jsx)(o.Z,{children:"Name"}),(0,K.jsx)(o.Z,{children:"Create"}),(0,K.jsx)(o.Z,{align:"left",children:"Read"}),(0,K.jsx)(o.Z,{align:"left",children:"Update"}),(0,K.jsx)(o.Z,{align:"left",children:"Delete"}),(0,K.jsx)(o.Z,{align:"left",children:"Admin"})]})}),(0,K.jsx)(d.Z,{children:N.map((function(e){var n=Z.result.network.netStats,t=S.result.network.netStats;return(0,K.jsx)(G,{disableAllRow:!Y(t),onChange:W,name:e,row:n},e)}))})]})}),(0,K.jsx)(P.Z,{sx:{display:"flex",width:"100%",justifyContent:"flex-end",marginTop:"20px"},children:(0,K.jsx)(T.Z,{variant:"contained",onClick:D,children:"Update Acl"})})]})},J={position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:"70vw",bgcolor:"background.paper",boxShadow:24,borderRadius:"10px",p:4};function Q(){var e=(0,b.K)((function(e){return e.apps})),n=(0,b.K)((function(e){return e.user.ACL.ownerAccess})),t=(0,b.K)((function(e){return e.user})),C=l.useState(!1),k=(0,i.Z)(C,2),y=k[0],A=k[1],S=l.useState([]),O=(0,i.Z)(S,2),B=O[0],E=O[1],T=l.useState(),R=(0,i.Z)(T,2),W=R[0],z=R[1],F=l.useState({modalOpen:!1,userId:""}),q=(0,i.Z)(F,2),P=q[0],V=q[1],M=l.useState(!1),X=(0,i.Z)(M,2),Y=X[0],G=X[1],Q=(0,b.K)((function(e){return e.ACL}));l.useEffect((function(){G(function(e){for(var n=Object.keys(e.result.application),t=!1,r=0;r<n.length;r++)if(!0===e.result.application[n[r]].admin){t=!0;break}return t}(Q))}),[Q]);var $=l.useState(),ee=(0,i.Z)($,2),ne=ee[0],te=ee[1],re=function(){var e=(0,a.Z)((0,r.Z)().mark((function e(n){var t,a,i,l,s=arguments;return(0,r.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=s.length>1&&void 0!==s[1]?s[1]:10,a=s.length>2&&void 0!==s[2]?s[2]:0,e.prev=2,!n){e.next=11;break}return console.log(n),e.next=7,_.ES(n,t,a);case 7:return i=e.sent,l=i.data,te({limit:l.limit,offset:l.offset,total:l.total}),e.abrupt("return",l.items);case 11:e.next=15;break;case 13:e.prev=13,e.t0=e.catch(2);case 15:return e.abrupt("return",[]);case 16:case"end":return e.stop()}}),e,null,[[2,13]])})));return function(n){return e.apply(this,arguments)}}();l.useEffect((function(){n&&e.length&&(z(e[0]._id),re(e[0]._id).then((function(e){E(e)})))}),[e]),l.useEffect((function(){n||(z(t.appId),re(t.appId).then((function(e){E(e)})))}),[]),l.useEffect((function(){console.log("Users mount")}),[]);var ae=function(){return V({modalOpen:!1,userId:""})};return(0,K.jsxs)(c.Z,{component:p.Z,style:{margin:"0 auto"},children:[(0,K.jsxs)(f.Z,{style:{display:"flex",alignItems:"center"},children:[(0,K.jsx)(x.Z,{variant:"h6",style:{margin:"16px"},children:"Users"}),W&&n?(0,K.jsxs)(I.Z,{variant:"standard",sx:{m:1,minWidth:120},children:[(0,K.jsx)(U.Z,{id:"demo-simple-select-label",children:"App"}),(0,K.jsx)(j.Z,{labelId:"demo-simple-select-label",id:"demo-simple-select",label:"App",value:W,onChange:function(e){z(e.target.value),re(e.target.value).then((function(e){E(e)}))},children:e.map((function(e){return(0,K.jsx)(v.Z,{value:e._id,children:e.appName},e._id)}))})]}):null,(n||Q.result.application.appUsers.create)&&(0,K.jsx)(m.Z,{onClick:function(){return A(!0)},size:"large",children:(0,K.jsx)(g.Z,{fontSize:"large"})})]}),0===B.length&&(0,K.jsxs)(f.Z,{style:{display:"flex",flexDirection:"column",alignItems:"center"},children:[(0,K.jsx)(w.Z,{}),(0,K.jsx)(x.Z,{style:{marginTop:"20px",marginBottom:"20px"},children:"Users not found."})]}),B.length>0&&(0,K.jsxs)(s.Z,{"aria-label":"simple table",children:[(0,K.jsx)(u.Z,{children:(0,K.jsxs)(h.Z,{children:[(0,K.jsx)(o.Z,{width:200,children:"appId"}),(0,K.jsx)(o.Z,{align:"right",children:"firstName"}),(0,K.jsx)(o.Z,{align:"right",children:"lastName"}),(0,K.jsx)(o.Z,{align:"right",children:"username"}),(0,K.jsx)(o.Z,{align:"right",children:"email"}),(0,K.jsx)(o.Z,{align:"right",children:"Actions"})]})}),(0,K.jsxs)(d.Z,{children:[B.map((function(e){return(0,K.jsxs)(h.Z,{sx:{"&:last-child td, &:last-child th":{border:0}},children:[(0,K.jsx)(o.Z,{component:"th",scope:"row",children:e.appId}),(0,K.jsx)(o.Z,{align:"right",children:e.firstName}),(0,K.jsx)(o.Z,{align:"right",children:e.lastName}),(0,K.jsx)(o.Z,{align:"right",children:e.username?e.username:"-"}),(0,K.jsx)(o.Z,{align:"right",children:e.email?e.email:"-"}),(0,K.jsx)(o.Z,{align:"right",children:(0,K.jsxs)(f.Z,{sx:{width:"200px"},children:[Q.result.application.appUsers.update&&(0,K.jsx)(x.Z,{children:"Edit"}),Y&&(0,K.jsx)(x.Z,{style:{cursor:"pointer",textDecoration:"underline"},onClick:function(){return n=e._id,V({modalOpen:!0,userId:n});var n},children:"Edit ACL"})]})})]},e._id)})),(null===ne||void 0===ne?void 0:ne.total)&&(0,K.jsx)(h.Z,{children:(0,K.jsx)(o.Z,{colSpan:6,children:(0,K.jsx)(L.Z,{onChange:function(e,n){var t=0;n-1>0&&(t=(n-1)*((null===ne||void 0===ne?void 0:ne.limit)||10)),re(W||null,(null===ne||void 0===ne?void 0:ne.limit)||10,t).then((function(e){return E(e)}))},count:Math.ceil(ne.total/ne.limit)})})})]})]}),(0,K.jsx)(D,{open:y,setUsers:E,setOpen:A}),(0,K.jsx)(Z.Z,{open:P.modalOpen,onClose:ae,"aria-labelledby":"modal-modal-title","aria-describedby":"modal-modal-description",children:(0,K.jsxs)(f.Z,{sx:J,children:[(0,K.jsx)(H,{updateData:function(e){var n=B,t=n.findIndex((function(e){return e._id===P.userId}));n[t]._id=e.result.userId,E(n)},userId:P.userId}),(0,K.jsx)(m.Z,{onClick:ae,sx:{position:"absolute",top:0,right:0,color:"black"},children:(0,K.jsx)(N.Z,{fontSize:"large"})})]})})]})}}}]);
//# sourceMappingURL=50.57553c55.chunk.js.map