Commented the settings view that are not yet migrated

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-08-19 16:46:06 +02:00
parent 0c516640ae
commit 77eedf2577
4 changed files with 445 additions and 423 deletions

View File

@ -1,6 +1,13 @@
import adminPermissions from '../../../permissions'; import adminPermissions from '../../../permissions';
const defaultGlobalLinks = [ const defaultGlobalLinks = [
{
intlLabel: { id: 'Settings.application.title', defaultMessage: 'Application' },
to: '/settings/application-infos',
id: 'application-infos',
isDisplayed: false,
permissions: [],
},
{ {
intlLabel: { id: 'Settings.webhooks.title', defaultMessage: 'Webhooks' }, intlLabel: { id: 'Settings.webhooks.title', defaultMessage: 'Webhooks' },
to: '/settings/webhooks', to: '/settings/webhooks',

View File

@ -1,74 +1,75 @@
import React from 'react'; // import React from 'react';
import { Header } from '@buffetjs/custom'; // import { Header } from '@buffetjs/custom';
import { Flex, Padded, Text } from '@buffetjs/core'; // import { Flex, Padded, Text } from '@buffetjs/core';
import { useIntl } from 'react-intl'; // import { useIntl } from 'react-intl';
import { BaselineAlignment, useAppInfos } from '@strapi/helper-plugin'; // import { BaselineAlignment, useAppInfos } from '@strapi/helper-plugin';
import Bloc from '../../components/Bloc'; // import Bloc from '../../components/Bloc';
import PageTitle from '../../components/SettingsPageTitle'; // import PageTitle from '../../components/SettingsPageTitle';
import { Detail, InfoText } from './components'; // import { Detail, InfoText } from './components';
const ApplicationInfosPage = () => { // const ApplicationInfosPage = () => {
const appInfos = useAppInfos(); // const appInfos = useAppInfos();
const { shouldUpdateStrapi, latestStrapiReleaseTag } = appInfos; // const { shouldUpdateStrapi, latestStrapiReleaseTag } = appInfos;
const { formatMessage } = useIntl(); // const { formatMessage } = useIntl();
const currentPlan = appInfos.communityEdition // const currentPlan = appInfos.communityEdition
? 'app.components.UpgradePlanModal.text-ce' // ? 'app.components.UpgradePlanModal.text-ce'
: 'app.components.UpgradePlanModal.text-ee'; // : 'app.components.UpgradePlanModal.text-ee';
const headerProps = { // const headerProps = {
title: { label: formatMessage({ id: 'Settings.application.title' }) }, // title: { label: formatMessage({ id: 'Settings.application.title' }) },
content: formatMessage({ // content: formatMessage({
id: 'Settings.application.description', // id: 'Settings.application.description',
}), // }),
}; // };
const pricingLabel = formatMessage({ id: 'Settings.application.link-pricing' }); // const pricingLabel = formatMessage({ id: 'Settings.application.link-pricing' });
const upgradeLabel = formatMessage({ id: 'Settings.application.link-upgrade' }); // const upgradeLabel = formatMessage({ id: 'Settings.application.link-upgrade' });
const strapiVersion = formatMessage({ id: 'Settings.application.strapi-version' }); // const strapiVersion = formatMessage({ id: 'Settings.application.strapi-version' });
const nodeVersion = formatMessage({ id: 'Settings.application.node-version' }); // const nodeVersion = formatMessage({ id: 'Settings.application.node-version' });
const editionTitle = formatMessage({ id: 'Settings.application.edition-title' }); // const editionTitle = formatMessage({ id: 'Settings.application.edition-title' });
/* eslint-disable indent */ // /* eslint-disable indent */
const upgradeLink = shouldUpdateStrapi // const upgradeLink = shouldUpdateStrapi
? { // ? {
label: upgradeLabel, // label: upgradeLabel,
href: `https://github.com/strapi/strapi/releases/tag/${latestStrapiReleaseTag}`, // href: `https://github.com/strapi/strapi/releases/tag/${latestStrapiReleaseTag}`,
} // }
: null; // : null;
/* eslint-enable indent */ // /* eslint-enable indent */
return ( // return (
<div> // <div>
<PageTitle name="Application" /> // <PageTitle name="Application" />
<Header {...headerProps} /> // <Header {...headerProps} />
<BaselineAlignment top size="3px" /> // <BaselineAlignment top size="3px" />
<Bloc> // <Bloc>
<Padded left right top size="smd"> // <Padded left right top size="smd">
<Padded left right top size="xs"> // <Padded left right top size="xs">
<Flex justifyContent="space-between"> // <Flex justifyContent="space-between">
<Detail // <Detail
link={upgradeLink} // link={upgradeLink}
title={strapiVersion} // title={strapiVersion}
content={`v${appInfos.strapiVersion}`} // content={`v${appInfos.strapiVersion}`}
/> // />
<Detail // <Detail
link={{ label: pricingLabel, href: 'https://strapi.io/pricing' }} // link={{ label: pricingLabel, href: 'https://strapi.io/pricing' }}
title={editionTitle} // title={editionTitle}
content={formatMessage({ id: currentPlan })} // content={formatMessage({ id: currentPlan })}
/> // />
</Flex> // </Flex>
<Padded top size="lg"> // <Padded top size="lg">
<Text fontSize="xs" color="grey" fontWeight="bold"> // <Text fontSize="xs" color="grey" fontWeight="bold">
{nodeVersion} // {nodeVersion}
</Text> // </Text>
<InfoText content={appInfos.nodeVersion} /> // <InfoText content={appInfos.nodeVersion} />
</Padded> // </Padded>
</Padded> // </Padded>
</Padded> // </Padded>
<BaselineAlignment top size="60px" /> // <BaselineAlignment top size="60px" />
</Bloc> // </Bloc>
</div> // </div>
); // );
}; // };
export default ApplicationInfosPage; // export default ApplicationInfosPage;
export default () => 'ApplicationInfosPage';

View File

@ -1,291 +1,292 @@
import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react'; // import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
import { // import {
BaselineAlignment, // BaselineAlignment,
useQuery, // useQuery,
request, // request,
useRBAC, // useRBAC,
LoadingIndicatorPage, // LoadingIndicatorPage,
PopUpWarning, // PopUpWarning,
useNotification, // useNotification,
} from '@strapi/helper-plugin'; // } from '@strapi/helper-plugin';
import { get } from 'lodash'; // import { get } from 'lodash';
import { useHistory, useLocation } from 'react-router-dom'; // import { useHistory, useLocation } from 'react-router-dom';
import { Flex, Padded } from '@buffetjs/core'; // import { Flex, Padded } from '@buffetjs/core';
import PageTitle from '../../../components/SettingsPageTitle'; // import PageTitle from '../../../components/SettingsPageTitle';
import { useSettingsHeaderSearchContext } from '../../../hooks'; // import { useSettingsHeaderSearchContext } from '../../../hooks';
import { Footer, List, Filter, FilterPicker, SortPicker } from '../../../components/Users'; // import { Footer, List, Filter, FilterPicker, SortPicker } from '../../../components/Users';
import adminPermissions from '../../../permissions'; // import adminPermissions from '../../../permissions';
import Header from './Header'; // import Header from './Header';
import ModalForm from './ModalForm'; // import ModalForm from './ModalForm';
import getFilters from './utils/getFilters'; // import getFilters from './utils/getFilters';
import init from './init'; // import init from './init';
import { initialState, reducer } from './reducer'; // import { initialState, reducer } from './reducer';
const ListPage = () => { // const ListPage = () => {
const { // const {
isLoading: isLoadingForPermissions, // isLoading: isLoadingForPermissions,
allowedActions: { canCreate, canDelete, canRead, canUpdate }, // allowedActions: { canCreate, canDelete, canRead, canUpdate },
} = useRBAC(adminPermissions.settings.users); // } = useRBAC(adminPermissions.settings.users);
const toggleNotification = useNotification(); // const toggleNotification = useNotification();
const [isWarningDeleteAllOpened, setIsWarningDeleteAllOpened] = useState(false); // const [isWarningDeleteAllOpened, setIsWarningDeleteAllOpened] = useState(false);
const [isModalOpened, setIsModalOpened] = useState(false); // const [isModalOpened, setIsModalOpened] = useState(false);
const { toggleHeaderSearch } = useSettingsHeaderSearchContext(); // const { toggleHeaderSearch } = useSettingsHeaderSearchContext();
const query = useQuery(); // const query = useQuery();
const { push } = useHistory(); // const { push } = useHistory();
const { search } = useLocation(); // const { search } = useLocation();
const filters = useMemo(() => { // const filters = useMemo(() => {
return getFilters(search); // return getFilters(search);
}, [search]); // }, [search]);
const [ // const [
{ // {
data, // data,
dataToDelete, // dataToDelete,
isLoading, // isLoading,
pagination: { total }, // pagination: { total },
shouldRefetchData, // shouldRefetchData,
showModalConfirmButtonLoading, // showModalConfirmButtonLoading,
}, // },
dispatch, // dispatch,
] = useReducer(reducer, initialState, init); // ] = useReducer(reducer, initialState, init);
const pageSize = parseInt(query.get('pageSize') || 10, 10); // const pageSize = parseInt(query.get('pageSize') || 10, 10);
const page = parseInt(query.get('page') || 0, 10); // const page = parseInt(query.get('page') || 0, 10);
const _sort = decodeURIComponent(query.get('_sort')); // const _sort = decodeURIComponent(query.get('_sort'));
const _q = decodeURIComponent(query.get('_q') || ''); // const _q = decodeURIComponent(query.get('_q') || '');
const getDataRef = useRef(); // const getDataRef = useRef();
const listRef = useRef(); // const listRef = useRef();
getDataRef.current = async () => { // getDataRef.current = async () => {
if (!canRead) { // if (!canRead) {
dispatch({ // dispatch({
type: 'UNSET_IS_LOADING', // type: 'UNSET_IS_LOADING',
}); // });
return; // return;
} // }
// Show the loading state and reset the state // // Show the loading state and reset the state
dispatch({ // dispatch({
type: 'GET_DATA', // type: 'GET_DATA',
}); // });
try { // try {
const { // const {
data: { results, pagination }, // data: { results, pagination },
} = await request(`/admin/users${search}`, { method: 'GET' }); // } = await request(`/admin/users${search}`, { method: 'GET' });
dispatch({ // dispatch({
type: 'GET_DATA_SUCCEEDED', // type: 'GET_DATA_SUCCEEDED',
data: results, // data: results,
pagination, // pagination,
}); // });
} catch (err) { // } catch (err) {
console.error(err.response); // console.error(err.response);
toggleNotification({ // toggleNotification({
type: 'warning', // type: 'warning',
message: { id: 'notification.error' }, // message: { id: 'notification.error' },
}); // });
} // }
}; // };
useEffect(() => { // useEffect(() => {
if (!isLoadingForPermissions) { // if (!isLoadingForPermissions) {
getDataRef.current(); // getDataRef.current();
} // }
}, [search, isLoadingForPermissions]); // }, [search, isLoadingForPermissions]);
useEffect(() => { // useEffect(() => {
if (canRead) { // if (canRead) {
toggleHeaderSearch({ id: 'Settings.permissions.menu.link.users.label' }); // toggleHeaderSearch({ id: 'Settings.permissions.menu.link.users.label' });
} // }
return () => { // return () => {
if (canRead) { // if (canRead) {
toggleHeaderSearch(); // toggleHeaderSearch();
} // }
}; // };
// eslint-disable-next-line react-hooks/exhaustive-deps // // eslint-disable-next-line react-hooks/exhaustive-deps
}, [canRead]); // }, [canRead]);
const handleChangeDataToDelete = ids => { // const handleChangeDataToDelete = ids => {
dispatch({ // dispatch({
type: 'ON_CHANGE_DATA_TO_DELETE', // type: 'ON_CHANGE_DATA_TO_DELETE',
dataToDelete: ids, // dataToDelete: ids,
}); // });
}; // };
const handleChangeFilter = ({ filter, name, value }) => { // const handleChangeFilter = ({ filter, name, value }) => {
const filterName = `${name}${filter}`; // const filterName = `${name}${filter}`;
updateSearchParams(filterName, encodeURIComponent(value), true); // updateSearchParams(filterName, encodeURIComponent(value), true);
}; // };
const handleChangeFooterParams = ({ target: { name, value } }) => { // const handleChangeFooterParams = ({ target: { name, value } }) => {
let paramName = name.split('.')[1].replace('_', ''); // let paramName = name.split('.')[1].replace('_', '');
if (paramName === 'limit') { // if (paramName === 'limit') {
paramName = 'pageSize'; // paramName = 'pageSize';
} // }
updateSearchParams(paramName, value); // updateSearchParams(paramName, value);
}; // };
const handleChangeSort = ({ target: { name, value } }) => { // const handleChangeSort = ({ target: { name, value } }) => {
updateSearchParams(name, value); // updateSearchParams(name, value);
}; // };
const handleClickDeleteFilter = ({ target: { name } }) => { // const handleClickDeleteFilter = ({ target: { name } }) => {
const currentSearch = new URLSearchParams(search); // const currentSearch = new URLSearchParams(search);
currentSearch.delete(name); // currentSearch.delete(name);
push({ search: currentSearch.toString() }); // push({ search: currentSearch.toString() });
}; // };
const handleClickDelete = useCallback(id => { // const handleClickDelete = useCallback(id => {
handleToggleModal(); // handleToggleModal();
dispatch({ // dispatch({
type: 'ON_CHANGE_DATA_TO_DELETE', // type: 'ON_CHANGE_DATA_TO_DELETE',
dataToDelete: [id], // dataToDelete: [id],
}); // });
}, []); // }, []);
const handleCloseModal = () => { // const handleCloseModal = () => {
// Refetch data // // Refetch data
getDataRef.current(); // getDataRef.current();
}; // };
const handleClosedModalDelete = () => { // const handleClosedModalDelete = () => {
if (shouldRefetchData) { // if (shouldRefetchData) {
getDataRef.current(); // getDataRef.current();
} else { // } else {
// Empty the selected ids when the modal closes // // Empty the selected ids when the modal closes
dispatch({ // dispatch({
type: 'RESET_DATA_TO_DELETE', // type: 'RESET_DATA_TO_DELETE',
}); // });
// Reset the list's reducer dataToDelete state using a ref so we don't need an effect // // Reset the list's reducer dataToDelete state using a ref so we don't need an effect
listRef.current.resetDataToDelete(); // listRef.current.resetDataToDelete();
} // }
}; // };
const handleConfirmDeleteData = useCallback(async () => { // const handleConfirmDeleteData = useCallback(async () => {
dispatch({ // dispatch({
type: 'ON_DELETE_USERS', // type: 'ON_DELETE_USERS',
}); // });
let shouldDispatchSucceededAction = false; // let shouldDispatchSucceededAction = false;
try { // try {
await request('/admin/users/batch-delete', { // await request('/admin/users/batch-delete', {
method: 'POST', // method: 'POST',
body: { // body: {
ids: dataToDelete, // ids: dataToDelete,
}, // },
}); // });
shouldDispatchSucceededAction = true; // shouldDispatchSucceededAction = true;
} catch (err) { // } catch (err) {
const errorMessage = get(err, 'response.payload.data', 'An error occured'); // const errorMessage = get(err, 'response.payload.data', 'An error occured');
toggleNotification({ // toggleNotification({
type: 'warning', // type: 'warning',
message: errorMessage, // message: errorMessage,
}); // });
} // }
// Only dispatch the action once // // Only dispatch the action once
if (shouldDispatchSucceededAction) { // if (shouldDispatchSucceededAction) {
dispatch({ // dispatch({
type: 'ON_DELETE_USERS_SUCCEEDED', // type: 'ON_DELETE_USERS_SUCCEEDED',
}); // });
} // }
handleToggleModal(); // handleToggleModal();
}, [dataToDelete, toggleNotification]); // }, [dataToDelete, toggleNotification]);
const handleToggle = () => setIsModalOpened(prev => !prev); // const handleToggle = () => setIsModalOpened(prev => !prev);
const handleToggleModal = () => setIsWarningDeleteAllOpened(prev => !prev); // const handleToggleModal = () => setIsWarningDeleteAllOpened(prev => !prev);
const updateSearchParams = (name, value, shouldDeleteSearch = false) => { // const updateSearchParams = (name, value, shouldDeleteSearch = false) => {
const currentSearch = new URLSearchParams(search); // const currentSearch = new URLSearchParams(search);
// Update the currentSearch // // Update the currentSearch
currentSearch.set(name, value); // currentSearch.set(name, value);
if (shouldDeleteSearch) { // if (shouldDeleteSearch) {
currentSearch.delete('_q'); // currentSearch.delete('_q');
} // }
push({ // push({
search: currentSearch.toString(), // search: currentSearch.toString(),
}); // });
}; // };
if (isLoadingForPermissions) { // if (isLoadingForPermissions) {
return <LoadingIndicatorPage />; // return <LoadingIndicatorPage />;
} // }
return ( // return (
<div> // <div>
<PageTitle name="Users" /> // <PageTitle name="Users" />
<Header // <Header
canCreate={canCreate} // canCreate={canCreate}
canDelete={canDelete} // canDelete={canDelete}
canRead={canRead} // canRead={canRead}
count={total} // count={total}
dataToDelete={dataToDelete} // dataToDelete={dataToDelete}
onClickAddUser={handleToggle} // onClickAddUser={handleToggle}
onClickDelete={handleToggleModal} // onClickDelete={handleToggleModal}
isLoading={isLoading} // isLoading={isLoading}
/> // />
{canRead && ( // {canRead && (
<> // <>
<BaselineAlignment top size="1px"> // <BaselineAlignment top size="1px">
<Flex flexWrap="wrap"> // <Flex flexWrap="wrap">
<SortPicker onChange={handleChangeSort} value={_sort} /> // <SortPicker onChange={handleChangeSort} value={_sort} />
<Padded right size="10px" /> // <Padded right size="10px" />
<BaselineAlignment bottom size="6px"> // <BaselineAlignment bottom size="6px">
<FilterPicker onChange={handleChangeFilter} /> // <FilterPicker onChange={handleChangeFilter} />
</BaselineAlignment> // </BaselineAlignment>
<Padded right size="10px" /> // <Padded right size="10px" />
{filters.map((filter, i) => ( // {filters.map((filter, i) => (
// eslint-disable-next-line react/no-array-index-key // // eslint-disable-next-line react/no-array-index-key
<Filter key={i} {...filter} onClick={handleClickDeleteFilter} /> // <Filter key={i} {...filter} onClick={handleClickDeleteFilter} />
))} // ))}
</Flex> // </Flex>
</BaselineAlignment> // </BaselineAlignment>
<BaselineAlignment top size="8px" /> // <BaselineAlignment top size="8px" />
<Padded top size="sm"> // <Padded top size="sm">
<List // <List
canDelete={canDelete} // canDelete={canDelete}
canUpdate={canUpdate} // canUpdate={canUpdate}
dataToDelete={dataToDelete} // dataToDelete={dataToDelete}
isLoading={isLoading} // isLoading={isLoading}
data={data} // data={data}
onChange={handleChangeDataToDelete} // onChange={handleChangeDataToDelete}
onClickDelete={handleClickDelete} // onClickDelete={handleClickDelete}
searchParam={_q} // searchParam={_q}
filters={filters} // filters={filters}
ref={listRef} // ref={listRef}
/> // />
</Padded> // </Padded>
<Footer // <Footer
count={total} // count={total}
onChange={handleChangeFooterParams} // onChange={handleChangeFooterParams}
params={{ _limit: pageSize, _page: page }} // params={{ _limit: pageSize, _page: page }}
/> // />
</> // </>
)} // )}
<ModalForm isOpen={isModalOpened} onClosed={handleCloseModal} onToggle={handleToggle} /> // <ModalForm isOpen={isModalOpened} onClosed={handleCloseModal} onToggle={handleToggle} />
<PopUpWarning // <PopUpWarning
isOpen={isWarningDeleteAllOpened} // isOpen={isWarningDeleteAllOpened}
onClosed={handleClosedModalDelete} // onClosed={handleClosedModalDelete}
onConfirm={handleConfirmDeleteData} // onConfirm={handleConfirmDeleteData}
toggleModal={handleToggleModal} // toggleModal={handleToggleModal}
isConfirmButtonLoading={showModalConfirmButtonLoading} // isConfirmButtonLoading={showModalConfirmButtonLoading}
/> // />
</div> // </div>
); // );
}; // };
export default ListPage; // export default ListPage;
export default () => 'Users - LV';

View File

@ -1,113 +1,126 @@
import React, { memo, useMemo } from 'react'; // import React, { memo, useMemo } from 'react';
import { // import {
BaselineAlignment, // BaselineAlignment,
CheckPagePermissions, // CheckPagePermissions,
NotAllowedInput, // NotAllowedInput,
SizedInput, // SizedInput,
useRBAC, // useRBAC,
} from '@strapi/helper-plugin'; // } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl'; // import { useIntl } from 'react-intl';
import { getRequestUrl } from '../../../../../admin/src/utils'; // import { getRequestUrl } from '../../../../../admin/src/utils';
import PageTitle from '../../../../../admin/src/components/SettingsPageTitle'; // import PageTitle from '../../../../../admin/src/components/SettingsPageTitle';
import ContainerFluid from '../../../../../admin/src/components/ContainerFluid'; // import ContainerFluid from '../../../../../admin/src/components/ContainerFluid';
import FormBloc from '../../../../../admin/src/components/FormBloc'; // import FormBloc from '../../../../../admin/src/components/FormBloc';
import { Header } from '../../../../../admin/src/components/Settings'; // import { Header } from '../../../../../admin/src/components/Settings';
import { useRolesList, useSettingsForm } from '../../../../../admin/src/hooks'; // import { useRolesList, useSettingsForm } from '../../../../../admin/src/hooks';
// import adminPermissions from '../../../../../admin/src/permissions';
// import { form, schema } from './utils';
// const ssoPermissions = {
// ...adminPermissions.settings.sso,
// readRoles: adminPermissions.settings.roles.read,
// };
// const SingleSignOn = () => {
// const { formatMessage } = useIntl();
// const {
// isLoading: isLoadingForPermissions,
// allowedActions: { canUpdate, canReadRoles },
// } = useRBAC(ssoPermissions);
// const [
// { formErrors, initialData, isLoading, modifiedData, showHeaderButtonLoader },
// // eslint-disable-next-line no-unused-vars
// dispatch,
// { handleCancel, handleChange, handleSubmit },
// ] = useSettingsForm(getRequestUrl('providers/options'), schema, () => {}, [
// 'autoRegister',
// 'defaultRole',
// ]);
// const { roles } = useRolesList(canReadRoles);
// const showLoader = useMemo(() => isLoadingForPermissions || isLoading, [
// isLoading,
// isLoadingForPermissions,
// ]);
// const options = useMemo(() => {
// return [
// <option key="placeholder" disabled value="">
// {formatMessage({ id: 'components.InputSelect.option.placeholder' })}
// </option>,
// ...roles.map(({ id, name }) => (
// <option key={id} value={id}>
// {name}
// </option>
// )),
// ];
// }, [roles, formatMessage]);
// return (
// <>
// <PageTitle name="SSO" />
// <form onSubmit={handleSubmit}>
// <ContainerFluid padding="0">
// <Header
// isLoading={showLoader}
// initialData={initialData}
// label={formatMessage({ id: 'Settings.sso.title' })}
// modifiedData={modifiedData}
// onCancel={handleCancel}
// content={formatMessage({ id: 'Settings.sso.description' })}
// showHeaderButtonLoader={showHeaderButtonLoader}
// />
// <BaselineAlignment top size="3px" />
// <FormBloc isLoading={showLoader}>
// {Object.keys(form).map(key => {
// // TODO: at some point it would be great to handle this in the upcoming input layout
// const type = key === 'defaultRole' && !canReadRoles ? 'notAllowed' : form[key].type;
// const description =
// key === 'defaultRole' && !canReadRoles
// ? form[key].notAllowedDescription
// : form[key].description;
// return (
// <SizedInput
// {...form[key]}
// customInputs={{ notAllowed: NotAllowedInput }}
// description={description}
// key={key}
// disabled={!canUpdate}
// error={formErrors[key]}
// name={key}
// onChange={handleChange}
// options={options}
// value={modifiedData[key]}
// type={type}
// />
// );
// })}
// </FormBloc>
// </ContainerFluid>
// </form>
// </>
// );
// };
import React from 'react';
import { CheckPagePermissions } from '@strapi/helper-plugin';
import adminPermissions from '../../../../../admin/src/permissions'; import adminPermissions from '../../../../../admin/src/permissions';
import { form, schema } from './utils';
const ssoPermissions = { const ssoPermissions = {
...adminPermissions.settings.sso, ...adminPermissions.settings.sso,
readRoles: adminPermissions.settings.roles.read, readRoles: adminPermissions.settings.roles.read,
}; };
const SingleSignOn = () => { // const ProtectedSSO = () => (
const { formatMessage } = useIntl(); // <CheckPagePermissions permissions={ssoPermissions.main}>
const { // <SingleSignOn />
isLoading: isLoadingForPermissions, // </CheckPagePermissions>
allowedActions: { canUpdate, canReadRoles }, // );
} = useRBAC(ssoPermissions);
const [
{ formErrors, initialData, isLoading, modifiedData, showHeaderButtonLoader },
// eslint-disable-next-line no-unused-vars
dispatch,
{ handleCancel, handleChange, handleSubmit },
] = useSettingsForm(getRequestUrl('providers/options'), schema, () => {}, [
'autoRegister',
'defaultRole',
]);
const { roles } = useRolesList(canReadRoles);
const showLoader = useMemo(() => isLoadingForPermissions || isLoading, [
isLoading,
isLoadingForPermissions,
]);
const options = useMemo(() => {
return [
<option key="placeholder" disabled value="">
{formatMessage({ id: 'components.InputSelect.option.placeholder' })}
</option>,
...roles.map(({ id, name }) => (
<option key={id} value={id}>
{name}
</option>
)),
];
}, [roles, formatMessage]);
return (
<>
<PageTitle name="SSO" />
<form onSubmit={handleSubmit}>
<ContainerFluid padding="0">
<Header
isLoading={showLoader}
initialData={initialData}
label={formatMessage({ id: 'Settings.sso.title' })}
modifiedData={modifiedData}
onCancel={handleCancel}
content={formatMessage({ id: 'Settings.sso.description' })}
showHeaderButtonLoader={showHeaderButtonLoader}
/>
<BaselineAlignment top size="3px" />
<FormBloc isLoading={showLoader}>
{Object.keys(form).map(key => {
// TODO: at some point it would be great to handle this in the upcoming input layout
const type = key === 'defaultRole' && !canReadRoles ? 'notAllowed' : form[key].type;
const description =
key === 'defaultRole' && !canReadRoles
? form[key].notAllowedDescription
: form[key].description;
return (
<SizedInput
{...form[key]}
customInputs={{ notAllowed: NotAllowedInput }}
description={description}
key={key}
disabled={!canUpdate}
error={formErrors[key]}
name={key}
onChange={handleChange}
options={options}
value={modifiedData[key]}
type={type}
/>
);
})}
</FormBloc>
</ContainerFluid>
</form>
</>
);
};
const ProtectedSSO = () => ( const ProtectedSSO = () => (
<CheckPagePermissions permissions={ssoPermissions.main}> <CheckPagePermissions permissions={ssoPermissions.main}>SingleSignOn</CheckPagePermissions>
<SingleSignOn />
</CheckPagePermissions>
); );
export default memo(ProtectedSSO); export default ProtectedSSO;