2021-02-15 12:49:54 +01:00
|
|
|
import React, { forwardRef, memo, useCallback, useImperativeHandle, useReducer } from 'react';
|
2021-02-10 09:09:19 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Tabs } from '../../../../../../admin/src/components/Roles';
|
|
|
|
import { roleTabsLabel as TAB_LABELS } from '../../../../../../admin/src/utils';
|
2021-02-11 15:38:08 +01:00
|
|
|
import { PermissionsDataManagerProvider } from '../contexts/PermissionsDataManagerContext';
|
2021-02-10 09:09:19 +01:00
|
|
|
import ContentTypes from '../ContentTypes';
|
2021-02-15 10:45:47 +01:00
|
|
|
import PluginsAndSettings from '../PluginsAndSettings';
|
2021-02-10 09:09:19 +01:00
|
|
|
import layout from '../temp/fakeData';
|
2021-02-12 18:51:08 +01:00
|
|
|
import init from './init';
|
2021-02-11 15:38:08 +01:00
|
|
|
import reducer, { initialState } from './reducer';
|
2021-02-10 09:09:19 +01:00
|
|
|
|
|
|
|
const Permissions = forwardRef(({ layout }, ref) => {
|
2021-02-15 12:49:54 +01:00
|
|
|
const [{ layouts, modifiedData }, dispatch] = useReducer(reducer, initialState, () =>
|
|
|
|
init(layout)
|
|
|
|
);
|
2021-02-11 15:38:08 +01:00
|
|
|
|
2021-02-10 09:09:19 +01:00
|
|
|
useImperativeHandle(ref, () => {
|
|
|
|
return {
|
|
|
|
getPermissions: () => {
|
|
|
|
console.log('todo');
|
|
|
|
},
|
|
|
|
resetForm: () => {
|
|
|
|
console.log('todo');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2021-02-12 11:59:01 +01:00
|
|
|
|
|
|
|
const handleChangeCollectionTypeLeftActionRowCheckbox = (
|
|
|
|
pathToCollectionType,
|
|
|
|
propertyName,
|
|
|
|
rowName,
|
|
|
|
value
|
|
|
|
) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'ON_CHANGE_COLLECTION_TYPE_ROW_LEFT_CHECKBOX',
|
|
|
|
pathToCollectionType,
|
|
|
|
propertyName,
|
|
|
|
rowName,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
};
|
2021-02-10 09:09:19 +01:00
|
|
|
|
2021-02-12 15:14:09 +01:00
|
|
|
const handleChangeCollectionTypeGlobalActionCheckbox = (collectionTypeKind, actionId, value) => {
|
2021-02-12 12:14:53 +01:00
|
|
|
dispatch({
|
2021-02-12 15:14:09 +01:00
|
|
|
type: 'ON_CHANGE_COLLECTION_TYPE_GLOBAL_ACTION_CHECKBOX',
|
2021-02-12 12:14:53 +01:00
|
|
|
collectionTypeKind,
|
|
|
|
actionId,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-02-11 15:38:08 +01:00
|
|
|
const handleChangeSimpleCheckbox = useCallback(({ target: { name, value } }) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'ON_CHANGE_SIMPLE_CHECKBOX',
|
|
|
|
keys: name,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2021-02-12 10:38:10 +01:00
|
|
|
const handleChangeParentCheckbox = useCallback(({ target: { name, value } }) => {
|
|
|
|
dispatch({
|
|
|
|
type: 'ON_CHANGE_TOGGLE_PARENT_CHECKBOX',
|
|
|
|
keys: name,
|
|
|
|
value,
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
2021-02-10 09:09:19 +01:00
|
|
|
return (
|
2021-02-11 15:38:08 +01:00
|
|
|
<PermissionsDataManagerProvider
|
2021-02-12 10:38:10 +01:00
|
|
|
value={{
|
2021-02-16 15:16:16 +01:00
|
|
|
availableConditions: layout.conditions,
|
2021-02-12 10:38:10 +01:00
|
|
|
modifiedData,
|
|
|
|
onChangeSimpleCheckbox: handleChangeSimpleCheckbox,
|
|
|
|
onChangeParentCheckbox: handleChangeParentCheckbox,
|
2021-02-12 11:59:01 +01:00
|
|
|
onChangeCollectionTypeLeftActionRowCheckbox: handleChangeCollectionTypeLeftActionRowCheckbox,
|
2021-02-12 12:14:53 +01:00
|
|
|
onChangeCollectionTypeGlobalActionCheckbox: handleChangeCollectionTypeGlobalActionCheckbox,
|
2021-02-12 10:38:10 +01:00
|
|
|
}}
|
2021-02-11 15:38:08 +01:00
|
|
|
>
|
|
|
|
<Tabs tabsLabel={TAB_LABELS}>
|
2021-02-15 12:49:54 +01:00
|
|
|
<ContentTypes layout={layouts.collectionTypes} kind="collectionTypes" />
|
|
|
|
<ContentTypes layout={layouts.singleTypes} kind="singleTypes" />
|
|
|
|
<PluginsAndSettings layout={layouts.plugins} kind="plugins" />
|
|
|
|
<PluginsAndSettings layout={layouts.settings} kind="settings" />
|
2021-02-11 15:38:08 +01:00
|
|
|
</Tabs>
|
|
|
|
</PermissionsDataManagerProvider>
|
2021-02-10 09:09:19 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Permissions.defaultProps = {
|
|
|
|
layout,
|
|
|
|
};
|
|
|
|
Permissions.propTypes = {
|
|
|
|
// Todo
|
|
|
|
layout: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default memo(Permissions);
|