node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

@@ -0,0 +1,31 @@
'use strict';
var admin = require('@strapi/strapi/admin');
var yup = require('yup');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
const createRoleSchema = yup__namespace.object().shape({
name: yup__namespace.string().required(admin.translatedErrors.required.id),
description: yup__namespace.string().required(admin.translatedErrors.required.id)
});
exports.createRoleSchema = createRoleSchema;
//# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sources":["../../../../admin/src/pages/Roles/constants.js"],"sourcesContent":["import { translatedErrors } from '@strapi/strapi/admin';\nimport * as yup from 'yup';\n\nexport const createRoleSchema = yup.object().shape({\n name: yup.string().required(translatedErrors.required.id),\n description: yup.string().required(translatedErrors.required.id),\n});\n"],"names":["createRoleSchema","yup","object","shape","name","string","required","translatedErrors","id","description"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;MAGaA,gBAAmBC,GAAAA,cAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;IACjDC,IAAMH,EAAAA,cAAAA,CAAII,MAAM,EAAGC,CAAAA,QAAQ,CAACC,sBAAiBD,CAAAA,QAAQ,CAACE,EAAE,CAAA;IACxDC,WAAaR,EAAAA,cAAAA,CAAII,MAAM,EAAGC,CAAAA,QAAQ,CAACC,sBAAiBD,CAAAA,QAAQ,CAACE,EAAE;AACjE,CAAG;;;;"}
@@ -0,0 +1,10 @@
import { translatedErrors } from '@strapi/strapi/admin';
import * as yup from 'yup';
const createRoleSchema = yup.object().shape({
name: yup.string().required(translatedErrors.required.id),
description: yup.string().required(translatedErrors.required.id)
});
export { createRoleSchema };
//# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"constants.mjs","sources":["../../../../admin/src/pages/Roles/constants.js"],"sourcesContent":["import { translatedErrors } from '@strapi/strapi/admin';\nimport * as yup from 'yup';\n\nexport const createRoleSchema = yup.object().shape({\n name: yup.string().required(translatedErrors.required.id),\n description: yup.string().required(translatedErrors.required.id),\n});\n"],"names":["createRoleSchema","yup","object","shape","name","string","required","translatedErrors","id","description"],"mappings":";;;MAGaA,gBAAmBC,GAAAA,GAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;IACjDC,IAAMH,EAAAA,GAAAA,CAAII,MAAM,EAAGC,CAAAA,QAAQ,CAACC,gBAAiBD,CAAAA,QAAQ,CAACE,EAAE,CAAA;IACxDC,WAAaR,EAAAA,GAAAA,CAAII,MAAM,EAAGC,CAAAA,QAAQ,CAACC,gBAAiBD,CAAAA,QAAQ,CAACE,EAAE;AACjE,CAAG;;;;"}
@@ -0,0 +1,78 @@
'use strict';
var React = require('react');
var admin = require('@strapi/strapi/admin');
var reactQuery = require('react-query');
var cleanPermissions = require('../../../utils/cleanPermissions.js');
var getTrad = require('../../../utils/getTrad.js');
const usePlugins = ()=>{
const { toggleNotification } = admin.useNotification();
const { get } = admin.useFetchClient();
const { formatAPIError } = admin.useAPIErrorHandler(getTrad);
const [{ data: permissions, isLoading: isLoadingPermissions, error: permissionsError, refetch: refetchPermissions }, { data: routes, isLoading: isLoadingRoutes, error: routesError, refetch: refetchRoutes }] = reactQuery.useQueries([
{
queryKey: [
'users-permissions',
'permissions'
],
async queryFn () {
const { data: { permissions } } = await get(`/users-permissions/permissions`);
return permissions;
}
},
{
queryKey: [
'users-permissions',
'routes'
],
async queryFn () {
const { data: { routes } } = await get(`/users-permissions/routes`);
return routes;
}
}
]);
const refetchQueries = async ()=>{
await Promise.all([
refetchPermissions(),
refetchRoutes()
]);
};
React.useEffect(()=>{
if (permissionsError) {
toggleNotification({
type: 'danger',
message: formatAPIError(permissionsError)
});
}
}, [
toggleNotification,
permissionsError,
formatAPIError
]);
React.useEffect(()=>{
if (routesError) {
toggleNotification({
type: 'danger',
message: formatAPIError(routesError)
});
}
}, [
toggleNotification,
routesError,
formatAPIError
]);
const isLoading = isLoadingPermissions || isLoadingRoutes;
return {
// TODO: these return values need to be memoized, otherwise
// they will create infinite rendering loops when used as
// effect dependencies
permissions: permissions ? cleanPermissions(permissions) : {},
routes: routes ?? {},
getData: refetchQueries,
isLoading
};
};
exports.usePlugins = usePlugins;
//# sourceMappingURL=usePlugins.js.map
@@ -0,0 +1 @@
{"version":3,"file":"usePlugins.js","sources":["../../../../../admin/src/pages/Roles/hooks/usePlugins.js"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { useAPIErrorHandler, useNotification, useFetchClient } from '@strapi/strapi/admin';\nimport { useQueries } from 'react-query';\n\nimport { cleanPermissions, getTrad } from '../../../utils';\n\nexport const usePlugins = () => {\n const { toggleNotification } = useNotification();\n const { get } = useFetchClient();\n const { formatAPIError } = useAPIErrorHandler(getTrad);\n\n const [\n {\n data: permissions,\n isLoading: isLoadingPermissions,\n error: permissionsError,\n refetch: refetchPermissions,\n },\n { data: routes, isLoading: isLoadingRoutes, error: routesError, refetch: refetchRoutes },\n ] = useQueries([\n {\n queryKey: ['users-permissions', 'permissions'],\n async queryFn() {\n const {\n data: { permissions },\n } = await get(`/users-permissions/permissions`);\n\n return permissions;\n },\n },\n {\n queryKey: ['users-permissions', 'routes'],\n async queryFn() {\n const {\n data: { routes },\n } = await get(`/users-permissions/routes`);\n\n return routes;\n },\n },\n ]);\n\n const refetchQueries = async () => {\n await Promise.all([refetchPermissions(), refetchRoutes()]);\n };\n\n useEffect(() => {\n if (permissionsError) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(permissionsError),\n });\n }\n }, [toggleNotification, permissionsError, formatAPIError]);\n\n useEffect(() => {\n if (routesError) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(routesError),\n });\n }\n }, [toggleNotification, routesError, formatAPIError]);\n\n const isLoading = isLoadingPermissions || isLoadingRoutes;\n\n return {\n // TODO: these return values need to be memoized, otherwise\n // they will create infinite rendering loops when used as\n // effect dependencies\n permissions: permissions ? cleanPermissions(permissions) : {},\n routes: routes ?? {},\n\n getData: refetchQueries,\n isLoading,\n };\n};\n"],"names":["usePlugins","toggleNotification","useNotification","get","useFetchClient","formatAPIError","useAPIErrorHandler","getTrad","data","permissions","isLoading","isLoadingPermissions","error","permissionsError","refetch","refetchPermissions","routes","isLoadingRoutes","routesError","refetchRoutes","useQueries","queryKey","queryFn","refetchQueries","Promise","all","useEffect","type","message","cleanPermissions","getData"],"mappings":";;;;;;;;MAOaA,UAAa,GAAA,IAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,qBAAAA,EAAAA;IAC/B,MAAM,EAAEC,GAAG,EAAE,GAAGC,oBAAAA,EAAAA;AAChB,IAAA,MAAM,EAAEC,cAAc,EAAE,GAAGC,wBAAmBC,CAAAA,OAAAA,CAAAA;AAE9C,IAAA,MAAM,CACJ,EACEC,IAAMC,EAAAA,WAAW,EACjBC,SAAAA,EAAWC,oBAAoB,EAC/BC,KAAOC,EAAAA,gBAAgB,EACvBC,OAAAA,EAASC,kBAAkB,EAC5B,EACD,EAAEP,IAAAA,EAAMQ,MAAM,EAAEN,SAAWO,EAAAA,eAAe,EAAEL,KAAAA,EAAOM,WAAW,EAAEJ,OAASK,EAAAA,aAAa,EAAE,CACzF,GAAGC,qBAAW,CAAA;AACb,QAAA;YACEC,QAAU,EAAA;AAAC,gBAAA,mBAAA;AAAqB,gBAAA;AAAc,aAAA;YAC9C,MAAMC,OAAAA,CAAAA,GAAAA;gBACJ,MAAM,EACJd,IAAM,EAAA,EAAEC,WAAW,EAAE,EACtB,GAAG,MAAMN,GAAAA,CAAI,CAAC,8BAA8B,CAAC,CAAA;gBAE9C,OAAOM,WAAAA;AACT;AACF,SAAA;AACA,QAAA;YACEY,QAAU,EAAA;AAAC,gBAAA,mBAAA;AAAqB,gBAAA;AAAS,aAAA;YACzC,MAAMC,OAAAA,CAAAA,GAAAA;gBACJ,MAAM,EACJd,IAAM,EAAA,EAAEQ,MAAM,EAAE,EACjB,GAAG,MAAMb,GAAAA,CAAI,CAAC,yBAAyB,CAAC,CAAA;gBAEzC,OAAOa,MAAAA;AACT;AACF;AACD,KAAA,CAAA;AAED,IAAA,MAAMO,cAAiB,GAAA,UAAA;QACrB,MAAMC,OAAAA,CAAQC,GAAG,CAAC;AAACV,YAAAA,kBAAAA,EAAAA;AAAsBI,YAAAA,aAAAA;AAAgB,SAAA,CAAA;AAC3D,KAAA;IAEAO,eAAU,CAAA,IAAA;AACR,QAAA,IAAIb,gBAAkB,EAAA;YACpBZ,kBAAmB,CAAA;gBACjB0B,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASvB,cAAeQ,CAAAA,gBAAAA;AAC1B,aAAA,CAAA;AACF;KACC,EAAA;AAACZ,QAAAA,kBAAAA;AAAoBY,QAAAA,gBAAAA;AAAkBR,QAAAA;AAAe,KAAA,CAAA;IAEzDqB,eAAU,CAAA,IAAA;AACR,QAAA,IAAIR,WAAa,EAAA;YACfjB,kBAAmB,CAAA;gBACjB0B,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASvB,cAAea,CAAAA,WAAAA;AAC1B,aAAA,CAAA;AACF;KACC,EAAA;AAACjB,QAAAA,kBAAAA;AAAoBiB,QAAAA,WAAAA;AAAab,QAAAA;AAAe,KAAA,CAAA;AAEpD,IAAA,MAAMK,YAAYC,oBAAwBM,IAAAA,eAAAA;IAE1C,OAAO;;;;QAILR,WAAaA,EAAAA,WAAAA,GAAcoB,gBAAiBpB,CAAAA,WAAAA,CAAAA,GAAe,EAAC;AAC5DO,QAAAA,MAAAA,EAAQA,UAAU,EAAC;QAEnBc,OAASP,EAAAA,cAAAA;AACTb,QAAAA;AACF,KAAA;AACF;;;;"}
@@ -0,0 +1,76 @@
import { useEffect } from 'react';
import { useNotification, useFetchClient, useAPIErrorHandler } from '@strapi/strapi/admin';
import { useQueries } from 'react-query';
import cleanPermissions from '../../../utils/cleanPermissions.mjs';
import getTrad from '../../../utils/getTrad.mjs';
const usePlugins = ()=>{
const { toggleNotification } = useNotification();
const { get } = useFetchClient();
const { formatAPIError } = useAPIErrorHandler(getTrad);
const [{ data: permissions, isLoading: isLoadingPermissions, error: permissionsError, refetch: refetchPermissions }, { data: routes, isLoading: isLoadingRoutes, error: routesError, refetch: refetchRoutes }] = useQueries([
{
queryKey: [
'users-permissions',
'permissions'
],
async queryFn () {
const { data: { permissions } } = await get(`/users-permissions/permissions`);
return permissions;
}
},
{
queryKey: [
'users-permissions',
'routes'
],
async queryFn () {
const { data: { routes } } = await get(`/users-permissions/routes`);
return routes;
}
}
]);
const refetchQueries = async ()=>{
await Promise.all([
refetchPermissions(),
refetchRoutes()
]);
};
useEffect(()=>{
if (permissionsError) {
toggleNotification({
type: 'danger',
message: formatAPIError(permissionsError)
});
}
}, [
toggleNotification,
permissionsError,
formatAPIError
]);
useEffect(()=>{
if (routesError) {
toggleNotification({
type: 'danger',
message: formatAPIError(routesError)
});
}
}, [
toggleNotification,
routesError,
formatAPIError
]);
const isLoading = isLoadingPermissions || isLoadingRoutes;
return {
// TODO: these return values need to be memoized, otherwise
// they will create infinite rendering loops when used as
// effect dependencies
permissions: permissions ? cleanPermissions(permissions) : {},
routes: routes ?? {},
getData: refetchQueries,
isLoading
};
};
export { usePlugins };
//# sourceMappingURL=usePlugins.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"usePlugins.mjs","sources":["../../../../../admin/src/pages/Roles/hooks/usePlugins.js"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { useAPIErrorHandler, useNotification, useFetchClient } from '@strapi/strapi/admin';\nimport { useQueries } from 'react-query';\n\nimport { cleanPermissions, getTrad } from '../../../utils';\n\nexport const usePlugins = () => {\n const { toggleNotification } = useNotification();\n const { get } = useFetchClient();\n const { formatAPIError } = useAPIErrorHandler(getTrad);\n\n const [\n {\n data: permissions,\n isLoading: isLoadingPermissions,\n error: permissionsError,\n refetch: refetchPermissions,\n },\n { data: routes, isLoading: isLoadingRoutes, error: routesError, refetch: refetchRoutes },\n ] = useQueries([\n {\n queryKey: ['users-permissions', 'permissions'],\n async queryFn() {\n const {\n data: { permissions },\n } = await get(`/users-permissions/permissions`);\n\n return permissions;\n },\n },\n {\n queryKey: ['users-permissions', 'routes'],\n async queryFn() {\n const {\n data: { routes },\n } = await get(`/users-permissions/routes`);\n\n return routes;\n },\n },\n ]);\n\n const refetchQueries = async () => {\n await Promise.all([refetchPermissions(), refetchRoutes()]);\n };\n\n useEffect(() => {\n if (permissionsError) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(permissionsError),\n });\n }\n }, [toggleNotification, permissionsError, formatAPIError]);\n\n useEffect(() => {\n if (routesError) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(routesError),\n });\n }\n }, [toggleNotification, routesError, formatAPIError]);\n\n const isLoading = isLoadingPermissions || isLoadingRoutes;\n\n return {\n // TODO: these return values need to be memoized, otherwise\n // they will create infinite rendering loops when used as\n // effect dependencies\n permissions: permissions ? cleanPermissions(permissions) : {},\n routes: routes ?? {},\n\n getData: refetchQueries,\n isLoading,\n };\n};\n"],"names":["usePlugins","toggleNotification","useNotification","get","useFetchClient","formatAPIError","useAPIErrorHandler","getTrad","data","permissions","isLoading","isLoadingPermissions","error","permissionsError","refetch","refetchPermissions","routes","isLoadingRoutes","routesError","refetchRoutes","useQueries","queryKey","queryFn","refetchQueries","Promise","all","useEffect","type","message","cleanPermissions","getData"],"mappings":";;;;;;MAOaA,UAAa,GAAA,IAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,GAAG,EAAE,GAAGC,cAAAA,EAAAA;AAChB,IAAA,MAAM,EAAEC,cAAc,EAAE,GAAGC,kBAAmBC,CAAAA,OAAAA,CAAAA;AAE9C,IAAA,MAAM,CACJ,EACEC,IAAMC,EAAAA,WAAW,EACjBC,SAAAA,EAAWC,oBAAoB,EAC/BC,KAAOC,EAAAA,gBAAgB,EACvBC,OAAAA,EAASC,kBAAkB,EAC5B,EACD,EAAEP,IAAAA,EAAMQ,MAAM,EAAEN,SAAWO,EAAAA,eAAe,EAAEL,KAAAA,EAAOM,WAAW,EAAEJ,OAASK,EAAAA,aAAa,EAAE,CACzF,GAAGC,UAAW,CAAA;AACb,QAAA;YACEC,QAAU,EAAA;AAAC,gBAAA,mBAAA;AAAqB,gBAAA;AAAc,aAAA;YAC9C,MAAMC,OAAAA,CAAAA,GAAAA;gBACJ,MAAM,EACJd,IAAM,EAAA,EAAEC,WAAW,EAAE,EACtB,GAAG,MAAMN,GAAAA,CAAI,CAAC,8BAA8B,CAAC,CAAA;gBAE9C,OAAOM,WAAAA;AACT;AACF,SAAA;AACA,QAAA;YACEY,QAAU,EAAA;AAAC,gBAAA,mBAAA;AAAqB,gBAAA;AAAS,aAAA;YACzC,MAAMC,OAAAA,CAAAA,GAAAA;gBACJ,MAAM,EACJd,IAAM,EAAA,EAAEQ,MAAM,EAAE,EACjB,GAAG,MAAMb,GAAAA,CAAI,CAAC,yBAAyB,CAAC,CAAA;gBAEzC,OAAOa,MAAAA;AACT;AACF;AACD,KAAA,CAAA;AAED,IAAA,MAAMO,cAAiB,GAAA,UAAA;QACrB,MAAMC,OAAAA,CAAQC,GAAG,CAAC;AAACV,YAAAA,kBAAAA,EAAAA;AAAsBI,YAAAA,aAAAA;AAAgB,SAAA,CAAA;AAC3D,KAAA;IAEAO,SAAU,CAAA,IAAA;AACR,QAAA,IAAIb,gBAAkB,EAAA;YACpBZ,kBAAmB,CAAA;gBACjB0B,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASvB,cAAeQ,CAAAA,gBAAAA;AAC1B,aAAA,CAAA;AACF;KACC,EAAA;AAACZ,QAAAA,kBAAAA;AAAoBY,QAAAA,gBAAAA;AAAkBR,QAAAA;AAAe,KAAA,CAAA;IAEzDqB,SAAU,CAAA,IAAA;AACR,QAAA,IAAIR,WAAa,EAAA;YACfjB,kBAAmB,CAAA;gBACjB0B,IAAM,EAAA,QAAA;AACNC,gBAAAA,OAAAA,EAASvB,cAAea,CAAAA,WAAAA;AAC1B,aAAA,CAAA;AACF;KACC,EAAA;AAACjB,QAAAA,kBAAAA;AAAoBiB,QAAAA,WAAAA;AAAab,QAAAA;AAAe,KAAA,CAAA;AAEpD,IAAA,MAAMK,YAAYC,oBAAwBM,IAAAA,eAAAA;IAE1C,OAAO;;;;QAILR,WAAaA,EAAAA,WAAAA,GAAcoB,gBAAiBpB,CAAAA,WAAAA,CAAAA,GAAe,EAAC;AAC5DO,QAAAA,MAAAA,EAAQA,UAAU,EAAC;QAEnBc,OAASP,EAAAA,cAAAA;AACTb,QAAAA;AACF,KAAA;AACF;;;;"}
@@ -0,0 +1,35 @@
'use strict';
var jsxRuntime = require('react/jsx-runtime');
require('react');
var admin = require('@strapi/strapi/admin');
var reactRouterDom = require('react-router-dom');
var constants = require('../../constants.js');
var CreatePage = require('./pages/CreatePage.js');
var EditPage = require('./pages/EditPage.js');
var index = require('./pages/ListPage/index.js');
const Roles = ()=>{
return /*#__PURE__*/ jsxRuntime.jsx(admin.Page.Protect, {
permissions: constants.PERMISSIONS.accessRoles,
children: /*#__PURE__*/ jsxRuntime.jsxs(reactRouterDom.Routes, {
children: [
/*#__PURE__*/ jsxRuntime.jsx(reactRouterDom.Route, {
index: true,
element: /*#__PURE__*/ jsxRuntime.jsx(index.ProtectedRolesListPage, {})
}),
/*#__PURE__*/ jsxRuntime.jsx(reactRouterDom.Route, {
path: "new",
element: /*#__PURE__*/ jsxRuntime.jsx(CreatePage.ProtectedRolesCreatePage, {})
}),
/*#__PURE__*/ jsxRuntime.jsx(reactRouterDom.Route, {
path: ":id",
element: /*#__PURE__*/ jsxRuntime.jsx(EditPage.ProtectedRolesEditPage, {})
})
]
})
});
};
module.exports = Roles;
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../../admin/src/pages/Roles/index.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page } from '@strapi/strapi/admin';\nimport { Route, Routes } from 'react-router-dom';\n\nimport { PERMISSIONS } from '../../constants';\n\nimport { ProtectedRolesCreatePage } from './pages/CreatePage';\nimport { ProtectedRolesEditPage } from './pages/EditPage';\nimport { ProtectedRolesListPage } from './pages/ListPage';\n\nconst Roles = () => {\n return (\n <Page.Protect permissions={PERMISSIONS.accessRoles}>\n <Routes>\n <Route index element={<ProtectedRolesListPage />} />\n <Route path=\"new\" element={<ProtectedRolesCreatePage />} />\n <Route path=\":id\" element={<ProtectedRolesEditPage />} />\n </Routes>\n </Page.Protect>\n );\n};\n\nexport default Roles;\n"],"names":["Roles","_jsx","Page","Protect","permissions","PERMISSIONS","accessRoles","_jsxs","Routes","Route","index","element","ProtectedRolesListPage","path","ProtectedRolesCreatePage","ProtectedRolesEditPage"],"mappings":";;;;;;;;;;;AAWA,MAAMA,KAAQ,GAAA,IAAA;IACZ,qBACEC,cAAA,CAACC,WAAKC,OAAO,EAAA;AAACC,QAAAA,WAAAA,EAAaC,sBAAYC,WAAW;AAChD,QAAA,QAAA,gBAAAC,eAACC,CAAAA,qBAAAA,EAAAA;;8BACCP,cAACQ,CAAAA,oBAAAA,EAAAA;oBAAMC,KAAK,EAAA,IAAA;AAACC,oBAAAA,OAAAA,gBAASV,cAACW,CAAAA,4BAAAA,EAAAA,EAAAA;;8BACvBX,cAACQ,CAAAA,oBAAAA,EAAAA;oBAAMI,IAAK,EAAA,KAAA;AAAMF,oBAAAA,OAAAA,gBAASV,cAACa,CAAAA,mCAAAA,EAAAA,EAAAA;;8BAC5Bb,cAACQ,CAAAA,oBAAAA,EAAAA;oBAAMI,IAAK,EAAA,KAAA;AAAMF,oBAAAA,OAAAA,gBAASV,cAACc,CAAAA,+BAAAA,EAAAA,EAAAA;;;;;AAIpC;;;;"}
@@ -0,0 +1,33 @@
import { jsx, jsxs } from 'react/jsx-runtime';
import 'react';
import { Page } from '@strapi/strapi/admin';
import { Routes, Route } from 'react-router-dom';
import { PERMISSIONS } from '../../constants.mjs';
import { ProtectedRolesCreatePage } from './pages/CreatePage.mjs';
import { ProtectedRolesEditPage } from './pages/EditPage.mjs';
import { ProtectedRolesListPage } from './pages/ListPage/index.mjs';
const Roles = ()=>{
return /*#__PURE__*/ jsx(Page.Protect, {
permissions: PERMISSIONS.accessRoles,
children: /*#__PURE__*/ jsxs(Routes, {
children: [
/*#__PURE__*/ jsx(Route, {
index: true,
element: /*#__PURE__*/ jsx(ProtectedRolesListPage, {})
}),
/*#__PURE__*/ jsx(Route, {
path: "new",
element: /*#__PURE__*/ jsx(ProtectedRolesCreatePage, {})
}),
/*#__PURE__*/ jsx(Route, {
path: ":id",
element: /*#__PURE__*/ jsx(ProtectedRolesEditPage, {})
})
]
})
});
};
export { Roles as default };
//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../../../admin/src/pages/Roles/index.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page } from '@strapi/strapi/admin';\nimport { Route, Routes } from 'react-router-dom';\n\nimport { PERMISSIONS } from '../../constants';\n\nimport { ProtectedRolesCreatePage } from './pages/CreatePage';\nimport { ProtectedRolesEditPage } from './pages/EditPage';\nimport { ProtectedRolesListPage } from './pages/ListPage';\n\nconst Roles = () => {\n return (\n <Page.Protect permissions={PERMISSIONS.accessRoles}>\n <Routes>\n <Route index element={<ProtectedRolesListPage />} />\n <Route path=\"new\" element={<ProtectedRolesCreatePage />} />\n <Route path=\":id\" element={<ProtectedRolesEditPage />} />\n </Routes>\n </Page.Protect>\n );\n};\n\nexport default Roles;\n"],"names":["Roles","_jsx","Page","Protect","permissions","PERMISSIONS","accessRoles","_jsxs","Routes","Route","index","element","ProtectedRolesListPage","path","ProtectedRolesCreatePage","ProtectedRolesEditPage"],"mappings":";;;;;;;;;AAWA,MAAMA,KAAQ,GAAA,IAAA;IACZ,qBACEC,GAAA,CAACC,KAAKC,OAAO,EAAA;AAACC,QAAAA,WAAAA,EAAaC,YAAYC,WAAW;AAChD,QAAA,QAAA,gBAAAC,IAACC,CAAAA,MAAAA,EAAAA;;8BACCP,GAACQ,CAAAA,KAAAA,EAAAA;oBAAMC,KAAK,EAAA,IAAA;AAACC,oBAAAA,OAAAA,gBAASV,GAACW,CAAAA,sBAAAA,EAAAA,EAAAA;;8BACvBX,GAACQ,CAAAA,KAAAA,EAAAA;oBAAMI,IAAK,EAAA,KAAA;AAAMF,oBAAAA,OAAAA,gBAASV,GAACa,CAAAA,wBAAAA,EAAAA,EAAAA;;8BAC5Bb,GAACQ,CAAAA,KAAAA,EAAAA;oBAAMI,IAAK,EAAA,KAAA;AAAMF,oBAAAA,OAAAA,gBAASV,GAACc,CAAAA,sBAAAA,EAAAA,EAAAA;;;;;AAIpC;;;;"}
@@ -0,0 +1,225 @@
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var designSystem = require('@strapi/design-system');
var icons = require('@strapi/icons');
var admin = require('@strapi/strapi/admin');
var formik = require('formik');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var reactRouterDom = require('react-router-dom');
var index = require('../../../components/UsersPermissions/index.js');
var constants = require('../../../constants.js');
var getTrad = require('../../../utils/getTrad.js');
var constants$1 = require('../constants.js');
var usePlugins = require('../hooks/usePlugins.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const CreatePage = ()=>{
const { formatMessage } = reactIntl.useIntl();
const { toggleNotification } = admin.useNotification();
const navigate = reactRouterDom.useNavigate();
const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins.usePlugins();
const { trackUsage } = admin.useTracking();
const permissionsRef = React__namespace.useRef();
const { post } = admin.useFetchClient();
const mutation = reactQuery.useMutation((body)=>post(`/users-permissions/roles`, body), {
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error',
defaultMessage: 'An error occurred'
})
});
},
onSuccess () {
trackUsage('didCreateRole');
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad('Settings.roles.created'),
defaultMessage: 'Role created'
})
});
// Forcing redirecting since we don't have the id in the response
navigate(-1);
}
});
const handleCreateRoleSubmit = async (data)=>{
// TODO: refactor. Child -> parent component communication is evil;
// We should either move the provider one level up or move the state
// straight into redux.
const permissions = permissionsRef.current.getPermissions();
await mutation.mutate({
...data,
...permissions,
users: []
});
};
return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Main, {
children: [
/*#__PURE__*/ jsxRuntime.jsx(admin.Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: 'Roles'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(formik.Formik, {
enableReinitialize: true,
initialValues: {
name: '',
description: ''
},
onSubmit: handleCreateRoleSubmit,
validationSchema: constants$1.createRoleSchema,
children: ({ handleSubmit, values, handleChange, errors })=>/*#__PURE__*/ jsxRuntime.jsxs(formik.Form, {
noValidate: true,
onSubmit: handleSubmit,
children: [
/*#__PURE__*/ jsxRuntime.jsx(admin.Layouts.Header, {
primaryAction: !isLoadingPlugins && /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
type: "submit",
loading: mutation.isLoading,
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Check, {}),
children: formatMessage({
id: 'global.save',
defaultMessage: 'Save'
})
}),
title: formatMessage({
id: 'Settings.roles.create.title',
defaultMessage: 'Create a role'
}),
subtitle: formatMessage({
id: 'Settings.roles.create.description',
defaultMessage: 'Define the rights given to the role'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(admin.Layouts.Content, {
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
background: "neutral0",
direction: "column",
alignItems: "stretch",
gap: 7,
hasRadius: true,
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
shadow: "filterShadow",
children: [
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
direction: "column",
alignItems: "stretch",
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: getTrad('EditPage.form.roles'),
defaultMessage: 'Role details'
})
}),
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Grid.Root, {
gap: 4,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "name",
error: errors?.name ? formatMessage({
id: errors.name,
defaultMessage: 'Name is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'global.name',
defaultMessage: 'Name'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.TextInput, {
value: values.name || '',
onChange: handleChange
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Error, {})
]
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "description",
error: errors?.description ? formatMessage({
id: errors.description,
defaultMessage: 'Description is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'global.description',
defaultMessage: 'Description'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Textarea, {
value: values.description || '',
onChange: handleChange
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Error, {})
]
})
})
]
})
]
}),
!isLoadingPlugins && /*#__PURE__*/ jsxRuntime.jsx(index, {
ref: permissionsRef,
permissions: permissions,
routes: routes
})
]
})
})
]
})
})
]
});
};
const ProtectedRolesCreatePage = ()=>/*#__PURE__*/ jsxRuntime.jsx(admin.Page.Protect, {
permissions: constants.PERMISSIONS.createRole,
children: /*#__PURE__*/ jsxRuntime.jsx(CreatePage, {})
});
exports.CreatePage = CreatePage;
exports.ProtectedRolesCreatePage = ProtectedRolesCreatePage;
//# sourceMappingURL=CreatePage.js.map
@@ -0,0 +1 @@
{"version":3,"file":"CreatePage.js","sources":["../../../../../admin/src/pages/Roles/pages/CreatePage.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Button,\n Flex,\n Grid,\n Main,\n Textarea,\n TextInput,\n Typography,\n Field,\n} from '@strapi/design-system';\nimport { Check } from '@strapi/icons';\nimport { Page, useTracking, useNotification, useFetchClient, Layouts } from '@strapi/strapi/admin';\nimport { Formik, Form } from 'formik';\nimport { useIntl } from 'react-intl';\nimport { useMutation } from 'react-query';\nimport { useNavigate } from 'react-router-dom';\n\nimport UsersPermissions from '../../../components/UsersPermissions';\nimport { PERMISSIONS } from '../../../constants';\nimport getTrad from '../../../utils/getTrad';\nimport { createRoleSchema } from '../constants';\nimport { usePlugins } from '../hooks/usePlugins';\n\nexport const CreatePage = () => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const navigate = useNavigate();\n const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();\n const { trackUsage } = useTracking();\n const permissionsRef = React.useRef();\n const { post } = useFetchClient();\n const mutation = useMutation((body) => post(`/users-permissions/roles`, body), {\n onError() {\n toggleNotification({\n type: 'danger',\n message: formatMessage({\n id: 'notification.error',\n defaultMessage: 'An error occurred',\n }),\n });\n },\n\n onSuccess() {\n trackUsage('didCreateRole');\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('Settings.roles.created'),\n defaultMessage: 'Role created',\n }),\n });\n\n // Forcing redirecting since we don't have the id in the response\n navigate(-1);\n },\n });\n\n const handleCreateRoleSubmit = async (data) => {\n // TODO: refactor. Child -> parent component communication is evil;\n // We should either move the provider one level up or move the state\n // straight into redux.\n const permissions = permissionsRef.current.getPermissions();\n\n await mutation.mutate({ ...data, ...permissions, users: [] });\n };\n\n return (\n <Main>\n <Page.Title>\n {formatMessage(\n { id: 'Settings.PageTitle', defaultMessage: 'Settings - {name}' },\n { name: 'Roles' }\n )}\n </Page.Title>\n <Formik\n enableReinitialize\n initialValues={{ name: '', description: '' }}\n onSubmit={handleCreateRoleSubmit}\n validationSchema={createRoleSchema}\n >\n {({ handleSubmit, values, handleChange, errors }) => (\n <Form noValidate onSubmit={handleSubmit}>\n <Layouts.Header\n primaryAction={\n !isLoadingPlugins && (\n <Button type=\"submit\" loading={mutation.isLoading} startIcon={<Check />}>\n {formatMessage({\n id: 'global.save',\n defaultMessage: 'Save',\n })}\n </Button>\n )\n }\n title={formatMessage({\n id: 'Settings.roles.create.title',\n defaultMessage: 'Create a role',\n })}\n subtitle={formatMessage({\n id: 'Settings.roles.create.description',\n defaultMessage: 'Define the rights given to the role',\n })}\n />\n <Layouts.Content>\n <Flex\n background=\"neutral0\"\n direction=\"column\"\n alignItems=\"stretch\"\n gap={7}\n hasRadius\n paddingTop={6}\n paddingBottom={6}\n paddingLeft={7}\n paddingRight={7}\n shadow=\"filterShadow\"\n >\n <Flex direction=\"column\" alignItems=\"stretch\">\n <Typography variant=\"delta\" tag=\"h2\">\n {formatMessage({\n id: getTrad('EditPage.form.roles'),\n defaultMessage: 'Role details',\n })}\n </Typography>\n\n <Grid.Root gap={4}>\n <Grid.Item col={6} direction=\"column\" alignItems=\"stretch\">\n <Field.Root\n name=\"name\"\n error={\n errors?.name\n ? formatMessage({ id: errors.name, defaultMessage: 'Name is required' })\n : false\n }\n required\n >\n <Field.Label>\n {formatMessage({\n id: 'global.name',\n Line truncated
@@ -0,0 +1,203 @@
import { jsx, jsxs } from 'react/jsx-runtime';
import * as React from 'react';
import { Main, Button, Flex, Typography, Grid, Field, TextInput, Textarea } from '@strapi/design-system';
import { Check } from '@strapi/icons';
import { Page, useNotification, useTracking, useFetchClient, Layouts } from '@strapi/strapi/admin';
import { Formik, Form } from 'formik';
import { useIntl } from 'react-intl';
import { useMutation } from 'react-query';
import { useNavigate } from 'react-router-dom';
import UsersPermissions from '../../../components/UsersPermissions/index.mjs';
import { PERMISSIONS } from '../../../constants.mjs';
import getTrad from '../../../utils/getTrad.mjs';
import { createRoleSchema } from '../constants.mjs';
import { usePlugins } from '../hooks/usePlugins.mjs';
const CreatePage = ()=>{
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const navigate = useNavigate();
const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();
const { trackUsage } = useTracking();
const permissionsRef = React.useRef();
const { post } = useFetchClient();
const mutation = useMutation((body)=>post(`/users-permissions/roles`, body), {
onError () {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error',
defaultMessage: 'An error occurred'
})
});
},
onSuccess () {
trackUsage('didCreateRole');
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad('Settings.roles.created'),
defaultMessage: 'Role created'
})
});
// Forcing redirecting since we don't have the id in the response
navigate(-1);
}
});
const handleCreateRoleSubmit = async (data)=>{
// TODO: refactor. Child -> parent component communication is evil;
// We should either move the provider one level up or move the state
// straight into redux.
const permissions = permissionsRef.current.getPermissions();
await mutation.mutate({
...data,
...permissions,
users: []
});
};
return /*#__PURE__*/ jsxs(Main, {
children: [
/*#__PURE__*/ jsx(Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: 'Roles'
})
}),
/*#__PURE__*/ jsx(Formik, {
enableReinitialize: true,
initialValues: {
name: '',
description: ''
},
onSubmit: handleCreateRoleSubmit,
validationSchema: createRoleSchema,
children: ({ handleSubmit, values, handleChange, errors })=>/*#__PURE__*/ jsxs(Form, {
noValidate: true,
onSubmit: handleSubmit,
children: [
/*#__PURE__*/ jsx(Layouts.Header, {
primaryAction: !isLoadingPlugins && /*#__PURE__*/ jsx(Button, {
type: "submit",
loading: mutation.isLoading,
startIcon: /*#__PURE__*/ jsx(Check, {}),
children: formatMessage({
id: 'global.save',
defaultMessage: 'Save'
})
}),
title: formatMessage({
id: 'Settings.roles.create.title',
defaultMessage: 'Create a role'
}),
subtitle: formatMessage({
id: 'Settings.roles.create.description',
defaultMessage: 'Define the rights given to the role'
})
}),
/*#__PURE__*/ jsx(Layouts.Content, {
children: /*#__PURE__*/ jsxs(Flex, {
background: "neutral0",
direction: "column",
alignItems: "stretch",
gap: 7,
hasRadius: true,
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
shadow: "filterShadow",
children: [
/*#__PURE__*/ jsxs(Flex, {
direction: "column",
alignItems: "stretch",
children: [
/*#__PURE__*/ jsx(Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: getTrad('EditPage.form.roles'),
defaultMessage: 'Role details'
})
}),
/*#__PURE__*/ jsxs(Grid.Root, {
gap: 4,
children: [
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "name",
error: errors?.name ? formatMessage({
id: errors.name,
defaultMessage: 'Name is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'global.name',
defaultMessage: 'Name'
})
}),
/*#__PURE__*/ jsx(TextInput, {
value: values.name || '',
onChange: handleChange
}),
/*#__PURE__*/ jsx(Field.Error, {})
]
})
}),
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "description",
error: errors?.description ? formatMessage({
id: errors.description,
defaultMessage: 'Description is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'global.description',
defaultMessage: 'Description'
})
}),
/*#__PURE__*/ jsx(Textarea, {
value: values.description || '',
onChange: handleChange
}),
/*#__PURE__*/ jsx(Field.Error, {})
]
})
})
]
})
]
}),
!isLoadingPlugins && /*#__PURE__*/ jsx(UsersPermissions, {
ref: permissionsRef,
permissions: permissions,
routes: routes
})
]
})
})
]
})
})
]
});
};
const ProtectedRolesCreatePage = ()=>/*#__PURE__*/ jsx(Page.Protect, {
permissions: PERMISSIONS.createRole,
children: /*#__PURE__*/ jsx(CreatePage, {})
});
export { CreatePage, ProtectedRolesCreatePage };
//# sourceMappingURL=CreatePage.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"CreatePage.mjs","sources":["../../../../../admin/src/pages/Roles/pages/CreatePage.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Button,\n Flex,\n Grid,\n Main,\n Textarea,\n TextInput,\n Typography,\n Field,\n} from '@strapi/design-system';\nimport { Check } from '@strapi/icons';\nimport { Page, useTracking, useNotification, useFetchClient, Layouts } from '@strapi/strapi/admin';\nimport { Formik, Form } from 'formik';\nimport { useIntl } from 'react-intl';\nimport { useMutation } from 'react-query';\nimport { useNavigate } from 'react-router-dom';\n\nimport UsersPermissions from '../../../components/UsersPermissions';\nimport { PERMISSIONS } from '../../../constants';\nimport getTrad from '../../../utils/getTrad';\nimport { createRoleSchema } from '../constants';\nimport { usePlugins } from '../hooks/usePlugins';\n\nexport const CreatePage = () => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const navigate = useNavigate();\n const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();\n const { trackUsage } = useTracking();\n const permissionsRef = React.useRef();\n const { post } = useFetchClient();\n const mutation = useMutation((body) => post(`/users-permissions/roles`, body), {\n onError() {\n toggleNotification({\n type: 'danger',\n message: formatMessage({\n id: 'notification.error',\n defaultMessage: 'An error occurred',\n }),\n });\n },\n\n onSuccess() {\n trackUsage('didCreateRole');\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('Settings.roles.created'),\n defaultMessage: 'Role created',\n }),\n });\n\n // Forcing redirecting since we don't have the id in the response\n navigate(-1);\n },\n });\n\n const handleCreateRoleSubmit = async (data) => {\n // TODO: refactor. Child -> parent component communication is evil;\n // We should either move the provider one level up or move the state\n // straight into redux.\n const permissions = permissionsRef.current.getPermissions();\n\n await mutation.mutate({ ...data, ...permissions, users: [] });\n };\n\n return (\n <Main>\n <Page.Title>\n {formatMessage(\n { id: 'Settings.PageTitle', defaultMessage: 'Settings - {name}' },\n { name: 'Roles' }\n )}\n </Page.Title>\n <Formik\n enableReinitialize\n initialValues={{ name: '', description: '' }}\n onSubmit={handleCreateRoleSubmit}\n validationSchema={createRoleSchema}\n >\n {({ handleSubmit, values, handleChange, errors }) => (\n <Form noValidate onSubmit={handleSubmit}>\n <Layouts.Header\n primaryAction={\n !isLoadingPlugins && (\n <Button type=\"submit\" loading={mutation.isLoading} startIcon={<Check />}>\n {formatMessage({\n id: 'global.save',\n defaultMessage: 'Save',\n })}\n </Button>\n )\n }\n title={formatMessage({\n id: 'Settings.roles.create.title',\n defaultMessage: 'Create a role',\n })}\n subtitle={formatMessage({\n id: 'Settings.roles.create.description',\n defaultMessage: 'Define the rights given to the role',\n })}\n />\n <Layouts.Content>\n <Flex\n background=\"neutral0\"\n direction=\"column\"\n alignItems=\"stretch\"\n gap={7}\n hasRadius\n paddingTop={6}\n paddingBottom={6}\n paddingLeft={7}\n paddingRight={7}\n shadow=\"filterShadow\"\n >\n <Flex direction=\"column\" alignItems=\"stretch\">\n <Typography variant=\"delta\" tag=\"h2\">\n {formatMessage({\n id: getTrad('EditPage.form.roles'),\n defaultMessage: 'Role details',\n })}\n </Typography>\n\n <Grid.Root gap={4}>\n <Grid.Item col={6} direction=\"column\" alignItems=\"stretch\">\n <Field.Root\n name=\"name\"\n error={\n errors?.name\n ? formatMessage({ id: errors.name, defaultMessage: 'Name is required' })\n : false\n }\n required\n >\n <Field.Label>\n {formatMessage({\n id: 'global.name',\n Line truncated
@@ -0,0 +1,229 @@
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var designSystem = require('@strapi/design-system');
var icons = require('@strapi/icons');
var admin = require('@strapi/strapi/admin');
var formik = require('formik');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var reactRouterDom = require('react-router-dom');
var index = require('../../../components/UsersPermissions/index.js');
var constants = require('../../../constants.js');
var getTrad = require('../../../utils/getTrad.js');
var constants$1 = require('../constants.js');
var usePlugins = require('../hooks/usePlugins.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const EditPage = ()=>{
const { formatMessage } = reactIntl.useIntl();
const { toggleNotification } = admin.useNotification();
const { params: { id } } = reactRouterDom.useMatch(`/settings/users-permissions/roles/:id`);
const { get } = admin.useFetchClient();
const { isLoading: isLoadingPlugins, routes } = usePlugins.usePlugins();
const { data: role, isLoading: isLoadingRole, refetch: refetchRole } = reactQuery.useQuery([
'users-permissions',
'role',
id
], async ()=>{
// TODO: why doesn't this endpoint follow the admin API conventions?
const { data: { role } } = await get(`/users-permissions/roles/${id}`);
return role;
});
const permissionsRef = React__namespace.useRef();
const { put } = admin.useFetchClient();
const { formatAPIError } = admin.useAPIErrorHandler();
const mutation = reactQuery.useMutation((body)=>put(`/users-permissions/roles/${id}`, body), {
onError (error) {
toggleNotification({
type: 'danger',
message: formatAPIError(error)
});
},
async onSuccess () {
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad('Settings.roles.created'),
defaultMessage: 'Role edited'
})
});
await refetchRole();
}
});
const handleEditRoleSubmit = async (data)=>{
const permissions = permissionsRef.current.getPermissions();
await mutation.mutate({
...data,
...permissions,
users: []
});
};
if (isLoadingRole) {
return /*#__PURE__*/ jsxRuntime.jsx(admin.Page.Loading, {});
}
return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Main, {
children: [
/*#__PURE__*/ jsxRuntime.jsx(admin.Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: 'Roles'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(formik.Formik, {
enableReinitialize: true,
initialValues: {
name: role.name,
description: role.description
},
onSubmit: handleEditRoleSubmit,
validationSchema: constants$1.createRoleSchema,
children: ({ handleSubmit, values, handleChange, errors })=>/*#__PURE__*/ jsxRuntime.jsxs(formik.Form, {
noValidate: true,
onSubmit: handleSubmit,
children: [
/*#__PURE__*/ jsxRuntime.jsx(admin.Layouts.Header, {
primaryAction: !isLoadingPlugins ? /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
disabled: role.code === 'strapi-super-admin',
type: "submit",
loading: mutation.isLoading,
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Check, {}),
children: formatMessage({
id: 'global.save',
defaultMessage: 'Save'
})
}) : null,
title: role.name,
subtitle: role.description,
navigationAction: /*#__PURE__*/ jsxRuntime.jsx(admin.BackButton, {
fallback: ".."
})
}),
/*#__PURE__*/ jsxRuntime.jsx(admin.Layouts.Content, {
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
background: "neutral0",
direction: "column",
alignItems: "stretch",
gap: 7,
hasRadius: true,
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
shadow: "filterShadow",
children: [
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
direction: "column",
alignItems: "stretch",
gap: 4,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: getTrad('EditPage.form.roles'),
defaultMessage: 'Role details'
})
}),
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Grid.Root, {
gap: 4,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "name",
error: errors?.name ? formatMessage({
id: errors.name,
defaultMessage: 'Name is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'global.name',
defaultMessage: 'Name'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.TextInput, {
value: values.name || '',
onChange: handleChange
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Error, {})
]
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
name: "description",
error: errors?.description ? formatMessage({
id: errors.description,
defaultMessage: 'Description is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
children: formatMessage({
id: 'global.description',
defaultMessage: 'Description'
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Textarea, {
value: values.description || '',
onChange: handleChange
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Error, {})
]
})
})
]
})
]
}),
!isLoadingPlugins && /*#__PURE__*/ jsxRuntime.jsx(index, {
ref: permissionsRef,
permissions: role.permissions,
routes: routes
})
]
})
})
]
})
})
]
});
};
const ProtectedRolesEditPage = ()=>/*#__PURE__*/ jsxRuntime.jsx(admin.Page.Protect, {
permissions: constants.PERMISSIONS.updateRole,
children: /*#__PURE__*/ jsxRuntime.jsx(EditPage, {})
});
exports.EditPage = EditPage;
exports.ProtectedRolesEditPage = ProtectedRolesEditPage;
//# sourceMappingURL=EditPage.js.map
@@ -0,0 +1 @@
{"version":3,"file":"EditPage.js","sources":["../../../../../admin/src/pages/Roles/pages/EditPage.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Main,\n Button,\n Flex,\n TextInput,\n Textarea,\n Typography,\n Grid,\n Field,\n} from '@strapi/design-system';\nimport { Check } from '@strapi/icons';\nimport {\n Page,\n BackButton,\n useAPIErrorHandler,\n useNotification,\n useFetchClient,\n Layouts,\n} from '@strapi/strapi/admin';\nimport { Formik, Form } from 'formik';\nimport { useIntl } from 'react-intl';\nimport { useQuery, useMutation } from 'react-query';\nimport { useMatch } from 'react-router-dom';\n\nimport UsersPermissions from '../../../components/UsersPermissions';\nimport { PERMISSIONS } from '../../../constants';\nimport getTrad from '../../../utils/getTrad';\nimport { createRoleSchema } from '../constants';\nimport { usePlugins } from '../hooks/usePlugins';\n\nexport const EditPage = () => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const {\n params: { id },\n } = useMatch(`/settings/users-permissions/roles/:id`);\n const { get } = useFetchClient();\n const { isLoading: isLoadingPlugins, routes } = usePlugins();\n const {\n data: role,\n isLoading: isLoadingRole,\n refetch: refetchRole,\n } = useQuery(['users-permissions', 'role', id], async () => {\n // TODO: why doesn't this endpoint follow the admin API conventions?\n const {\n data: { role },\n } = await get(`/users-permissions/roles/${id}`);\n\n return role;\n });\n\n const permissionsRef = React.useRef();\n const { put } = useFetchClient();\n const { formatAPIError } = useAPIErrorHandler();\n const mutation = useMutation((body) => put(`/users-permissions/roles/${id}`, body), {\n onError(error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n },\n\n async onSuccess() {\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('Settings.roles.created'),\n defaultMessage: 'Role edited',\n }),\n });\n\n await refetchRole();\n },\n });\n\n const handleEditRoleSubmit = async (data) => {\n const permissions = permissionsRef.current.getPermissions();\n\n await mutation.mutate({ ...data, ...permissions, users: [] });\n };\n\n if (isLoadingRole) {\n return <Page.Loading />;\n }\n\n return (\n <Main>\n <Page.Title>\n {formatMessage(\n { id: 'Settings.PageTitle', defaultMessage: 'Settings - {name}' },\n { name: 'Roles' }\n )}\n </Page.Title>\n <Formik\n enableReinitialize\n initialValues={{ name: role.name, description: role.description }}\n onSubmit={handleEditRoleSubmit}\n validationSchema={createRoleSchema}\n >\n {({ handleSubmit, values, handleChange, errors }) => (\n <Form noValidate onSubmit={handleSubmit}>\n <Layouts.Header\n primaryAction={\n !isLoadingPlugins ? (\n <Button\n disabled={role.code === 'strapi-super-admin'}\n type=\"submit\"\n loading={mutation.isLoading}\n startIcon={<Check />}\n >\n {formatMessage({\n id: 'global.save',\n defaultMessage: 'Save',\n })}\n </Button>\n ) : null\n }\n title={role.name}\n subtitle={role.description}\n navigationAction={<BackButton fallback=\"..\" />}\n />\n <Layouts.Content>\n <Flex\n background=\"neutral0\"\n direction=\"column\"\n alignItems=\"stretch\"\n gap={7}\n hasRadius\n paddingTop={6}\n paddingBottom={6}\n paddingLeft={7}\n paddingRight={7}\n shadow=\"filterShadow\"\n >\n <Flex direction=\"column\" alignItems=\"stretch\" gap={4}>\n <Typography variant=\"delta\" tag=\"h2\">\n {formatMessage({\n id: getTrad('EditPage.form.roles'),\n defaultMessage: 'Role details',\n })}\n </Typography>\n\n <Grid.Root gap={4}>\n <Grid.Item col={6} direction=\"column\" alignItems=\"stretch\">\n <Field.Root\n name=\"name\"\n error={\n errors?.name\n ? formatMessage({\n id: errors.name,\n defaultMessage: 'Name is required',\n })\n Line truncated
@@ -0,0 +1,207 @@
import { jsx, jsxs } from 'react/jsx-runtime';
import * as React from 'react';
import { Main, Button, Flex, Typography, Grid, Field, TextInput, Textarea } from '@strapi/design-system';
import { Check } from '@strapi/icons';
import { Page, useNotification, useFetchClient, useAPIErrorHandler, Layouts, BackButton } from '@strapi/strapi/admin';
import { Formik, Form } from 'formik';
import { useIntl } from 'react-intl';
import { useQuery, useMutation } from 'react-query';
import { useMatch } from 'react-router-dom';
import UsersPermissions from '../../../components/UsersPermissions/index.mjs';
import { PERMISSIONS } from '../../../constants.mjs';
import getTrad from '../../../utils/getTrad.mjs';
import { createRoleSchema } from '../constants.mjs';
import { usePlugins } from '../hooks/usePlugins.mjs';
const EditPage = ()=>{
const { formatMessage } = useIntl();
const { toggleNotification } = useNotification();
const { params: { id } } = useMatch(`/settings/users-permissions/roles/:id`);
const { get } = useFetchClient();
const { isLoading: isLoadingPlugins, routes } = usePlugins();
const { data: role, isLoading: isLoadingRole, refetch: refetchRole } = useQuery([
'users-permissions',
'role',
id
], async ()=>{
// TODO: why doesn't this endpoint follow the admin API conventions?
const { data: { role } } = await get(`/users-permissions/roles/${id}`);
return role;
});
const permissionsRef = React.useRef();
const { put } = useFetchClient();
const { formatAPIError } = useAPIErrorHandler();
const mutation = useMutation((body)=>put(`/users-permissions/roles/${id}`, body), {
onError (error) {
toggleNotification({
type: 'danger',
message: formatAPIError(error)
});
},
async onSuccess () {
toggleNotification({
type: 'success',
message: formatMessage({
id: getTrad('Settings.roles.created'),
defaultMessage: 'Role edited'
})
});
await refetchRole();
}
});
const handleEditRoleSubmit = async (data)=>{
const permissions = permissionsRef.current.getPermissions();
await mutation.mutate({
...data,
...permissions,
users: []
});
};
if (isLoadingRole) {
return /*#__PURE__*/ jsx(Page.Loading, {});
}
return /*#__PURE__*/ jsxs(Main, {
children: [
/*#__PURE__*/ jsx(Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: 'Roles'
})
}),
/*#__PURE__*/ jsx(Formik, {
enableReinitialize: true,
initialValues: {
name: role.name,
description: role.description
},
onSubmit: handleEditRoleSubmit,
validationSchema: createRoleSchema,
children: ({ handleSubmit, values, handleChange, errors })=>/*#__PURE__*/ jsxs(Form, {
noValidate: true,
onSubmit: handleSubmit,
children: [
/*#__PURE__*/ jsx(Layouts.Header, {
primaryAction: !isLoadingPlugins ? /*#__PURE__*/ jsx(Button, {
disabled: role.code === 'strapi-super-admin',
type: "submit",
loading: mutation.isLoading,
startIcon: /*#__PURE__*/ jsx(Check, {}),
children: formatMessage({
id: 'global.save',
defaultMessage: 'Save'
})
}) : null,
title: role.name,
subtitle: role.description,
navigationAction: /*#__PURE__*/ jsx(BackButton, {
fallback: ".."
})
}),
/*#__PURE__*/ jsx(Layouts.Content, {
children: /*#__PURE__*/ jsxs(Flex, {
background: "neutral0",
direction: "column",
alignItems: "stretch",
gap: 7,
hasRadius: true,
paddingTop: 6,
paddingBottom: 6,
paddingLeft: 7,
paddingRight: 7,
shadow: "filterShadow",
children: [
/*#__PURE__*/ jsxs(Flex, {
direction: "column",
alignItems: "stretch",
gap: 4,
children: [
/*#__PURE__*/ jsx(Typography, {
variant: "delta",
tag: "h2",
children: formatMessage({
id: getTrad('EditPage.form.roles'),
defaultMessage: 'Role details'
})
}),
/*#__PURE__*/ jsxs(Grid.Root, {
gap: 4,
children: [
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "name",
error: errors?.name ? formatMessage({
id: errors.name,
defaultMessage: 'Name is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'global.name',
defaultMessage: 'Name'
})
}),
/*#__PURE__*/ jsx(TextInput, {
value: values.name || '',
onChange: handleChange
}),
/*#__PURE__*/ jsx(Field.Error, {})
]
})
}),
/*#__PURE__*/ jsx(Grid.Item, {
col: 6,
direction: "column",
alignItems: "stretch",
children: /*#__PURE__*/ jsxs(Field.Root, {
name: "description",
error: errors?.description ? formatMessage({
id: errors.description,
defaultMessage: 'Description is required'
}) : false,
required: true,
children: [
/*#__PURE__*/ jsx(Field.Label, {
children: formatMessage({
id: 'global.description',
defaultMessage: 'Description'
})
}),
/*#__PURE__*/ jsx(Textarea, {
value: values.description || '',
onChange: handleChange
}),
/*#__PURE__*/ jsx(Field.Error, {})
]
})
})
]
})
]
}),
!isLoadingPlugins && /*#__PURE__*/ jsx(UsersPermissions, {
ref: permissionsRef,
permissions: role.permissions,
routes: routes
})
]
})
})
]
})
})
]
});
};
const ProtectedRolesEditPage = ()=>/*#__PURE__*/ jsx(Page.Protect, {
permissions: PERMISSIONS.updateRole,
children: /*#__PURE__*/ jsx(EditPage, {})
});
export { EditPage, ProtectedRolesEditPage };
//# sourceMappingURL=EditPage.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"EditPage.mjs","sources":["../../../../../admin/src/pages/Roles/pages/EditPage.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Main,\n Button,\n Flex,\n TextInput,\n Textarea,\n Typography,\n Grid,\n Field,\n} from '@strapi/design-system';\nimport { Check } from '@strapi/icons';\nimport {\n Page,\n BackButton,\n useAPIErrorHandler,\n useNotification,\n useFetchClient,\n Layouts,\n} from '@strapi/strapi/admin';\nimport { Formik, Form } from 'formik';\nimport { useIntl } from 'react-intl';\nimport { useQuery, useMutation } from 'react-query';\nimport { useMatch } from 'react-router-dom';\n\nimport UsersPermissions from '../../../components/UsersPermissions';\nimport { PERMISSIONS } from '../../../constants';\nimport getTrad from '../../../utils/getTrad';\nimport { createRoleSchema } from '../constants';\nimport { usePlugins } from '../hooks/usePlugins';\n\nexport const EditPage = () => {\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const {\n params: { id },\n } = useMatch(`/settings/users-permissions/roles/:id`);\n const { get } = useFetchClient();\n const { isLoading: isLoadingPlugins, routes } = usePlugins();\n const {\n data: role,\n isLoading: isLoadingRole,\n refetch: refetchRole,\n } = useQuery(['users-permissions', 'role', id], async () => {\n // TODO: why doesn't this endpoint follow the admin API conventions?\n const {\n data: { role },\n } = await get(`/users-permissions/roles/${id}`);\n\n return role;\n });\n\n const permissionsRef = React.useRef();\n const { put } = useFetchClient();\n const { formatAPIError } = useAPIErrorHandler();\n const mutation = useMutation((body) => put(`/users-permissions/roles/${id}`, body), {\n onError(error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n },\n\n async onSuccess() {\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('Settings.roles.created'),\n defaultMessage: 'Role edited',\n }),\n });\n\n await refetchRole();\n },\n });\n\n const handleEditRoleSubmit = async (data) => {\n const permissions = permissionsRef.current.getPermissions();\n\n await mutation.mutate({ ...data, ...permissions, users: [] });\n };\n\n if (isLoadingRole) {\n return <Page.Loading />;\n }\n\n return (\n <Main>\n <Page.Title>\n {formatMessage(\n { id: 'Settings.PageTitle', defaultMessage: 'Settings - {name}' },\n { name: 'Roles' }\n )}\n </Page.Title>\n <Formik\n enableReinitialize\n initialValues={{ name: role.name, description: role.description }}\n onSubmit={handleEditRoleSubmit}\n validationSchema={createRoleSchema}\n >\n {({ handleSubmit, values, handleChange, errors }) => (\n <Form noValidate onSubmit={handleSubmit}>\n <Layouts.Header\n primaryAction={\n !isLoadingPlugins ? (\n <Button\n disabled={role.code === 'strapi-super-admin'}\n type=\"submit\"\n loading={mutation.isLoading}\n startIcon={<Check />}\n >\n {formatMessage({\n id: 'global.save',\n defaultMessage: 'Save',\n })}\n </Button>\n ) : null\n }\n title={role.name}\n subtitle={role.description}\n navigationAction={<BackButton fallback=\"..\" />}\n />\n <Layouts.Content>\n <Flex\n background=\"neutral0\"\n direction=\"column\"\n alignItems=\"stretch\"\n gap={7}\n hasRadius\n paddingTop={6}\n paddingBottom={6}\n paddingLeft={7}\n paddingRight={7}\n shadow=\"filterShadow\"\n >\n <Flex direction=\"column\" alignItems=\"stretch\" gap={4}>\n <Typography variant=\"delta\" tag=\"h2\">\n {formatMessage({\n id: getTrad('EditPage.form.roles'),\n defaultMessage: 'Role details',\n })}\n </Typography>\n\n <Grid.Root gap={4}>\n <Grid.Item col={6} direction=\"column\" alignItems=\"stretch\">\n <Field.Root\n name=\"name\"\n error={\n errors?.name\n ? formatMessage({\n id: errors.name,\n defaultMessage: 'Name is required',\n })\n Line truncated
@@ -0,0 +1,125 @@
'use strict';
var jsxRuntime = require('react/jsx-runtime');
require('react');
var designSystem = require('@strapi/design-system');
var icons = require('@strapi/icons');
var PropTypes = require('prop-types');
var reactIntl = require('react-intl');
var reactRouterDom = require('react-router-dom');
var styledComponents = require('styled-components');
const EditLink = styledComponents.styled(designSystem.Link)`
align-items: center;
height: 3.2rem;
width: 3.2rem;
display: flex;
justify-content: center;
padding: ${({ theme })=>`${theme.spaces[2]}`};
svg {
height: 1.6rem;
width: 1.6rem;
path {
fill: ${({ theme })=>theme.colors.neutral500};
}
}
&:hover,
&:focus {
svg {
path {
fill: ${({ theme })=>theme.colors.neutral800};
}
}
}
`;
const TableBody = ({ sortedRoles, canDelete, canUpdate, setRoleToDelete, onDelete })=>{
const { formatMessage } = reactIntl.useIntl();
const navigate = reactRouterDom.useNavigate();
const [showConfirmDelete, setShowConfirmDelete] = onDelete;
const checkCanDeleteRole = (role)=>canDelete && ![
'public',
'authenticated'
].includes(role.type);
const handleClickDelete = (id)=>{
setRoleToDelete(id);
setShowConfirmDelete(!showConfirmDelete);
};
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Tbody, {
children: sortedRoles?.map((role)=>/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Tr, {
cursor: "pointer",
onClick: ()=>navigate(role.id.toString()),
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Td, {
width: "20%",
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
children: role.name
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Td, {
width: "50%",
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
children: role.description
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Td, {
width: "30%",
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
children: formatMessage({
id: 'Roles.RoleRow.user-count',
defaultMessage: '{number, plural, =0 {# user} one {# user} other {# users}}'
}, {
number: role.nb_users
})
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Td, {
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
justifyContent: "end",
onClick: (e)=>e.stopPropagation(),
children: [
canUpdate ? /*#__PURE__*/ jsxRuntime.jsx(EditLink, {
tag: reactRouterDom.NavLink,
to: role.id.toString(),
"aria-label": formatMessage({
id: 'app.component.table.edit',
defaultMessage: 'Edit {target}'
}, {
target: `${role.name}`
}),
children: /*#__PURE__*/ jsxRuntime.jsx(icons.Pencil, {})
}) : null,
checkCanDeleteRole(role) && /*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
onClick: ()=>handleClickDelete(role.id.toString()),
variant: "ghost",
label: formatMessage({
id: 'global.delete-target',
defaultMessage: 'Delete {target}'
}, {
target: `${role.name}`
}),
children: /*#__PURE__*/ jsxRuntime.jsx(icons.Trash, {})
})
]
})
})
]
}, role.name))
});
};
TableBody.defaultProps = {
canDelete: false,
canUpdate: false
};
TableBody.propTypes = {
onDelete: PropTypes.array.isRequired,
setRoleToDelete: PropTypes.func.isRequired,
sortedRoles: PropTypes.array.isRequired,
canDelete: PropTypes.bool,
canUpdate: PropTypes.bool
};
module.exports = TableBody;
//# sourceMappingURL=TableBody.js.map
@@ -0,0 +1 @@
{"version":3,"file":"TableBody.js","sources":["../../../../../../../admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Flex, IconButton, Link, Tbody, Td, Tr, Typography } from '@strapi/design-system';\nimport { Pencil, Trash } from '@strapi/icons';\nimport PropTypes from 'prop-types';\nimport { useIntl } from 'react-intl';\nimport { useNavigate, NavLink } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nconst EditLink = styled(Link)`\n align-items: center;\n height: 3.2rem;\n width: 3.2rem;\n display: flex;\n justify-content: center;\n padding: ${({ theme }) => `${theme.spaces[2]}`};\n\n svg {\n height: 1.6rem;\n width: 1.6rem;\n\n path {\n fill: ${({ theme }) => theme.colors.neutral500};\n }\n }\n\n &:hover,\n &:focus {\n svg {\n path {\n fill: ${({ theme }) => theme.colors.neutral800};\n }\n }\n }\n`;\n\nconst TableBody = ({ sortedRoles, canDelete, canUpdate, setRoleToDelete, onDelete }) => {\n const { formatMessage } = useIntl();\n const navigate = useNavigate();\n const [showConfirmDelete, setShowConfirmDelete] = onDelete;\n\n const checkCanDeleteRole = (role) =>\n canDelete && !['public', 'authenticated'].includes(role.type);\n\n const handleClickDelete = (id) => {\n setRoleToDelete(id);\n setShowConfirmDelete(!showConfirmDelete);\n };\n\n return (\n <Tbody>\n {sortedRoles?.map((role) => (\n <Tr cursor=\"pointer\" key={role.name} onClick={() => navigate(role.id.toString())}>\n <Td width=\"20%\">\n <Typography>{role.name}</Typography>\n </Td>\n <Td width=\"50%\">\n <Typography>{role.description}</Typography>\n </Td>\n <Td width=\"30%\">\n <Typography>\n {formatMessage(\n {\n id: 'Roles.RoleRow.user-count',\n defaultMessage: '{number, plural, =0 {# user} one {# user} other {# users}}',\n },\n { number: role.nb_users }\n )}\n </Typography>\n </Td>\n <Td>\n <Flex justifyContent=\"end\" onClick={(e) => e.stopPropagation()}>\n {canUpdate ? (\n <EditLink\n tag={NavLink}\n to={role.id.toString()}\n aria-label={formatMessage(\n { id: 'app.component.table.edit', defaultMessage: 'Edit {target}' },\n { target: `${role.name}` }\n )}\n >\n <Pencil />\n </EditLink>\n ) : null}\n\n {checkCanDeleteRole(role) && (\n <IconButton\n onClick={() => handleClickDelete(role.id.toString())}\n variant=\"ghost\"\n label={formatMessage(\n { id: 'global.delete-target', defaultMessage: 'Delete {target}' },\n { target: `${role.name}` }\n )}\n >\n <Trash />\n </IconButton>\n )}\n </Flex>\n </Td>\n </Tr>\n ))}\n </Tbody>\n );\n};\n\nexport default TableBody;\n\nTableBody.defaultProps = {\n canDelete: false,\n canUpdate: false,\n};\n\nTableBody.propTypes = {\n onDelete: PropTypes.array.isRequired,\n setRoleToDelete: PropTypes.func.isRequired,\n sortedRoles: PropTypes.array.isRequired,\n canDelete: PropTypes.bool,\n canUpdate: PropTypes.bool,\n};\n"],"names":["EditLink","styled","Link","theme","spaces","colors","neutral500","neutral800","TableBody","sortedRoles","canDelete","canUpdate","setRoleToDelete","onDelete","formatMessage","useIntl","navigate","useNavigate","showConfirmDelete","setShowConfirmDelete","checkCanDeleteRole","role","includes","type","handleClickDelete","id","_jsx","Tbody","map","_jsxs","Tr","cursor","onClick","toString","Td","width","Typography","name","description","defaultMessage","number","nb_users","Flex","justifyContent","e","stopPropagation","tag","NavLink","to","aria-label","target","Pencil","IconButton","variant","label","Trash","defaultProps","propTypes","PropTypes","array","isRequired","func","bool"],"mappings":";;;;;;;;;;;AASA,MAAMA,QAAAA,GAAWC,uBAAOC,CAAAA,iBAAAA,CAAK;;;;;;AAMlB,WAAA,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAK,CAAC,EAAEA,KAAAA,CAAMC,MAAM,CAAC,CAAE,CAAA,CAAC,CAAC,CAAC;;;;;;;YAOrC,EAAE,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAME,CAAAA,MAAM,CAACC,UAAU,CAAC;;;;;;;;cAQvC,EAAE,CAAC,EAAEH,KAAK,EAAE,GAAKA,KAAME,CAAAA,MAAM,CAACE,UAAU,CAAC;;;;AAIvD,CAAC;AAED,MAAMC,SAAY,GAAA,CAAC,EAAEC,WAAW,EAAEC,SAAS,EAAEC,SAAS,EAAEC,eAAe,EAAEC,QAAQ,EAAE,GAAA;IACjF,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAMC,QAAWC,GAAAA,0BAAAA,EAAAA;IACjB,MAAM,CAACC,iBAAmBC,EAAAA,oBAAAA,CAAqB,GAAGN,QAAAA;AAElD,IAAA,MAAMO,kBAAqB,GAAA,CAACC,IAC1BX,GAAAA,SAAAA,IAAa,CAAC;AAAC,YAAA,QAAA;AAAU,YAAA;SAAgB,CAACY,QAAQ,CAACD,IAAAA,CAALine truncated
@@ -0,0 +1,123 @@
import { jsx, jsxs } from 'react/jsx-runtime';
import 'react';
import { Link, Tbody, Tr, Td, Typography, Flex, IconButton } from '@strapi/design-system';
import { Pencil, Trash } from '@strapi/icons';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { useNavigate, NavLink } from 'react-router-dom';
import { styled } from 'styled-components';
const EditLink = styled(Link)`
align-items: center;
height: 3.2rem;
width: 3.2rem;
display: flex;
justify-content: center;
padding: ${({ theme })=>`${theme.spaces[2]}`};
svg {
height: 1.6rem;
width: 1.6rem;
path {
fill: ${({ theme })=>theme.colors.neutral500};
}
}
&:hover,
&:focus {
svg {
path {
fill: ${({ theme })=>theme.colors.neutral800};
}
}
}
`;
const TableBody = ({ sortedRoles, canDelete, canUpdate, setRoleToDelete, onDelete })=>{
const { formatMessage } = useIntl();
const navigate = useNavigate();
const [showConfirmDelete, setShowConfirmDelete] = onDelete;
const checkCanDeleteRole = (role)=>canDelete && ![
'public',
'authenticated'
].includes(role.type);
const handleClickDelete = (id)=>{
setRoleToDelete(id);
setShowConfirmDelete(!showConfirmDelete);
};
return /*#__PURE__*/ jsx(Tbody, {
children: sortedRoles?.map((role)=>/*#__PURE__*/ jsxs(Tr, {
cursor: "pointer",
onClick: ()=>navigate(role.id.toString()),
children: [
/*#__PURE__*/ jsx(Td, {
width: "20%",
children: /*#__PURE__*/ jsx(Typography, {
children: role.name
})
}),
/*#__PURE__*/ jsx(Td, {
width: "50%",
children: /*#__PURE__*/ jsx(Typography, {
children: role.description
})
}),
/*#__PURE__*/ jsx(Td, {
width: "30%",
children: /*#__PURE__*/ jsx(Typography, {
children: formatMessage({
id: 'Roles.RoleRow.user-count',
defaultMessage: '{number, plural, =0 {# user} one {# user} other {# users}}'
}, {
number: role.nb_users
})
})
}),
/*#__PURE__*/ jsx(Td, {
children: /*#__PURE__*/ jsxs(Flex, {
justifyContent: "end",
onClick: (e)=>e.stopPropagation(),
children: [
canUpdate ? /*#__PURE__*/ jsx(EditLink, {
tag: NavLink,
to: role.id.toString(),
"aria-label": formatMessage({
id: 'app.component.table.edit',
defaultMessage: 'Edit {target}'
}, {
target: `${role.name}`
}),
children: /*#__PURE__*/ jsx(Pencil, {})
}) : null,
checkCanDeleteRole(role) && /*#__PURE__*/ jsx(IconButton, {
onClick: ()=>handleClickDelete(role.id.toString()),
variant: "ghost",
label: formatMessage({
id: 'global.delete-target',
defaultMessage: 'Delete {target}'
}, {
target: `${role.name}`
}),
children: /*#__PURE__*/ jsx(Trash, {})
})
]
})
})
]
}, role.name))
});
};
TableBody.defaultProps = {
canDelete: false,
canUpdate: false
};
TableBody.propTypes = {
onDelete: PropTypes.array.isRequired,
setRoleToDelete: PropTypes.func.isRequired,
sortedRoles: PropTypes.array.isRequired,
canDelete: PropTypes.bool,
canUpdate: PropTypes.bool
};
export { TableBody as default };
//# sourceMappingURL=TableBody.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"TableBody.mjs","sources":["../../../../../../../admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Flex, IconButton, Link, Tbody, Td, Tr, Typography } from '@strapi/design-system';\nimport { Pencil, Trash } from '@strapi/icons';\nimport PropTypes from 'prop-types';\nimport { useIntl } from 'react-intl';\nimport { useNavigate, NavLink } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nconst EditLink = styled(Link)`\n align-items: center;\n height: 3.2rem;\n width: 3.2rem;\n display: flex;\n justify-content: center;\n padding: ${({ theme }) => `${theme.spaces[2]}`};\n\n svg {\n height: 1.6rem;\n width: 1.6rem;\n\n path {\n fill: ${({ theme }) => theme.colors.neutral500};\n }\n }\n\n &:hover,\n &:focus {\n svg {\n path {\n fill: ${({ theme }) => theme.colors.neutral800};\n }\n }\n }\n`;\n\nconst TableBody = ({ sortedRoles, canDelete, canUpdate, setRoleToDelete, onDelete }) => {\n const { formatMessage } = useIntl();\n const navigate = useNavigate();\n const [showConfirmDelete, setShowConfirmDelete] = onDelete;\n\n const checkCanDeleteRole = (role) =>\n canDelete && !['public', 'authenticated'].includes(role.type);\n\n const handleClickDelete = (id) => {\n setRoleToDelete(id);\n setShowConfirmDelete(!showConfirmDelete);\n };\n\n return (\n <Tbody>\n {sortedRoles?.map((role) => (\n <Tr cursor=\"pointer\" key={role.name} onClick={() => navigate(role.id.toString())}>\n <Td width=\"20%\">\n <Typography>{role.name}</Typography>\n </Td>\n <Td width=\"50%\">\n <Typography>{role.description}</Typography>\n </Td>\n <Td width=\"30%\">\n <Typography>\n {formatMessage(\n {\n id: 'Roles.RoleRow.user-count',\n defaultMessage: '{number, plural, =0 {# user} one {# user} other {# users}}',\n },\n { number: role.nb_users }\n )}\n </Typography>\n </Td>\n <Td>\n <Flex justifyContent=\"end\" onClick={(e) => e.stopPropagation()}>\n {canUpdate ? (\n <EditLink\n tag={NavLink}\n to={role.id.toString()}\n aria-label={formatMessage(\n { id: 'app.component.table.edit', defaultMessage: 'Edit {target}' },\n { target: `${role.name}` }\n )}\n >\n <Pencil />\n </EditLink>\n ) : null}\n\n {checkCanDeleteRole(role) && (\n <IconButton\n onClick={() => handleClickDelete(role.id.toString())}\n variant=\"ghost\"\n label={formatMessage(\n { id: 'global.delete-target', defaultMessage: 'Delete {target}' },\n { target: `${role.name}` }\n )}\n >\n <Trash />\n </IconButton>\n )}\n </Flex>\n </Td>\n </Tr>\n ))}\n </Tbody>\n );\n};\n\nexport default TableBody;\n\nTableBody.defaultProps = {\n canDelete: false,\n canUpdate: false,\n};\n\nTableBody.propTypes = {\n onDelete: PropTypes.array.isRequired,\n setRoleToDelete: PropTypes.func.isRequired,\n sortedRoles: PropTypes.array.isRequired,\n canDelete: PropTypes.bool,\n canUpdate: PropTypes.bool,\n};\n"],"names":["EditLink","styled","Link","theme","spaces","colors","neutral500","neutral800","TableBody","sortedRoles","canDelete","canUpdate","setRoleToDelete","onDelete","formatMessage","useIntl","navigate","useNavigate","showConfirmDelete","setShowConfirmDelete","checkCanDeleteRole","role","includes","type","handleClickDelete","id","_jsx","Tbody","map","_jsxs","Tr","cursor","onClick","toString","Td","width","Typography","name","description","defaultMessage","number","nb_users","Flex","justifyContent","e","stopPropagation","tag","NavLink","to","aria-label","target","Pencil","IconButton","variant","label","Trash","defaultProps","propTypes","PropTypes","array","isRequired","func","bool"],"mappings":";;;;;;;;;AASA,MAAMA,QAAAA,GAAWC,MAAOC,CAAAA,IAAAA,CAAK;;;;;;AAMlB,WAAA,EAAE,CAAC,EAAEC,KAAK,EAAE,GAAK,CAAC,EAAEA,KAAAA,CAAMC,MAAM,CAAC,CAAE,CAAA,CAAC,CAAC,CAAC;;;;;;;YAOrC,EAAE,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAME,CAAAA,MAAM,CAACC,UAAU,CAAC;;;;;;;;cAQvC,EAAE,CAAC,EAAEH,KAAK,EAAE,GAAKA,KAAME,CAAAA,MAAM,CAACE,UAAU,CAAC;;;;AAIvD,CAAC;AAED,MAAMC,SAAY,GAAA,CAAC,EAAEC,WAAW,EAAEC,SAAS,EAAEC,SAAS,EAAEC,eAAe,EAAEC,QAAQ,EAAE,GAAA;IACjF,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAMC,QAAWC,GAAAA,WAAAA,EAAAA;IACjB,MAAM,CAACC,iBAAmBC,EAAAA,oBAAAA,CAAqB,GAAGN,QAAAA;AAElD,IAAA,MAAMO,kBAAqB,GAAA,CAACC,IAC1BX,GAAAA,SAAAA,IAAa,CAAC;AAAC,YAAA,QAAA;AAAU,YAAA;SAAgB,CAACY,QAAQ,CAACD,IAAAA,CAAKE,IALine truncated
@@ -0,0 +1,237 @@
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var designSystem = require('@strapi/design-system');
var icons = require('@strapi/icons');
var admin = require('@strapi/strapi/admin');
var reactIntl = require('react-intl');
var reactQuery = require('react-query');
var reactRouterDom = require('react-router-dom');
var constants = require('../../../../constants.js');
require('lodash/isEmpty');
var getTrad = require('../../../../utils/getTrad.js');
var TableBody = require('./components/TableBody.js');
const RolesListPage = ()=>{
const { trackUsage } = admin.useTracking();
const { formatMessage, locale } = reactIntl.useIntl();
const { toggleNotification } = admin.useNotification();
const { notifyStatus } = designSystem.useNotifyAT();
const [{ query }] = admin.useQueryParams();
const _q = query?._q || '';
const [showConfirmDelete, setShowConfirmDelete] = React.useState(false);
const [roleToDelete, setRoleToDelete] = React.useState();
const { del, get } = admin.useFetchClient();
const { isLoading: isLoadingForPermissions, allowedActions: { canRead, canDelete, canCreate, canUpdate } } = admin.useRBAC({
create: constants.PERMISSIONS.createRole,
read: constants.PERMISSIONS.readRoles,
update: constants.PERMISSIONS.updateRole,
delete: constants.PERMISSIONS.deleteRole
});
const { isLoading: isLoadingForData, data: { roles }, isFetching, refetch } = reactQuery.useQuery('get-roles', ()=>fetchData(toggleNotification, formatMessage, notifyStatus), {
initialData: {},
enabled: canRead
});
const { contains } = designSystem.useFilter(locale, {
sensitivity: 'base'
});
/**
* @type {Intl.Collator}
*/ const formatter = designSystem.useCollator(locale, {
sensitivity: 'base'
});
const isLoading = isLoadingForData || isFetching || isLoadingForPermissions;
const handleShowConfirmDelete = ()=>{
setShowConfirmDelete(!showConfirmDelete);
};
const deleteData = async (id, formatMessage, toggleNotification)=>{
try {
await del(`/users-permissions/roles/${id}`);
} catch (error) {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error',
defaultMessage: 'An error occured'
})
});
}
};
const fetchData = async (toggleNotification, formatMessage, notifyStatus)=>{
try {
const { data } = await get('/users-permissions/roles');
notifyStatus('The roles have loaded successfully');
return data;
} catch (err) {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error',
defaultMessage: 'An error occurred'
})
});
throw new Error(err);
}
};
const emptyLayout = {
roles: {
id: getTrad('Roles.empty'),
defaultMessage: "You don't have any roles yet."
},
search: {
id: getTrad('Roles.empty.search'),
defaultMessage: 'No roles match the search.'
}
};
const pageTitle = formatMessage({
id: 'global.roles',
defaultMessage: 'Roles'
});
const deleteMutation = reactQuery.useMutation((id)=>deleteData(id, formatMessage, toggleNotification), {
async onSuccess () {
await refetch();
}
});
const handleConfirmDelete = async ()=>{
await deleteMutation.mutateAsync(roleToDelete);
setShowConfirmDelete(!showConfirmDelete);
};
const sortedRoles = (roles || []).filter((role)=>contains(role.name, _q) || contains(role.description, _q)).sort((a, b)=>formatter.compare(a.name, b.name) || formatter.compare(a.description, b.description));
const emptyContent = _q && !sortedRoles.length ? 'search' : 'roles';
const colCount = 4;
const rowCount = (roles?.length || 0) + 1;
if (isLoading) {
return /*#__PURE__*/ jsxRuntime.jsx(admin.Page.Loading, {});
}
return /*#__PURE__*/ jsxRuntime.jsxs(admin.Layouts.Root, {
children: [
/*#__PURE__*/ jsxRuntime.jsx(admin.Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: pageTitle
})
}),
/*#__PURE__*/ jsxRuntime.jsxs(admin.Page.Main, {
children: [
/*#__PURE__*/ jsxRuntime.jsx(admin.Layouts.Header, {
title: formatMessage({
id: 'global.roles',
defaultMessage: 'Roles'
}),
subtitle: formatMessage({
id: 'Settings.roles.list.description',
defaultMessage: 'List of roles'
}),
primaryAction: canCreate ? /*#__PURE__*/ jsxRuntime.jsx(designSystem.LinkButton, {
to: "new",
tag: reactRouterDom.NavLink,
onClick: ()=>trackUsage('willCreateRole'),
startIcon: /*#__PURE__*/ jsxRuntime.jsx(icons.Plus, {}),
size: "S",
children: formatMessage({
id: getTrad('List.button.roles'),
defaultMessage: 'Add new role'
})
}) : null
}),
/*#__PURE__*/ jsxRuntime.jsx(admin.Layouts.Action, {
startActions: /*#__PURE__*/ jsxRuntime.jsx(admin.SearchInput, {
label: formatMessage({
id: 'app.component.search.label',
defaultMessage: 'Search'
})
})
}),
/*#__PURE__*/ jsxRuntime.jsxs(admin.Layouts.Content, {
children: [
!canRead && /*#__PURE__*/ jsxRuntime.jsx(admin.Page.NoPermissions, {}),
canRead && sortedRoles && sortedRoles?.length ? /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Table, {
colCount: colCount,
rowCount: rowCount,
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Thead, {
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Tr, {
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Th, {
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
variant: "sigma",
textColor: "neutral600",
children: formatMessage({
id: 'global.name',
defaultMessage: 'Name'
})
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Th, {
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
variant: "sigma",
textColor: "neutral600",
children: formatMessage({
id: 'global.description',
defaultMessage: 'Description'
})
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Th, {
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
variant: "sigma",
textColor: "neutral600",
children: formatMessage({
id: 'global.users',
defaultMessage: 'Users'
})
})
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Th, {
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.VisuallyHidden, {
children: formatMessage({
id: 'global.actions',
defaultMessage: 'Actions'
})
})
})
]
})
}),
/*#__PURE__*/ jsxRuntime.jsx(TableBody, {
sortedRoles: sortedRoles,
canDelete: canDelete,
canUpdate: canUpdate,
permissions: constants.PERMISSIONS,
setRoleToDelete: setRoleToDelete,
onDelete: [
showConfirmDelete,
setShowConfirmDelete
]
})
]
}) : /*#__PURE__*/ jsxRuntime.jsx(designSystem.EmptyStateLayout, {
content: formatMessage(emptyLayout[emptyContent])
})
]
}),
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Root, {
open: showConfirmDelete,
onOpenChange: handleShowConfirmDelete,
children: /*#__PURE__*/ jsxRuntime.jsx(admin.ConfirmDialog, {
onConfirm: handleConfirmDelete
})
})
]
})
]
});
};
const ProtectedRolesListPage = ()=>{
return /*#__PURE__*/ jsxRuntime.jsx(admin.Page.Protect, {
permissions: constants.PERMISSIONS.accessRoles,
children: /*#__PURE__*/ jsxRuntime.jsx(RolesListPage, {})
});
};
exports.ProtectedRolesListPage = ProtectedRolesListPage;
exports.RolesListPage = RolesListPage;
//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../../../../admin/src/pages/Roles/pages/ListPage/index.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport {\n Table,\n Th,\n Thead,\n Tr,\n Typography,\n useNotifyAT,\n VisuallyHidden,\n EmptyStateLayout,\n useCollator,\n useFilter,\n LinkButton,\n Dialog,\n} from '@strapi/design-system';\nimport { Plus } from '@strapi/icons';\nimport {\n ConfirmDialog,\n useTracking,\n Page,\n SearchInput,\n useNotification,\n useQueryParams,\n useFetchClient,\n useRBAC,\n Layouts,\n} from '@strapi/strapi/admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQuery } from 'react-query';\nimport { NavLink } from 'react-router-dom';\n\nimport { PERMISSIONS } from '../../../../constants';\nimport { getTrad } from '../../../../utils';\n\nimport TableBody from './components/TableBody';\n\nexport const RolesListPage = () => {\n const { trackUsage } = useTracking();\n const { formatMessage, locale } = useIntl();\n const { toggleNotification } = useNotification();\n const { notifyStatus } = useNotifyAT();\n const [{ query }] = useQueryParams();\n const _q = query?._q || '';\n const [showConfirmDelete, setShowConfirmDelete] = useState(false);\n const [roleToDelete, setRoleToDelete] = useState();\n const { del, get } = useFetchClient();\n\n const {\n isLoading: isLoadingForPermissions,\n allowedActions: { canRead, canDelete, canCreate, canUpdate },\n } = useRBAC({\n create: PERMISSIONS.createRole,\n read: PERMISSIONS.readRoles,\n update: PERMISSIONS.updateRole,\n delete: PERMISSIONS.deleteRole,\n });\n\n const {\n isLoading: isLoadingForData,\n data: { roles },\n isFetching,\n refetch,\n } = useQuery('get-roles', () => fetchData(toggleNotification, formatMessage, notifyStatus), {\n initialData: {},\n enabled: canRead,\n });\n\n const { contains } = useFilter(locale, {\n sensitivity: 'base',\n });\n\n /**\n * @type {Intl.Collator}\n */\n const formatter = useCollator(locale, {\n sensitivity: 'base',\n });\n\n const isLoading = isLoadingForData || isFetching || isLoadingForPermissions;\n\n const handleShowConfirmDelete = () => {\n setShowConfirmDelete(!showConfirmDelete);\n };\n\n const deleteData = async (id, formatMessage, toggleNotification) => {\n try {\n await del(`/users-permissions/roles/${id}`);\n } catch (error) {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occured' }),\n });\n }\n };\n\n const fetchData = async (toggleNotification, formatMessage, notifyStatus) => {\n try {\n const { data } = await get('/users-permissions/roles');\n notifyStatus('The roles have loaded successfully');\n\n return data;\n } catch (err) {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n\n throw new Error(err);\n }\n };\n\n const emptyLayout = {\n roles: {\n id: getTrad('Roles.empty'),\n defaultMessage: \"You don't have any roles yet.\",\n },\n search: {\n id: getTrad('Roles.empty.search'),\n defaultMessage: 'No roles match the search.',\n },\n };\n\n const pageTitle = formatMessage({\n id: 'global.roles',\n defaultMessage: 'Roles',\n });\n\n const deleteMutation = useMutation((id) => deleteData(id, formatMessage, toggleNotification), {\n async onSuccess() {\n await refetch();\n },\n });\n\n const handleConfirmDelete = async () => {\n await deleteMutation.mutateAsync(roleToDelete);\n setShowConfirmDelete(!showConfirmDelete);\n };\n\n const sortedRoles = (roles || [])\n .filter((role) => contains(role.name, _q) || contains(role.description, _q))\n .sort(\n (a, b) => formatter.compare(a.name, b.name) || formatter.compare(a.description, b.description)\n );\n\n const emptyContent = _q && !sortedRoles.length ? 'search' : 'roles';\n\n const colCount = 4;\n const rowCount = (roles?.length || 0) + 1;\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n return (\n <Layouts.Root>\n <Page.Title>\n {formatMessage(\n { id: 'Settings.PageTitle', defaultMessage: 'Settings - {name}' },\n { name: pageTitle }\n )}\n </Page.Title>\n <Page.Main>\n <Layouts.Header\n title={formatMessage({\n id: 'global.roles',\n defaultMessage: 'Roles',\n })}\n subtitle={formatMessage({\n id: 'Settings.roles.list.description',\n defaultMessage: 'List of roles',\n })}\n primaryAction={\n canCreate ? (\n <LinkButton\n to=\"new\"\n tag={NavLink}\n onClick={() => trackUsage('willCreateRole')}\n startIcon={<Plus />}\n sLine truncated
@@ -0,0 +1,234 @@
import { jsx, jsxs } from 'react/jsx-runtime';
import { useState } from 'react';
import { useNotifyAT, useFilter, useCollator, LinkButton, Table, Thead, Tr, Th, Typography, VisuallyHidden, EmptyStateLayout, Dialog } from '@strapi/design-system';
import { Plus } from '@strapi/icons';
import { Page, useTracking, useNotification, useQueryParams, useFetchClient, useRBAC, Layouts, SearchInput, ConfirmDialog } from '@strapi/strapi/admin';
import { useIntl } from 'react-intl';
import { useQuery, useMutation } from 'react-query';
import { NavLink } from 'react-router-dom';
import { PERMISSIONS } from '../../../../constants.mjs';
import 'lodash/isEmpty';
import getTrad from '../../../../utils/getTrad.mjs';
import TableBody from './components/TableBody.mjs';
const RolesListPage = ()=>{
const { trackUsage } = useTracking();
const { formatMessage, locale } = useIntl();
const { toggleNotification } = useNotification();
const { notifyStatus } = useNotifyAT();
const [{ query }] = useQueryParams();
const _q = query?._q || '';
const [showConfirmDelete, setShowConfirmDelete] = useState(false);
const [roleToDelete, setRoleToDelete] = useState();
const { del, get } = useFetchClient();
const { isLoading: isLoadingForPermissions, allowedActions: { canRead, canDelete, canCreate, canUpdate } } = useRBAC({
create: PERMISSIONS.createRole,
read: PERMISSIONS.readRoles,
update: PERMISSIONS.updateRole,
delete: PERMISSIONS.deleteRole
});
const { isLoading: isLoadingForData, data: { roles }, isFetching, refetch } = useQuery('get-roles', ()=>fetchData(toggleNotification, formatMessage, notifyStatus), {
initialData: {},
enabled: canRead
});
const { contains } = useFilter(locale, {
sensitivity: 'base'
});
/**
* @type {Intl.Collator}
*/ const formatter = useCollator(locale, {
sensitivity: 'base'
});
const isLoading = isLoadingForData || isFetching || isLoadingForPermissions;
const handleShowConfirmDelete = ()=>{
setShowConfirmDelete(!showConfirmDelete);
};
const deleteData = async (id, formatMessage, toggleNotification)=>{
try {
await del(`/users-permissions/roles/${id}`);
} catch (error) {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error',
defaultMessage: 'An error occured'
})
});
}
};
const fetchData = async (toggleNotification, formatMessage, notifyStatus)=>{
try {
const { data } = await get('/users-permissions/roles');
notifyStatus('The roles have loaded successfully');
return data;
} catch (err) {
toggleNotification({
type: 'danger',
message: formatMessage({
id: 'notification.error',
defaultMessage: 'An error occurred'
})
});
throw new Error(err);
}
};
const emptyLayout = {
roles: {
id: getTrad('Roles.empty'),
defaultMessage: "You don't have any roles yet."
},
search: {
id: getTrad('Roles.empty.search'),
defaultMessage: 'No roles match the search.'
}
};
const pageTitle = formatMessage({
id: 'global.roles',
defaultMessage: 'Roles'
});
const deleteMutation = useMutation((id)=>deleteData(id, formatMessage, toggleNotification), {
async onSuccess () {
await refetch();
}
});
const handleConfirmDelete = async ()=>{
await deleteMutation.mutateAsync(roleToDelete);
setShowConfirmDelete(!showConfirmDelete);
};
const sortedRoles = (roles || []).filter((role)=>contains(role.name, _q) || contains(role.description, _q)).sort((a, b)=>formatter.compare(a.name, b.name) || formatter.compare(a.description, b.description));
const emptyContent = _q && !sortedRoles.length ? 'search' : 'roles';
const colCount = 4;
const rowCount = (roles?.length || 0) + 1;
if (isLoading) {
return /*#__PURE__*/ jsx(Page.Loading, {});
}
return /*#__PURE__*/ jsxs(Layouts.Root, {
children: [
/*#__PURE__*/ jsx(Page.Title, {
children: formatMessage({
id: 'Settings.PageTitle',
defaultMessage: 'Settings - {name}'
}, {
name: pageTitle
})
}),
/*#__PURE__*/ jsxs(Page.Main, {
children: [
/*#__PURE__*/ jsx(Layouts.Header, {
title: formatMessage({
id: 'global.roles',
defaultMessage: 'Roles'
}),
subtitle: formatMessage({
id: 'Settings.roles.list.description',
defaultMessage: 'List of roles'
}),
primaryAction: canCreate ? /*#__PURE__*/ jsx(LinkButton, {
to: "new",
tag: NavLink,
onClick: ()=>trackUsage('willCreateRole'),
startIcon: /*#__PURE__*/ jsx(Plus, {}),
size: "S",
children: formatMessage({
id: getTrad('List.button.roles'),
defaultMessage: 'Add new role'
})
}) : null
}),
/*#__PURE__*/ jsx(Layouts.Action, {
startActions: /*#__PURE__*/ jsx(SearchInput, {
label: formatMessage({
id: 'app.component.search.label',
defaultMessage: 'Search'
})
})
}),
/*#__PURE__*/ jsxs(Layouts.Content, {
children: [
!canRead && /*#__PURE__*/ jsx(Page.NoPermissions, {}),
canRead && sortedRoles && sortedRoles?.length ? /*#__PURE__*/ jsxs(Table, {
colCount: colCount,
rowCount: rowCount,
children: [
/*#__PURE__*/ jsx(Thead, {
children: /*#__PURE__*/ jsxs(Tr, {
children: [
/*#__PURE__*/ jsx(Th, {
children: /*#__PURE__*/ jsx(Typography, {
variant: "sigma",
textColor: "neutral600",
children: formatMessage({
id: 'global.name',
defaultMessage: 'Name'
})
})
}),
/*#__PURE__*/ jsx(Th, {
children: /*#__PURE__*/ jsx(Typography, {
variant: "sigma",
textColor: "neutral600",
children: formatMessage({
id: 'global.description',
defaultMessage: 'Description'
})
})
}),
/*#__PURE__*/ jsx(Th, {
children: /*#__PURE__*/ jsx(Typography, {
variant: "sigma",
textColor: "neutral600",
children: formatMessage({
id: 'global.users',
defaultMessage: 'Users'
})
})
}),
/*#__PURE__*/ jsx(Th, {
children: /*#__PURE__*/ jsx(VisuallyHidden, {
children: formatMessage({
id: 'global.actions',
defaultMessage: 'Actions'
})
})
})
]
})
}),
/*#__PURE__*/ jsx(TableBody, {
sortedRoles: sortedRoles,
canDelete: canDelete,
canUpdate: canUpdate,
permissions: PERMISSIONS,
setRoleToDelete: setRoleToDelete,
onDelete: [
showConfirmDelete,
setShowConfirmDelete
]
})
]
}) : /*#__PURE__*/ jsx(EmptyStateLayout, {
content: formatMessage(emptyLayout[emptyContent])
})
]
}),
/*#__PURE__*/ jsx(Dialog.Root, {
open: showConfirmDelete,
onOpenChange: handleShowConfirmDelete,
children: /*#__PURE__*/ jsx(ConfirmDialog, {
onConfirm: handleConfirmDelete
})
})
]
})
]
});
};
const ProtectedRolesListPage = ()=>{
return /*#__PURE__*/ jsx(Page.Protect, {
permissions: PERMISSIONS.accessRoles,
children: /*#__PURE__*/ jsx(RolesListPage, {})
});
};
export { ProtectedRolesListPage, RolesListPage };
//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../../../../../admin/src/pages/Roles/pages/ListPage/index.jsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport {\n Table,\n Th,\n Thead,\n Tr,\n Typography,\n useNotifyAT,\n VisuallyHidden,\n EmptyStateLayout,\n useCollator,\n useFilter,\n LinkButton,\n Dialog,\n} from '@strapi/design-system';\nimport { Plus } from '@strapi/icons';\nimport {\n ConfirmDialog,\n useTracking,\n Page,\n SearchInput,\n useNotification,\n useQueryParams,\n useFetchClient,\n useRBAC,\n Layouts,\n} from '@strapi/strapi/admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQuery } from 'react-query';\nimport { NavLink } from 'react-router-dom';\n\nimport { PERMISSIONS } from '../../../../constants';\nimport { getTrad } from '../../../../utils';\n\nimport TableBody from './components/TableBody';\n\nexport const RolesListPage = () => {\n const { trackUsage } = useTracking();\n const { formatMessage, locale } = useIntl();\n const { toggleNotification } = useNotification();\n const { notifyStatus } = useNotifyAT();\n const [{ query }] = useQueryParams();\n const _q = query?._q || '';\n const [showConfirmDelete, setShowConfirmDelete] = useState(false);\n const [roleToDelete, setRoleToDelete] = useState();\n const { del, get } = useFetchClient();\n\n const {\n isLoading: isLoadingForPermissions,\n allowedActions: { canRead, canDelete, canCreate, canUpdate },\n } = useRBAC({\n create: PERMISSIONS.createRole,\n read: PERMISSIONS.readRoles,\n update: PERMISSIONS.updateRole,\n delete: PERMISSIONS.deleteRole,\n });\n\n const {\n isLoading: isLoadingForData,\n data: { roles },\n isFetching,\n refetch,\n } = useQuery('get-roles', () => fetchData(toggleNotification, formatMessage, notifyStatus), {\n initialData: {},\n enabled: canRead,\n });\n\n const { contains } = useFilter(locale, {\n sensitivity: 'base',\n });\n\n /**\n * @type {Intl.Collator}\n */\n const formatter = useCollator(locale, {\n sensitivity: 'base',\n });\n\n const isLoading = isLoadingForData || isFetching || isLoadingForPermissions;\n\n const handleShowConfirmDelete = () => {\n setShowConfirmDelete(!showConfirmDelete);\n };\n\n const deleteData = async (id, formatMessage, toggleNotification) => {\n try {\n await del(`/users-permissions/roles/${id}`);\n } catch (error) {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occured' }),\n });\n }\n };\n\n const fetchData = async (toggleNotification, formatMessage, notifyStatus) => {\n try {\n const { data } = await get('/users-permissions/roles');\n notifyStatus('The roles have loaded successfully');\n\n return data;\n } catch (err) {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n\n throw new Error(err);\n }\n };\n\n const emptyLayout = {\n roles: {\n id: getTrad('Roles.empty'),\n defaultMessage: \"You don't have any roles yet.\",\n },\n search: {\n id: getTrad('Roles.empty.search'),\n defaultMessage: 'No roles match the search.',\n },\n };\n\n const pageTitle = formatMessage({\n id: 'global.roles',\n defaultMessage: 'Roles',\n });\n\n const deleteMutation = useMutation((id) => deleteData(id, formatMessage, toggleNotification), {\n async onSuccess() {\n await refetch();\n },\n });\n\n const handleConfirmDelete = async () => {\n await deleteMutation.mutateAsync(roleToDelete);\n setShowConfirmDelete(!showConfirmDelete);\n };\n\n const sortedRoles = (roles || [])\n .filter((role) => contains(role.name, _q) || contains(role.description, _q))\n .sort(\n (a, b) => formatter.compare(a.name, b.name) || formatter.compare(a.description, b.description)\n );\n\n const emptyContent = _q && !sortedRoles.length ? 'search' : 'roles';\n\n const colCount = 4;\n const rowCount = (roles?.length || 0) + 1;\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n return (\n <Layouts.Root>\n <Page.Title>\n {formatMessage(\n { id: 'Settings.PageTitle', defaultMessage: 'Settings - {name}' },\n { name: pageTitle }\n )}\n </Page.Title>\n <Page.Main>\n <Layouts.Header\n title={formatMessage({\n id: 'global.roles',\n defaultMessage: 'Roles',\n })}\n subtitle={formatMessage({\n id: 'Settings.roles.list.description',\n defaultMessage: 'List of roles',\n })}\n primaryAction={\n canCreate ? (\n <LinkButton\n to=\"new\"\n tag={NavLink}\n onClick={() => trackUsage('willCreateRole')}\n startIcon={<Plus />}\n Line truncated