"use strict";(self.webpackChunk_digicms_admin=self.webpackChunk_digicms_admin||[]).push([[8056],{83782:function(ue,M,t){t.r(M),t.d(M,{default:function(){return le}});var e=t(32735),n=t(58521),R=t(83983),k=t(5636),A=t(84968),h=t(5141),V=t(33348),x=t.n(V),$=t(28356),H=t(17e3),Z=t(27649),F=t(41415),S=t(19406),P=t(17247),O=[{name:"name",key:"name",metadatas:{label:{id:"Settings.apiTokens.ListView.headers.name",defaultMessage:"Name"},sortable:!0}},{name:"description",key:"description",metadatas:{label:{id:"Settings.apiTokens.ListView.headers.description",defaultMessage:"Description"},sortable:!1}},{name:"createdAt",key:"createdAt",metadatas:{label:{id:"Settings.apiTokens.ListView.headers.createdAt",defaultMessage:"Created at"},sortable:!1}},{name:"lastUsedAt",key:"lastUsedAt",metadatas:{label:{id:"Settings.apiTokens.ListView.headers.lastUsedAt",defaultMessage:"Last used"},sortable:!1}}],Q=t(60216),a=t.n(Q),y=t(49372),W=t(3594),z=t(29005),f=t(66735),G=t(87933),j=t(4038),Y=t(50563),J=t(72850);const B=({tokenName:l,onClickDelete:o})=>{const{formatMessage:d}=(0,k.useIntl)(),{trackUsage:c}=(0,n.useTracking)();return e.createElement(J.x,{paddingLeft:1,...n.stopPropagation},e.createElement(Y.h,{onClick:()=>{c("willDeleteToken"),o()},label:d({id:"global.delete-target",defaultMessage:"Delete {target}"},{target:`${l}`}),name:"delete",noBorder:!0,icon:e.createElement(j.default,null)}))};B.propTypes={tokenName:a().string.isRequired,onClickDelete:a().func.isRequired};var K=B,X=t(68625),q=t(83292);const _={edit:{id:"app.component.table.edit",defaultMessage:"Edit {target}"},read:{id:"app.component.table.read",defaultMessage:"Read {target}"}},ee=(0,q.default)(n.Link)`
  svg {
    path {
      fill: ${({theme:l})=>l.colors.neutral500};
    }
  }

  &:hover,
  &:focus {
    svg {
      path {
        fill: ${({theme:l})=>l.colors.neutral800};
      }
    }
  }
`,C=({tokenName:l,tokenId:o,buttonType:d,children:c})=>{const{formatMessage:u}=(0,k.useIntl)(),{location:{pathname:m}}=(0,h.useHistory)();return e.createElement(ee,{to:`${m}/${o}`,title:u(_[d],{target:l})},c)};C.propTypes={tokenName:a().string.isRequired,tokenId:a().oneOfType([a().string,a().number]).isRequired,buttonType:a().string,children:a().node.isRequired},C.defaultProps={buttonType:"edit"};var I=C;const N=({tokenName:l,tokenId:o})=>e.createElement(I,{tokenName:l,tokenId:o},e.createElement(X.Z,null));N.propTypes={tokenName:a().string.isRequired,tokenId:a().oneOfType([a().string,a().number]).isRequired};var te=N,ae=t(54894);const w=({tokenName:l,tokenId:o})=>e.createElement(I,{tokenName:l,tokenId:o,buttonType:"read"},e.createElement(ae.default,null));w.propTypes={tokenName:a().string.isRequired,tokenId:a().oneOfType([a().string,a().number]).isRequired};var ne=w;const D=({canDelete:l,canUpdate:o,canRead:d,onClickDelete:c,withBulkActions:u,rows:m})=>{const[{query:r}]=(0,n.useQueryParams)(),[,T]=r.sort.split(":"),{push:g,location:{pathname:L}}=(0,h.useHistory)(),{trackUsage:E}=(0,n.useTracking)(),b=m.sort((s,p)=>{const v=s.name.localeCompare(p.name);return T==="DESC"?-v:v});return e.createElement(W.p,null,b.map(s=>e.createElement(z.Tr,{key:s.id,...(0,n.onRowClick)({fn(){E("willEditTokenFromList"),g(`${L}/${s.id}`)},condition:o})},e.createElement(f.Td,null,e.createElement(y.Z,{textColor:"neutral800",fontWeight:"bold"},s.name)),e.createElement(f.Td,{maxWidth:(0,n.pxToRem)(250)},e.createElement(y.Z,{textColor:"neutral800",ellipsis:!0},s.description)),e.createElement(f.Td,null,e.createElement(y.Z,{textColor:"neutral800"},e.createElement(n.RelativeTime,{timestamp:new Date(s.createdAt)}))),e.createElement(f.Td,null,s.lastUsedAt&&e.createElement(y.Z,{textColor:"neutral800"},e.createElement(n.RelativeTime,{timestamp:new Date(s.lastUsedAt)}))),u&&e.createElement(f.Td,null,e.createElement(G.k,{justifyContent:"end"},o&&e.createElement(te,{tokenName:s.name,tokenId:s.id}),!o&&d&&e.createElement(ne,{tokenName:s.name,tokenId:s.id}),l&&e.createElement(K,{tokenName:s.name,onClickDelete:()=>c(s.id)}))))))};D.defaultProps={canDelete:!1,canUpdate:!1,canRead:!1,onClickDelete(){},rows:[],withBulkActions:!1},D.propTypes={canDelete:a().bool,canUpdate:a().bool,canRead:a().bool,onClickDelete:a().func,rows:a().array,withBulkActions:a().bool};var se=D,oe=()=>{(0,n.useFocusWhenNavigate)();const l=(0,A.useQueryClient)(),{formatMessage:o}=(0,k.useIntl)(),d=(0,n.useNotification)(),{allowedActions:{canCreate:c,canDelete:u,canUpdate:m,canRead:r}}=(0,n.useRBAC)(R.Z.settings["api-tokens"]),{push:T}=(0,h.useHistory)(),{trackUsage:g}=(0,n.useTracking)(),{startSection:L}=(0,n.useGuidedTour)(),E=(0,e.useRef)(L);(0,e.useEffect)(()=>{E.current&&E.current("apiTokens")},[]),(0,e.useEffect)(()=>{T({search:x().stringify({sort:"name:ASC"},{encode:!1})})},[T]);const b=O.map(i=>({...i,metadatas:{...i.metadatas,label:o(i.metadatas.label)}})),{data:s,status:p,isFetching:v}=(0,A.useQuery)(["api-tokens"],async()=>{g("willAccessTokenList");const{data:{data:i}}=await P.be.get("/admin/api-tokens");return g("didAccessTokenList",{number:i.length}),i},{enabled:r,onError(){d({type:"warning",message:{id:"notification.error",defaultMessage:"An error occured"}})}}),U=r&&(p!=="success"&&p!=="error"||p==="success"&&v),ie=(0,A.useMutation)(async i=>{await P.be.delete(`/admin/api-tokens/${i}`)},{async onSuccess(){await l.invalidateQueries(["api-tokens"]),g("didDeleteToken")},onError(i){i?.response?.data?.data?d({type:"warning",message:i.response.data.data}):d({type:"warning",message:{id:"notification.error",defaultMessage:"An error occured"}})}}),re=r&&s,de=r&&!s&&!c,ce=r&&!s&&c;return e.createElement(Z.o,{"aria-busy":U},e.createElement(n.SettingsPageTitle,{name:"API Tokens"}),e.createElement($.T,{title:o({id:"Settings.apiTokens.title",defaultMessage:"API Tokens"}),subtitle:o({id:"Settings.apiTokens.description",defaultMessage:"List of generated tokens to consume the API"}),primaryAction:c?e.createElement(n.LinkButton,{"data-testid":"create-api-token-button",startIcon:e.createElement(S.default,null),size:"S",onClick:()=>g("willAddTokenFromList"),to:"/settings/api-tokens/create"},o({id:"Settings.apiTokens.create",defaultMessage:"Create new API Token"})):void 0}),e.createElement(H.D,null,!r&&e.createElement(n.NoPermissions,null),re&&e.createElement(n.DynamicTable,{headers:b,contentType:"api-tokens",rows:s,withBulkActions:u||m||r,isLoading:U,onConfirmDelete:i=>ie.mutateAsync(i)},e.createElement(se,{canRead:r,canDelete:u,canUpdate:m,rows:s,withBulkActions:u||m||r})),ce&&e.createElement(n.NoContent,{content:{id:"Settings.apiTokens.addFirstToken",defaultMessage:"Add your first API Token"},action:e.createElement(F.z,{variant:"secondary",startIcon:e.createElement(S.default,null)},o({id:"Settings.apiTokens.addNewToken",defaultMessage:"Add new API Token"}))}),de&&e.createElement(n.NoContent,{content:{id:"Settings.apiTokens.emptyStateLayout",defaultMessage:"You don\u2019t have any content yet..."}})))},le=()=>e.createElement(n.CheckPagePermissions,{permissions:R.Z.settings["api-tokens"].main},e.createElement(oe,null))}}]);
