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';
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' },
to: '/settings/webhooks',

View File

@ -1,74 +1,75 @@
import React from 'react';
import { Header } from '@buffetjs/custom';
import { Flex, Padded, Text } from '@buffetjs/core';
import { useIntl } from 'react-intl';
import { BaselineAlignment, useAppInfos } from '@strapi/helper-plugin';
import Bloc from '../../components/Bloc';
import PageTitle from '../../components/SettingsPageTitle';
import { Detail, InfoText } from './components';
// import React from 'react';
// import { Header } from '@buffetjs/custom';
// import { Flex, Padded, Text } from '@buffetjs/core';
// import { useIntl } from 'react-intl';
// import { BaselineAlignment, useAppInfos } from '@strapi/helper-plugin';
// import Bloc from '../../components/Bloc';
// import PageTitle from '../../components/SettingsPageTitle';
// import { Detail, InfoText } from './components';
const ApplicationInfosPage = () => {
const appInfos = useAppInfos();
const { shouldUpdateStrapi, latestStrapiReleaseTag } = appInfos;
const { formatMessage } = useIntl();
// const ApplicationInfosPage = () => {
// const appInfos = useAppInfos();
// const { shouldUpdateStrapi, latestStrapiReleaseTag } = appInfos;
// const { formatMessage } = useIntl();
const currentPlan = appInfos.communityEdition
? 'app.components.UpgradePlanModal.text-ce'
: 'app.components.UpgradePlanModal.text-ee';
// const currentPlan = appInfos.communityEdition
// ? 'app.components.UpgradePlanModal.text-ce'
// : 'app.components.UpgradePlanModal.text-ee';
const headerProps = {
title: { label: formatMessage({ id: 'Settings.application.title' }) },
content: formatMessage({
id: 'Settings.application.description',
}),
};
const pricingLabel = formatMessage({ id: 'Settings.application.link-pricing' });
const upgradeLabel = formatMessage({ id: 'Settings.application.link-upgrade' });
const strapiVersion = formatMessage({ id: 'Settings.application.strapi-version' });
const nodeVersion = formatMessage({ id: 'Settings.application.node-version' });
const editionTitle = formatMessage({ id: 'Settings.application.edition-title' });
// const headerProps = {
// title: { label: formatMessage({ id: 'Settings.application.title' }) },
// content: formatMessage({
// id: 'Settings.application.description',
// }),
// };
// const pricingLabel = formatMessage({ id: 'Settings.application.link-pricing' });
// const upgradeLabel = formatMessage({ id: 'Settings.application.link-upgrade' });
// const strapiVersion = formatMessage({ id: 'Settings.application.strapi-version' });
// const nodeVersion = formatMessage({ id: 'Settings.application.node-version' });
// const editionTitle = formatMessage({ id: 'Settings.application.edition-title' });
/* eslint-disable indent */
const upgradeLink = shouldUpdateStrapi
? {
label: upgradeLabel,
href: `https://github.com/strapi/strapi/releases/tag/${latestStrapiReleaseTag}`,
}
: null;
/* eslint-enable indent */
// /* eslint-disable indent */
// const upgradeLink = shouldUpdateStrapi
// ? {
// label: upgradeLabel,
// href: `https://github.com/strapi/strapi/releases/tag/${latestStrapiReleaseTag}`,
// }
// : null;
// /* eslint-enable indent */
return (
<div>
<PageTitle name="Application" />
<Header {...headerProps} />
<BaselineAlignment top size="3px" />
<Bloc>
<Padded left right top size="smd">
<Padded left right top size="xs">
<Flex justifyContent="space-between">
<Detail
link={upgradeLink}
title={strapiVersion}
content={`v${appInfos.strapiVersion}`}
/>
<Detail
link={{ label: pricingLabel, href: 'https://strapi.io/pricing' }}
title={editionTitle}
content={formatMessage({ id: currentPlan })}
/>
</Flex>
<Padded top size="lg">
<Text fontSize="xs" color="grey" fontWeight="bold">
{nodeVersion}
</Text>
<InfoText content={appInfos.nodeVersion} />
</Padded>
</Padded>
</Padded>
<BaselineAlignment top size="60px" />
</Bloc>
</div>
);
};
// return (
// <div>
// <PageTitle name="Application" />
// <Header {...headerProps} />
// <BaselineAlignment top size="3px" />
// <Bloc>
// <Padded left right top size="smd">
// <Padded left right top size="xs">
// <Flex justifyContent="space-between">
// <Detail
// link={upgradeLink}
// title={strapiVersion}
// content={`v${appInfos.strapiVersion}`}
// />
// <Detail
// link={{ label: pricingLabel, href: 'https://strapi.io/pricing' }}
// title={editionTitle}
// content={formatMessage({ id: currentPlan })}
// />
// </Flex>
// <Padded top size="lg">
// <Text fontSize="xs" color="grey" fontWeight="bold">
// {nodeVersion}
// </Text>
// <InfoText content={appInfos.nodeVersion} />
// </Padded>
// </Padded>
// </Padded>
// <BaselineAlignment top size="60px" />
// </Bloc>
// </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 {
BaselineAlignment,
useQuery,
request,
useRBAC,
LoadingIndicatorPage,
PopUpWarning,
useNotification,
} from '@strapi/helper-plugin';
import { get } from 'lodash';
import { useHistory, useLocation } from 'react-router-dom';
import { Flex, Padded } from '@buffetjs/core';
import PageTitle from '../../../components/SettingsPageTitle';
import { useSettingsHeaderSearchContext } from '../../../hooks';
import { Footer, List, Filter, FilterPicker, SortPicker } from '../../../components/Users';
import adminPermissions from '../../../permissions';
import Header from './Header';
import ModalForm from './ModalForm';
import getFilters from './utils/getFilters';
import init from './init';
import { initialState, reducer } from './reducer';
// import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
// import {
// BaselineAlignment,
// useQuery,
// request,
// useRBAC,
// LoadingIndicatorPage,
// PopUpWarning,
// useNotification,
// } from '@strapi/helper-plugin';
// import { get } from 'lodash';
// import { useHistory, useLocation } from 'react-router-dom';
// import { Flex, Padded } from '@buffetjs/core';
// import PageTitle from '../../../components/SettingsPageTitle';
// import { useSettingsHeaderSearchContext } from '../../../hooks';
// import { Footer, List, Filter, FilterPicker, SortPicker } from '../../../components/Users';
// import adminPermissions from '../../../permissions';
// import Header from './Header';
// import ModalForm from './ModalForm';
// import getFilters from './utils/getFilters';
// import init from './init';
// import { initialState, reducer } from './reducer';
const ListPage = () => {
const {
isLoading: isLoadingForPermissions,
allowedActions: { canCreate, canDelete, canRead, canUpdate },
} = useRBAC(adminPermissions.settings.users);
const toggleNotification = useNotification();
const [isWarningDeleteAllOpened, setIsWarningDeleteAllOpened] = useState(false);
const [isModalOpened, setIsModalOpened] = useState(false);
const { toggleHeaderSearch } = useSettingsHeaderSearchContext();
const query = useQuery();
const { push } = useHistory();
const { search } = useLocation();
const filters = useMemo(() => {
return getFilters(search);
}, [search]);
// const ListPage = () => {
// const {
// isLoading: isLoadingForPermissions,
// allowedActions: { canCreate, canDelete, canRead, canUpdate },
// } = useRBAC(adminPermissions.settings.users);
// const toggleNotification = useNotification();
// const [isWarningDeleteAllOpened, setIsWarningDeleteAllOpened] = useState(false);
// const [isModalOpened, setIsModalOpened] = useState(false);
// const { toggleHeaderSearch } = useSettingsHeaderSearchContext();
// const query = useQuery();
// const { push } = useHistory();
// const { search } = useLocation();
// const filters = useMemo(() => {
// return getFilters(search);
// }, [search]);
const [
{
data,
dataToDelete,
isLoading,
pagination: { total },
shouldRefetchData,
showModalConfirmButtonLoading,
},
dispatch,
] = useReducer(reducer, initialState, init);
const pageSize = parseInt(query.get('pageSize') || 10, 10);
const page = parseInt(query.get('page') || 0, 10);
const _sort = decodeURIComponent(query.get('_sort'));
const _q = decodeURIComponent(query.get('_q') || '');
const getDataRef = useRef();
const listRef = useRef();
// const [
// {
// data,
// dataToDelete,
// isLoading,
// pagination: { total },
// shouldRefetchData,
// showModalConfirmButtonLoading,
// },
// dispatch,
// ] = useReducer(reducer, initialState, init);
// const pageSize = parseInt(query.get('pageSize') || 10, 10);
// const page = parseInt(query.get('page') || 0, 10);
// const _sort = decodeURIComponent(query.get('_sort'));
// const _q = decodeURIComponent(query.get('_q') || '');
// const getDataRef = useRef();
// const listRef = useRef();
getDataRef.current = async () => {
if (!canRead) {
dispatch({
type: 'UNSET_IS_LOADING',
});
// getDataRef.current = async () => {
// if (!canRead) {
// dispatch({
// type: 'UNSET_IS_LOADING',
// });
return;
}
// Show the loading state and reset the state
dispatch({
type: 'GET_DATA',
});
// return;
// }
// // Show the loading state and reset the state
// dispatch({
// type: 'GET_DATA',
// });
try {
const {
data: { results, pagination },
} = await request(`/admin/users${search}`, { method: 'GET' });
// try {
// const {
// data: { results, pagination },
// } = await request(`/admin/users${search}`, { method: 'GET' });
dispatch({
type: 'GET_DATA_SUCCEEDED',
data: results,
pagination,
});
} catch (err) {
console.error(err.response);
toggleNotification({
type: 'warning',
message: { id: 'notification.error' },
});
}
};
// dispatch({
// type: 'GET_DATA_SUCCEEDED',
// data: results,
// pagination,
// });
// } catch (err) {
// console.error(err.response);
// toggleNotification({
// type: 'warning',
// message: { id: 'notification.error' },
// });
// }
// };
useEffect(() => {
if (!isLoadingForPermissions) {
getDataRef.current();
}
}, [search, isLoadingForPermissions]);
// useEffect(() => {
// if (!isLoadingForPermissions) {
// getDataRef.current();
// }
// }, [search, isLoadingForPermissions]);
useEffect(() => {
if (canRead) {
toggleHeaderSearch({ id: 'Settings.permissions.menu.link.users.label' });
}
// useEffect(() => {
// if (canRead) {
// toggleHeaderSearch({ id: 'Settings.permissions.menu.link.users.label' });
// }
return () => {
if (canRead) {
toggleHeaderSearch();
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [canRead]);
// return () => {
// if (canRead) {
// toggleHeaderSearch();
// }
// };
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [canRead]);
const handleChangeDataToDelete = ids => {
dispatch({
type: 'ON_CHANGE_DATA_TO_DELETE',
dataToDelete: ids,
});
};
// const handleChangeDataToDelete = ids => {
// dispatch({
// type: 'ON_CHANGE_DATA_TO_DELETE',
// dataToDelete: ids,
// });
// };
const handleChangeFilter = ({ filter, name, value }) => {
const filterName = `${name}${filter}`;
// const handleChangeFilter = ({ filter, name, value }) => {
// const filterName = `${name}${filter}`;
updateSearchParams(filterName, encodeURIComponent(value), true);
};
// updateSearchParams(filterName, encodeURIComponent(value), true);
// };
const handleChangeFooterParams = ({ target: { name, value } }) => {
let paramName = name.split('.')[1].replace('_', '');
// const handleChangeFooterParams = ({ target: { name, value } }) => {
// let paramName = name.split('.')[1].replace('_', '');
if (paramName === 'limit') {
paramName = 'pageSize';
}
// if (paramName === 'limit') {
// paramName = 'pageSize';
// }
updateSearchParams(paramName, value);
};
// updateSearchParams(paramName, value);
// };
const handleChangeSort = ({ target: { name, value } }) => {
updateSearchParams(name, value);
};
// const handleChangeSort = ({ target: { name, value } }) => {
// updateSearchParams(name, value);
// };
const handleClickDeleteFilter = ({ target: { name } }) => {
const currentSearch = new URLSearchParams(search);
// const handleClickDeleteFilter = ({ target: { name } }) => {
// const currentSearch = new URLSearchParams(search);
currentSearch.delete(name);
// currentSearch.delete(name);
push({ search: currentSearch.toString() });
};
// push({ search: currentSearch.toString() });
// };
const handleClickDelete = useCallback(id => {
handleToggleModal();
// const handleClickDelete = useCallback(id => {
// handleToggleModal();
dispatch({
type: 'ON_CHANGE_DATA_TO_DELETE',
dataToDelete: [id],
});
}, []);
// dispatch({
// type: 'ON_CHANGE_DATA_TO_DELETE',
// dataToDelete: [id],
// });
// }, []);
const handleCloseModal = () => {
// Refetch data
getDataRef.current();
};
// const handleCloseModal = () => {
// // Refetch data
// getDataRef.current();
// };
const handleClosedModalDelete = () => {
if (shouldRefetchData) {
getDataRef.current();
} else {
// Empty the selected ids when the modal closes
dispatch({
type: 'RESET_DATA_TO_DELETE',
});
// const handleClosedModalDelete = () => {
// if (shouldRefetchData) {
// getDataRef.current();
// } else {
// // Empty the selected ids when the modal closes
// dispatch({
// type: 'RESET_DATA_TO_DELETE',
// });
// Reset the list's reducer dataToDelete state using a ref so we don't need an effect
listRef.current.resetDataToDelete();
}
};
// // Reset the list's reducer dataToDelete state using a ref so we don't need an effect
// listRef.current.resetDataToDelete();
// }
// };
const handleConfirmDeleteData = useCallback(async () => {
dispatch({
type: 'ON_DELETE_USERS',
});
// const handleConfirmDeleteData = useCallback(async () => {
// dispatch({
// type: 'ON_DELETE_USERS',
// });
let shouldDispatchSucceededAction = false;
// let shouldDispatchSucceededAction = false;
try {
await request('/admin/users/batch-delete', {
method: 'POST',
body: {
ids: dataToDelete,
},
});
shouldDispatchSucceededAction = true;
} catch (err) {
const errorMessage = get(err, 'response.payload.data', 'An error occured');
// try {
// await request('/admin/users/batch-delete', {
// method: 'POST',
// body: {
// ids: dataToDelete,
// },
// });
// shouldDispatchSucceededAction = true;
// } catch (err) {
// const errorMessage = get(err, 'response.payload.data', 'An error occured');
toggleNotification({
type: 'warning',
message: errorMessage,
});
}
// toggleNotification({
// type: 'warning',
// message: errorMessage,
// });
// }
// Only dispatch the action once
if (shouldDispatchSucceededAction) {
dispatch({
type: 'ON_DELETE_USERS_SUCCEEDED',
});
}
// // Only dispatch the action once
// if (shouldDispatchSucceededAction) {
// dispatch({
// type: 'ON_DELETE_USERS_SUCCEEDED',
// });
// }
handleToggleModal();
}, [dataToDelete, toggleNotification]);
// handleToggleModal();
// }, [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 currentSearch = new URLSearchParams(search);
// Update the currentSearch
currentSearch.set(name, value);
// const updateSearchParams = (name, value, shouldDeleteSearch = false) => {
// const currentSearch = new URLSearchParams(search);
// // Update the currentSearch
// currentSearch.set(name, value);
if (shouldDeleteSearch) {
currentSearch.delete('_q');
}
// if (shouldDeleteSearch) {
// currentSearch.delete('_q');
// }
push({
search: currentSearch.toString(),
});
};
// push({
// search: currentSearch.toString(),
// });
// };
if (isLoadingForPermissions) {
return <LoadingIndicatorPage />;
}
// if (isLoadingForPermissions) {
// return <LoadingIndicatorPage />;
// }
return (
<div>
<PageTitle name="Users" />
<Header
canCreate={canCreate}
canDelete={canDelete}
canRead={canRead}
count={total}
dataToDelete={dataToDelete}
onClickAddUser={handleToggle}
onClickDelete={handleToggleModal}
isLoading={isLoading}
/>
{canRead && (
<>
<BaselineAlignment top size="1px">
<Flex flexWrap="wrap">
<SortPicker onChange={handleChangeSort} value={_sort} />
<Padded right size="10px" />
<BaselineAlignment bottom size="6px">
<FilterPicker onChange={handleChangeFilter} />
</BaselineAlignment>
<Padded right size="10px" />
{filters.map((filter, i) => (
// eslint-disable-next-line react/no-array-index-key
<Filter key={i} {...filter} onClick={handleClickDeleteFilter} />
))}
</Flex>
</BaselineAlignment>
<BaselineAlignment top size="8px" />
<Padded top size="sm">
<List
canDelete={canDelete}
canUpdate={canUpdate}
dataToDelete={dataToDelete}
isLoading={isLoading}
data={data}
onChange={handleChangeDataToDelete}
onClickDelete={handleClickDelete}
searchParam={_q}
filters={filters}
ref={listRef}
/>
</Padded>
<Footer
count={total}
onChange={handleChangeFooterParams}
params={{ _limit: pageSize, _page: page }}
/>
</>
)}
<ModalForm isOpen={isModalOpened} onClosed={handleCloseModal} onToggle={handleToggle} />
<PopUpWarning
isOpen={isWarningDeleteAllOpened}
onClosed={handleClosedModalDelete}
onConfirm={handleConfirmDeleteData}
toggleModal={handleToggleModal}
isConfirmButtonLoading={showModalConfirmButtonLoading}
/>
</div>
);
};
// return (
// <div>
// <PageTitle name="Users" />
// <Header
// canCreate={canCreate}
// canDelete={canDelete}
// canRead={canRead}
// count={total}
// dataToDelete={dataToDelete}
// onClickAddUser={handleToggle}
// onClickDelete={handleToggleModal}
// isLoading={isLoading}
// />
// {canRead && (
// <>
// <BaselineAlignment top size="1px">
// <Flex flexWrap="wrap">
// <SortPicker onChange={handleChangeSort} value={_sort} />
// <Padded right size="10px" />
// <BaselineAlignment bottom size="6px">
// <FilterPicker onChange={handleChangeFilter} />
// </BaselineAlignment>
// <Padded right size="10px" />
// {filters.map((filter, i) => (
// // eslint-disable-next-line react/no-array-index-key
// <Filter key={i} {...filter} onClick={handleClickDeleteFilter} />
// ))}
// </Flex>
// </BaselineAlignment>
// <BaselineAlignment top size="8px" />
// <Padded top size="sm">
// <List
// canDelete={canDelete}
// canUpdate={canUpdate}
// dataToDelete={dataToDelete}
// isLoading={isLoading}
// data={data}
// onChange={handleChangeDataToDelete}
// onClickDelete={handleClickDelete}
// searchParam={_q}
// filters={filters}
// ref={listRef}
// />
// </Padded>
// <Footer
// count={total}
// onChange={handleChangeFooterParams}
// params={{ _limit: pageSize, _page: page }}
// />
// </>
// )}
// <ModalForm isOpen={isModalOpened} onClosed={handleCloseModal} onToggle={handleToggle} />
// <PopUpWarning
// isOpen={isWarningDeleteAllOpened}
// onClosed={handleClosedModalDelete}
// onConfirm={handleConfirmDeleteData}
// toggleModal={handleToggleModal}
// isConfirmButtonLoading={showModalConfirmButtonLoading}
// />
// </div>
// );
// };
export default ListPage;
// export default ListPage;
export default () => 'Users - LV';

View File

@ -1,113 +1,126 @@
import React, { memo, useMemo } from 'react';
import {
BaselineAlignment,
CheckPagePermissions,
NotAllowedInput,
SizedInput,
useRBAC,
} from '@strapi/helper-plugin';
import { useIntl } from 'react-intl';
import { getRequestUrl } from '../../../../../admin/src/utils';
import PageTitle from '../../../../../admin/src/components/SettingsPageTitle';
import ContainerFluid from '../../../../../admin/src/components/ContainerFluid';
import FormBloc from '../../../../../admin/src/components/FormBloc';
import { Header } from '../../../../../admin/src/components/Settings';
import { useRolesList, useSettingsForm } from '../../../../../admin/src/hooks';
// import React, { memo, useMemo } from 'react';
// import {
// BaselineAlignment,
// CheckPagePermissions,
// NotAllowedInput,
// SizedInput,
// useRBAC,
// } from '@strapi/helper-plugin';
// import { useIntl } from 'react-intl';
// import { getRequestUrl } from '../../../../../admin/src/utils';
// import PageTitle from '../../../../../admin/src/components/SettingsPageTitle';
// import ContainerFluid from '../../../../../admin/src/components/ContainerFluid';
// import FormBloc from '../../../../../admin/src/components/FormBloc';
// import { Header } from '../../../../../admin/src/components/Settings';
// 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 { 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>
</>
);
};
// const ProtectedSSO = () => (
// <CheckPagePermissions permissions={ssoPermissions.main}>
// <SingleSignOn />
// </CheckPagePermissions>
// );
const ProtectedSSO = () => (
<CheckPagePermissions permissions={ssoPermissions.main}>
<SingleSignOn />
</CheckPagePermissions>
<CheckPagePermissions permissions={ssoPermissions.main}>SingleSignOn</CheckPagePermissions>
);
export default memo(ProtectedSSO);
export default ProtectedSSO;