131 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-10-15 15:12:53 +02:00
import React from 'react';
import PropTypes from 'prop-types';
2019-10-15 16:36:50 +02:00
import { get } from 'lodash';
2019-10-15 15:12:53 +02:00
import { withRouter } from 'react-router-dom';
2019-10-16 16:00:24 +02:00
import { FormattedMessage } from 'react-intl';
import { Inputs as Input } from '@buffetjs/custom';
2019-10-15 16:36:50 +02:00
import {
BackHeader,
PluginHeader,
LoadingIndicatorPage,
} from 'strapi-helper-plugin';
2019-10-15 15:12:53 +02:00
import Block from '../Block';
import Container from '../Container';
import SectionTitle from '../SectionTitle';
2019-10-15 16:36:50 +02:00
import Separator from '../Separator';
2019-10-15 15:12:53 +02:00
const SettingsViewWrapper = ({
2019-10-15 18:32:19 +02:00
children,
2019-10-15 16:36:50 +02:00
getSelectOptions,
2019-10-15 15:12:53 +02:00
history: { goBack },
2019-10-15 16:36:50 +02:00
inputs,
isLoading,
modifiedData,
onChange,
2019-10-15 15:12:53 +02:00
onSubmit,
pluginHeaderProps,
}) => {
2019-10-15 16:36:50 +02:00
if (isLoading) {
return <LoadingIndicatorPage />;
}
2019-10-15 15:12:53 +02:00
return (
<>
<BackHeader onClick={goBack} />
<Container className="container-fluid">
<form onSubmit={onSubmit}>
<PluginHeader {...pluginHeaderProps} />
<div className="row">
<Block
style={{
marginBottom: '13px',
paddingBottom: '30px',
paddingTop: '24px',
}}
>
<SectionTitle isSettings />
2019-10-15 16:36:50 +02:00
<div className="row">
{inputs.map(input => {
return (
2019-10-16 16:00:24 +02:00
<FormattedMessage key={input.name} id={input.label.id}>
{label => (
<div className={input.customBootstrapClass}>
<FormattedMessage
id={get(
input,
'description.id',
'app.utils.defaultMessage'
)}
>
{description => (
<Input
{...input}
description={description}
label={label === ' ' ? null : label}
onChange={onChange}
options={getSelectOptions(input)}
value={get(modifiedData, input.name, '')}
/>
)}
</FormattedMessage>
</div>
)}
</FormattedMessage>
2019-10-15 16:36:50 +02:00
);
})}
<div className="col-12">
<Separator />
</div>
</div>
2019-10-15 18:32:19 +02:00
<SectionTitle />
{children}
2019-10-15 15:12:53 +02:00
</Block>
</div>
</form>
</Container>
</>
);
};
SettingsViewWrapper.defaultProps = {
2019-10-15 16:36:50 +02:00
getSelectOptions: () => {},
inputs: [],
modifiedData: {},
2019-10-15 15:12:53 +02:00
onSubmit: () => {},
pluginHeaderProps: {
actions: [],
description: {
id: 'app.utils.defaultMessage',
},
title: {
id: 'app.utils.defaultMessage',
values: {},
},
},
};
SettingsViewWrapper.propTypes = {
2019-10-15 18:32:19 +02:00
children: PropTypes.node.isRequired,
2019-10-15 16:36:50 +02:00
getSelectOptions: PropTypes.func,
2019-10-15 15:12:53 +02:00
history: PropTypes.shape({
goBack: PropTypes.func.isRequired,
}).isRequired,
2019-10-15 16:36:50 +02:00
inputs: PropTypes.array,
isLoading: PropTypes.bool.isRequired,
modifiedData: PropTypes.object,
onChange: PropTypes.func.isRequired,
2019-10-15 15:12:53 +02:00
onSubmit: PropTypes.func,
pluginHeaderProps: PropTypes.shape({
actions: PropTypes.array,
description: PropTypes.shape({
id: PropTypes.string,
}),
title: PropTypes.shape({
id: PropTypes.string,
values: PropTypes.object,
}),
}),
};
export default withRouter(SettingsViewWrapper);