2021-02-19 09:57:28 +01:00
|
|
|
import React, { forwardRef, memo, useCallback, useImperativeHandle, useReducer } from 'react';
|
2020-06-22 01:11:03 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-01 10:53:36 +02:00
|
|
|
import Tabs from '../Tabs';
|
2021-02-19 09:57:28 +01:00
|
|
|
import PermissionsDataManagerProvider from '../PermissionsDataManagerProvider';
|
|
|
|
import ContentTypes from '../ContentTypes';
|
|
|
|
import PluginsAndSettings from '../PluginsAndSettings';
|
|
|
|
import layout from '../temp/fakeData';
|
|
|
|
import TAB_LABELS from './utils/tabLabels';
|
|
|
|
import init from './init';
|
|
|
|
import reducer, { initialState } from './reducer';
|
2020-06-01 10:53:36 +02:00
|
|
|
|
2021-02-19 10:44:16 +01:00
|
|
|
const Permissions = forwardRef(({ layout, isFormDisabled }, ref) => {
|
2021-02-19 09:57:28 +01:00
|
|
|
const [{ layouts, modifiedData }, dispatch] = useReducer(reducer, initialState, () =>
|
|
|
|
init(layout)
|
2020-06-22 01:11:03 +02:00
|
|
|
);
|
|
|
|
|
2021-02-19 09:57:28 +01:00
|
|
|
useImperativeHandle(ref, () => {
|
|
|
|
return {
|
|
|
|
getPermissions: () => {
|
|
|
|
console.log('todo');
|
|
|
|
},
|
|
|
|
resetForm: () => {
|
|
|
|
console.log('todo');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2020-06-23 21:54:03 +02:00
|
|
|
|
2021-02-19 09:57:28 +01:00
|
|
|
const handleChangeCollectionTypeLeftActionRowCheckbox = (
|
|
|
|
pathToCollectionType,
|
|
|
|
propertyName,
|
|
|
|
rowName,
|
|
|
|
value
|
|
|
|
) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'ON_CHANGE_COLLECTION_TYPE_ROW_LEFT_CHECKBOX',
|
|
|
|
pathToCollectionType,
|
|
|
|
propertyName,
|
|
|
|
rowName,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
};
|
2020-06-23 21:54:03 +02:00
|
|
|
|
2021-02-19 09:57:28 +01:00
|
|
|
const handleChangeCollectionTypeGlobalActionCheckbox = (collectionTypeKind, actionId, value) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'ON_CHANGE_COLLECTION_TYPE_GLOBAL_ACTION_CHECKBOX',
|
|
|
|
collectionTypeKind,
|
|
|
|
actionId,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
};
|
2020-06-11 14:41:58 +02:00
|
|
|
|
2021-02-19 09:57:28 +01:00
|
|
|
const handleChangeConditions = conditions => {
|
|
|
|
dispatch({ type: 'ON_CHANGE_CONDITIONS', conditions });
|
|
|
|
};
|
2020-06-28 01:35:41 +02:00
|
|
|
|
2021-02-19 09:57:28 +01:00
|
|
|
const handleChangeSimpleCheckbox = useCallback(({ target: { name, value } }) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'ON_CHANGE_SIMPLE_CHECKBOX',
|
|
|
|
keys: name,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}, []);
|
2020-06-28 01:35:41 +02:00
|
|
|
|
2021-02-19 09:57:28 +01:00
|
|
|
const handleChangeParentCheckbox = useCallback(({ target: { name, value } }) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'ON_CHANGE_TOGGLE_PARENT_CHECKBOX',
|
|
|
|
keys: name,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}, []);
|
2020-06-01 10:53:36 +02:00
|
|
|
|
|
|
|
return (
|
2021-02-19 09:57:28 +01:00
|
|
|
<PermissionsDataManagerProvider
|
|
|
|
value={{
|
|
|
|
availableConditions: layout.conditions,
|
|
|
|
modifiedData,
|
|
|
|
onChangeConditions: handleChangeConditions,
|
|
|
|
onChangeSimpleCheckbox: handleChangeSimpleCheckbox,
|
|
|
|
onChangeParentCheckbox: handleChangeParentCheckbox,
|
|
|
|
onChangeCollectionTypeLeftActionRowCheckbox: handleChangeCollectionTypeLeftActionRowCheckbox,
|
|
|
|
onChangeCollectionTypeGlobalActionCheckbox: handleChangeCollectionTypeGlobalActionCheckbox,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Tabs tabsLabel={TAB_LABELS}>
|
2021-02-19 10:44:16 +01:00
|
|
|
<ContentTypes
|
|
|
|
layout={layouts.collectionTypes}
|
|
|
|
kind="collectionTypes"
|
|
|
|
isFormDisabled={isFormDisabled}
|
|
|
|
/>
|
|
|
|
<ContentTypes
|
|
|
|
layout={layouts.singleTypes}
|
|
|
|
kind="singleTypes"
|
|
|
|
isFormDisabled={isFormDisabled}
|
|
|
|
/>
|
|
|
|
<PluginsAndSettings
|
|
|
|
layout={layouts.plugins}
|
|
|
|
kind="plugins"
|
|
|
|
isFormDisabled={isFormDisabled}
|
|
|
|
/>
|
|
|
|
<PluginsAndSettings
|
|
|
|
layout={layouts.settings}
|
|
|
|
kind="settings"
|
|
|
|
isFormDisabled={isFormDisabled}
|
|
|
|
/>
|
2020-06-11 14:41:58 +02:00
|
|
|
</Tabs>
|
2021-02-19 09:57:28 +01:00
|
|
|
</PermissionsDataManagerProvider>
|
2020-06-01 10:53:36 +02:00
|
|
|
);
|
2020-06-23 21:54:03 +02:00
|
|
|
});
|
2020-06-01 10:53:36 +02:00
|
|
|
|
2020-07-08 12:02:46 +02:00
|
|
|
Permissions.defaultProps = {
|
2021-02-19 09:57:28 +01:00
|
|
|
layout,
|
2020-07-08 12:02:46 +02:00
|
|
|
};
|
2020-06-22 01:11:03 +02:00
|
|
|
Permissions.propTypes = {
|
2021-02-19 09:57:28 +01:00
|
|
|
layout: PropTypes.object,
|
2021-02-19 10:44:16 +01:00
|
|
|
isFormDisabled: PropTypes.bool.isRequired,
|
2020-06-22 01:11:03 +02:00
|
|
|
};
|
2020-08-31 10:17:12 +02:00
|
|
|
|
|
|
|
export default memo(Permissions);
|