2021-02-11 15:38:08 +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';
|
|
|
|
import layout from '../temp/fakeData';
|
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-11 15:38:08 +01:00
|
|
|
const [{ modifiedData }, dispatch] = useReducer(reducer, initialState);
|
|
|
|
|
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-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={{
|
|
|
|
modifiedData,
|
|
|
|
onChangeSimpleCheckbox: handleChangeSimpleCheckbox,
|
|
|
|
onChangeParentCheckbox: handleChangeParentCheckbox,
|
2021-02-12 11:59:01 +01:00
|
|
|
onChangeCollectionTypeLeftActionRowCheckbox: handleChangeCollectionTypeLeftActionRowCheckbox,
|
2021-02-12 10:38:10 +01:00
|
|
|
}}
|
2021-02-11 15:38:08 +01:00
|
|
|
>
|
|
|
|
<Tabs tabsLabel={TAB_LABELS}>
|
|
|
|
<ContentTypes layout={layout.sections.collectionTypes} kind="collectionTypes" />
|
|
|
|
<ContentTypes layout={layout.sections.singleTypes} kind="singleTypes" />
|
|
|
|
<div>Plugins</div>
|
|
|
|
<div>Settings</div>
|
|
|
|
</Tabs>
|
|
|
|
</PermissionsDataManagerProvider>
|
2021-02-10 09:09:19 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Permissions.defaultProps = {
|
|
|
|
layout,
|
|
|
|
};
|
|
|
|
Permissions.propTypes = {
|
|
|
|
// Todo
|
|
|
|
layout: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default memo(Permissions);
|