import React, { useState, useRef } from 'react'; import { ContentLayout, HeaderLayout } from '@strapi/parts/Layout'; import { Main, Button, Stack, Box, GridItem, Grid, TextInput, Textarea } from '@strapi/parts'; import { H3 } from '@strapi/parts/Text'; import { CheckIcon } from '@strapi/icons'; import { Formik } from 'formik'; import { useIntl } from 'react-intl'; import { useRouteMatch } from 'react-router-dom'; import { useOverlayBlocker, SettingsPageTitle, LoadingIndicatorPage, Form, useNotification, } from '@strapi/helper-plugin'; import UsersPermissions from '../../../components/UsersPermissions'; import getTrad from '../../../utils/getTrad'; import pluginId from '../../../pluginId'; import { usePlugins, useFetchRole } from '../../../hooks'; import schema from './utils/schema'; import axiosInstance from '../../../utils/axiosInstance'; const EditPage = () => { const { formatMessage } = useIntl(); const [isSubmitting, setIsSubmitting] = useState(false); const toggleNotification = useNotification(); const { lockApp, unlockApp } = useOverlayBlocker(); const { params: { id }, } = useRouteMatch(`/settings/${pluginId}/roles/:id`); const { isLoading: isLoadingPlugins, routes, policies } = usePlugins(); const { role, onSubmitSucceeded, isLoading: isLoadingRole } = useFetchRole(id); const permissionsRef = useRef(); const handleCreateRoleSubmit = async data => { // Set loading state lockApp(); setIsSubmitting(true); try { // Update role in Strapi await axiosInstance.put(`/${pluginId}/roles/${id}`, { ...data, users: [] }); // Notify success onSubmitSucceeded({ name: data.name, description: data.description }); toggleNotification({ type: 'success', message: { id: getTrad('Settings.roles.edited'), defaultMessage: 'Role edited', }, }); } catch (err) { console.error(err); toggleNotification({ type: 'warning', message: { id: 'notification.error', defaultMessage: 'An error occurred', }, }); } // Unset loading state setIsSubmitting(false); unlockApp(); }; if (isLoadingRole) { return ; } return (
{({ handleSubmit, values, handleChange, errors }) => (
} > {formatMessage({ id: 'app.components.Button.save', defaultMessage: 'Save', })} ) } title={role.name} subtitle={role.description} />

{formatMessage({ id: getTrad('EditPage.form.roles'), defaultMessage: 'Role details', })}