Created sso settings page

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-12-23 19:59:50 +01:00 committed by Convly
parent 41b1c11bb1
commit 4000243107
3 changed files with 7 additions and 172 deletions

View File

@ -1,122 +1,27 @@
import React, {
memo,
// useCallback,
// useEffect,
useMemo,
// useReducer, useRef
} from 'react';
import {
BaselineAlignment,
SizedInput,
useGlobalContext,
// request
} from 'strapi-helper-plugin';
import {
// checkFormValidity,
getRequestUrl,
} from '../../../../../admin/src/utils';
import React, { memo, useMemo } from 'react';
import { BaselineAlignment, SizedInput } 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, useUsersForm } from '../../../../../admin/src/hooks';
import { useRolesList, useUsersForm as useForm } from '../../../../../admin/src/hooks';
import { form, schema } from './utils';
// import reducer, { initialState } from './reducer';
const SingleSignOn = () => {
const { formatMessage } = useGlobalContext();
// const [
// { formErrors, isLoading, initialData, modifiedData, showHeaderButtonLoader },
// dispatch,
// ] = useReducer(reducer, initialState);
const { formatMessage } = useIntl();
const [
{ formErrors, initialData, isLoading, modifiedData, showHeaderButtonLoader },
// eslint-disable-next-line no-unused-vars
dispatch,
{ handleCancel, handleChange, handleSubmit },
] = useUsersForm(getRequestUrl('providers/options'), schema, () => {}, [
] = useForm(getRequestUrl('providers/options'), schema, () => {}, [
'autoRegister',
'defaultRole',
]);
const { roles, isLoading: isLoadingForRoles } = useRolesList();
// useEffect(() => {
// const abortController = new AbortController();
// const { signal } = abortController;
// const getData = async signal => {
// try {
// dispatch({ type: 'GET_DATA' });
// const data = await request(getRequestUrl('providers/options'), {
// method: 'GET',
// signal,
// });
// dispatch({
// type: 'GET_DATA_SUCCEEDED',
// data,
// });
// } catch (err) {
// console.error(err);
// }
// };
// getData(signal);
// return () => {
// abortController.abort();
// };
// }, []);
// const handleCancel = useCallback(() => {
// dispatch({ type: 'ON_CANCEL' });
// }, []);
// const handleChange = useCallback(({ target: { name, value } }) => {
// dispatch({
// type: 'ON_CHANGE',
// keys: name,
// value,
// });
// }, []);
// const handleSubmit = useCallback(
// async e => {
// e.preventDefault();
// const errors = await checkFormValidity(modifiedData, schema);
// dispatch({
// type: 'SET_ERRORS',
// errors: errors || {},
// });
// if (!errors) {
// try {
// strapi.lockAppWithOverlay();
// dispatch({ type: 'ON_SUBMIT' });
// const data = await request(getRequestUrl('providers/options'), {
// method: 'PUT',
// body: modifiedData,
// });
// dispatch({
// type: 'ON_SUBMIT_SUCCEEDED',
// data,
// });
// strapi.notification.toggle({
// type: 'success',
// message: { id: 'notification.success.saved' },
// });
// } catch (err) {
// console.error(err);
// }
// }
// },
// [modifiedData]
// );
const showLoader = useMemo(() => isLoadingForRoles || isLoading, [isLoading, isLoadingForRoles]);
const options = useMemo(() => {

View File

@ -1,59 +0,0 @@
/* eslint-disable consistent-return */
import produce from 'immer';
import { set } from 'lodash';
const initialState = {
formErrors: {},
initialData: {},
modifiedData: {},
isLoading: true,
showHeaderButtonLoader: false,
};
const reducer = (state, action) =>
produce(state, draftState => {
switch (action.type) {
case 'GET_DATA': {
draftState.isLoading = true;
draftState.initialData = {};
draftState.modifiedData = {};
break;
}
case 'GET_DATA_SUCCEEDED': {
draftState.isLoading = false;
draftState.initialData = action.data;
draftState.modifiedData = action.data;
break;
}
case 'ON_CHANGE': {
set(draftState.modifiedData, action.keys.split('.'), action.value);
draftState.formErrors = {};
break;
}
case 'ON_CANCEL': {
draftState.modifiedData = state.initialData;
draftState.formErrors = {};
break;
}
case 'ON_SUBMIT': {
draftState.showHeaderButtonLoader = true;
break;
}
case 'ON_SUBMIT_SUCCEEDED': {
draftState.initialData = action.data;
draftState.modifiedData = action.data;
draftState.showHeaderButtonLoader = false;
break;
}
case 'SET_ERRORS': {
draftState.formErrors = action.errors;
// draftState.showHeaderButtonLoader = false;
break;
}
default:
return draftState;
}
});
export default reducer;
export { initialState };

View File

@ -1,11 +0,0 @@
import styled from 'styled-components';
const SettingsPageWrapper = styled.div`
padding: 25px 10px;
margin-top: 33px;
border-radius: ${({ theme }) => theme.main.sizes.borderRadius};
box-shadow: 0 2px 4px ${({ theme }) => theme.main.colors.darkGrey};
background: ${({ theme }) => theme.main.colors.white};
`;
export default SettingsPageWrapper;