import React, { useReducer } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; // import { get } from 'lodash'; import pluginId from '../../pluginId'; import useDataManager from '../../hooks/useDataManager'; import Button from './AddFieldButton'; import DraggedItem from './DraggedItem'; import EmptyComponent from './EmptyComponent'; import init from './init'; import reducer, { initialState } from './reducer'; const RepeatableComponent = ({ componentValue, componentValueLength, // componentUid, fields, name, schema, }) => { const { addRepeatableComponentToField, // modifiedData, // removeComponentFromField, } = useDataManager(); const [state, dispatch] = useReducer(reducer, initialState, () => init(initialState, componentValue) ); const { collapses } = state.toJS(); console.log({ state: state.toJS(), fields, schema }); return (
{componentValueLength === 0 && ( {msg =>

{msg}

}
)} {componentValueLength > 0 && componentValue.map((data, index) => { const componentFieldName = `${name}.${index}`; console.log({ componentFieldName }); return ( { dispatch({ type: 'TOGGLE_COLLAPSE', index, }); }} schema={schema} componentFieldName={componentFieldName} /> ); })}
); }; RepeatableComponent.defaultProps = { componentValue: null, componentValueLength: 0, fields: [], }; RepeatableComponent.propTypes = { componentValue: PropTypes.oneOfType([PropTypes.array, PropTypes.object]), componentValueLength: PropTypes.number, fields: PropTypes.array, name: PropTypes.string.isRequired, schema: PropTypes.object.isRequired, }; export default RepeatableComponent;