"use strict";(self.webpackChunk_digicms_admin=self.webpackChunk_digicms_admin||[]).push([[2544],{33778:function(ae,y,t){t.r(y),t.d(y,{default:function(){return Q}});var e=t(32735),s=t(58521),R=t(5141),P=t(83983),d=t(72850),S=t(41415),U=t(28356),Z=t(17e3),B=t(27649),v=t(27677),D=t(83281),F=t(29439),z=t(33795),L=t.n(z),M=t(5636),j=t(37511),N=t(15335),C=t(5803),K=t(87933),b=t(49372),G=t(10508),O=t(10369),$=t(60216),c=t.n($);const E=({disabled:r,role:a,values:n,errors:i,onChange:f,onBlur:m})=>{const{formatMessage:o}=(0,M.useIntl)();return e.createElement(d.x,{background:"neutral0",padding:6,shadow:"filterShadow",hasRadius:!0},e.createElement(v.K,{spacing:4},e.createElement(K.k,{justifyContent:"space-between"},e.createElement(d.x,null,e.createElement(d.x,null,e.createElement(b.Z,{fontWeight:"bold"},a?a.name:o({id:"global.details",defaultMessage:"Details"}))),e.createElement(d.x,null,e.createElement(b.Z,{textColor:"neutral500",variant:"pi"},a?a.description:o({id:"Settings.roles.form.description",defaultMessage:"Name and description of the role"})))),e.createElement(S.z,{disabled:!0,variant:"secondary"},o({id:"Settings.roles.form.button.users-with-role",defaultMessage:"{number, plural, =0 {# users} one {# user} other {# users}} with this role"},{number:a.usersCount}))),e.createElement(N.r,{gap:4},e.createElement(C.P,{col:6},e.createElement(O.o,{disabled:r,name:"name",error:i.name&&o({id:i.name}),label:o({id:"global.name",defaultMessage:"Name"}),onChange:f,onBlur:m,value:n.name||""})),e.createElement(C.P,{col:6},e.createElement(G.g,{disabled:r,label:o({id:"global.description",defaultMessage:"Description"}),name:"description",error:i.name&&o({id:i.name}),onChange:f,onBlur:m},n.description||"")))))};E.defaultProps={disabled:!1,role:null,values:{name:"",description:""}},E.propTypes={disabled:c().bool,errors:c().object.isRequired,onBlur:c().func.isRequired,onChange:c().func.isRequired,role:c().object,values:c().object};var H=E,x=t(31842),T=t(5173),V=T.Ry().shape({name:T.Z_().required(s.translatedErrors.required)}),W=t(98399),J=()=>{const r=(0,s.useNotification)(),{formatMessage:a}=(0,M.useIntl)(),{params:{id:n}}=(0,R.useRouteMatch)("/settings/roles/:id"),[i,f]=(0,e.useState)(!1),m=(0,e.useRef)(),{lockApp:o,unlockApp:X}=(0,s.useOverlayBlocker)(),{trackUsage:Y}=(0,s.useTracking)(),{isLoading:k,data:w}=(0,x.U_)(n),{role:u,permissions:q,isLoading:A,onSubmitSucceeded:_}=(0,x.Dq)(n),ee=async g=>{try{o(),f(!0);const{permissionsToSend:l,didUpdateConditions:p}=m.current.getPermissions();await(0,s.request)(`/admin/roles/${n}`,{method:"PUT",body:g}),u.code!=="strapi-super-admin"&&(await(0,s.request)(`/admin/roles/${n}/permissions`,{method:"PUT",body:{permissions:l}}),p&&Y("didUpdateConditions")),m.current.setFormAfterSubmit(),_({name:g.name,description:g.description}),r({type:"success",message:{id:"notification.success.saved"}})}catch(l){W.error(l.response);const p=L()(l,"response.payload.message","An error occured"),h=L()(l,"response.payload.data.permissions[0]",p);r({type:"warning",message:h})}finally{f(!1),X()}},I=u.code==="strapi-super-admin";return e.createElement(B.o,null,e.createElement(s.SettingsPageTitle,{name:"Roles"}),e.createElement(D.Formik,{enableReinitialize:!0,initialValues:{name:u.name,description:u.description},onSubmit:ee,validationSchema:V,validateOnChange:!1},({handleSubmit:g,values:l,errors:p,handleChange:h,handleBlur:te})=>e.createElement("form",{onSubmit:g},e.createElement(U.T,{primaryAction:e.createElement(v.K,{horizontal:!0,spacing:2},e.createElement(S.z,{disabled:u.code==="strapi-super-admin",onClick:g,loading:i,size:"L"},a({id:"global.save",defaultMessage:"Save"}))),title:a({id:"Settings.roles.edit.title",defaultMessage:"Edit a role"}),subtitle:a({id:"Settings.roles.create.description",defaultMessage:"Define the rights given to the role"}),navigationAction:e.createElement(s.Link,{startIcon:e.createElement(F.Z,null),to:"/settings/roles"},a({id:"global.back",defaultMessage:"Back"}))}),e.createElement(Z.D,null,e.createElement(v.K,{spacing:6},e.createElement(H,{isLoading:A,disabled:I,errors:p,values:l,onChange:h,onBlur:te,role:u}),!k&&!A?e.createElement(d.x,{shadow:"filterShadow",hasRadius:!0},e.createElement(j.Z,{isFormDisabled:I,permissions:q,ref:m,layout:w})):e.createElement(d.x,{background:"neutral0",padding:6,shadow:"filterShadow",hasRadius:!0},e.createElement(s.LoadingIndicatorPage,null)))))))},Q=()=>{const r=(0,e.useMemo)(()=>({read:P.Z.settings.roles.read,update:P.Z.settings.roles.update}),[]),{isLoading:a,allowedActions:{canRead:n,canUpdate:i}}=(0,s.useRBAC)(r);return a?e.createElement(s.LoadingIndicatorPage,null):!n&&!i?e.createElement(R.Redirect,{to:"/"}):e.createElement(J,null)}}}]);
