2018-02-28 14:57:45 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* EditForm
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2018-02-28 16:20:23 +01:00
|
|
|
import { findIndex, get, isEmpty, map } from 'lodash';
|
2018-02-28 14:57:45 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
// You can find these components in either
|
|
|
|
// ./node_modules/strapi-helper-plugin/lib/src
|
|
|
|
// or strapi/packages/strapi-helper-plugin/lib/src
|
2019-04-16 18:23:26 +02:00
|
|
|
import { InputsIndex as Input } from 'strapi-helper-plugin';
|
2019-09-10 16:34:43 +02:00
|
|
|
import Separator from '../Separator';
|
|
|
|
import Wrapper from './Wrapper';
|
2018-02-28 14:57:45 +01:00
|
|
|
|
2019-04-16 18:23:26 +02:00
|
|
|
class EditForm extends React.Component {
|
|
|
|
getProviderForm = () =>
|
|
|
|
get(
|
|
|
|
this.props.settings,
|
|
|
|
['providers', this.props.selectedProviderIndex, 'auth'],
|
2019-09-10 16:34:43 +02:00
|
|
|
{}
|
2019-04-16 18:23:26 +02:00
|
|
|
);
|
2018-02-28 16:20:23 +01:00
|
|
|
|
2019-04-16 18:23:26 +02:00
|
|
|
generateSelectOptions = () =>
|
|
|
|
Object.keys(get(this.props.settings, 'providers', {})).reduce(
|
|
|
|
(acc, current) => {
|
|
|
|
const option = {
|
|
|
|
id: get(this.props.settings, ['providers', current, 'name']),
|
|
|
|
value: get(this.props.settings, ['providers', current, 'provider']),
|
|
|
|
};
|
|
|
|
acc.push(option);
|
|
|
|
return acc;
|
|
|
|
},
|
2019-09-10 16:34:43 +02:00
|
|
|
[]
|
2019-04-16 18:23:26 +02:00
|
|
|
);
|
2018-02-28 14:57:45 +01:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2019-09-10 16:34:43 +02:00
|
|
|
<Wrapper>
|
2018-02-28 14:57:45 +01:00
|
|
|
<div className="row">
|
|
|
|
<Input
|
|
|
|
customBootstrapClass="col-md-6"
|
2019-04-16 18:23:26 +02:00
|
|
|
inputDescription={{
|
|
|
|
id: 'upload.EditForm.Input.select.inputDescription',
|
|
|
|
}}
|
2019-09-10 16:34:43 +02:00
|
|
|
inputClassName="inputStyle"
|
2018-02-28 14:57:45 +01:00
|
|
|
label={{ id: 'upload.EditForm.Input.select.label' }}
|
|
|
|
name="provider"
|
|
|
|
onChange={this.props.onChange}
|
|
|
|
selectOptions={this.generateSelectOptions()}
|
|
|
|
type="select"
|
|
|
|
value={get(this.props.modifiedData, 'provider')}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-02-28 16:20:23 +01:00
|
|
|
{!isEmpty(this.getProviderForm()) && (
|
2019-09-10 16:34:43 +02:00
|
|
|
<div className="subFormWrapper">
|
2018-02-28 16:20:23 +01:00
|
|
|
<div className="row">
|
|
|
|
{map(this.getProviderForm(), (value, key) => (
|
|
|
|
<Input
|
2018-02-28 17:11:44 +01:00
|
|
|
didCheckErrors={this.props.didCheckErrors}
|
2019-04-16 18:23:26 +02:00
|
|
|
errors={get(this.props.formErrors, [
|
|
|
|
findIndex(this.props.formErrors, ['name', key]),
|
|
|
|
'errors',
|
|
|
|
])}
|
2018-02-28 16:20:23 +01:00
|
|
|
key={key}
|
|
|
|
label={{ id: value.label }}
|
|
|
|
name={key}
|
|
|
|
onChange={this.props.onChange}
|
|
|
|
selectOptions={value.values}
|
|
|
|
type={value.type === 'enum' ? 'select' : value.type}
|
|
|
|
validations={{ required: true }}
|
|
|
|
value={get(this.props.modifiedData, key, '')}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2019-12-16 16:31:04 +01:00
|
|
|
<Separator style={{ marginBottom: 17 }} />
|
2018-02-28 14:57:45 +01:00
|
|
|
<div className="row">
|
|
|
|
<Input
|
2019-09-10 16:34:43 +02:00
|
|
|
inputClassName="inputStyle"
|
2018-02-28 14:57:45 +01:00
|
|
|
label={{ id: 'upload.EditForm.Input.number.label' }}
|
|
|
|
name="sizeLimit"
|
|
|
|
onChange={this.props.onChange}
|
|
|
|
type="number"
|
2019-02-28 16:28:06 +05:30
|
|
|
step={0.01}
|
2018-03-05 12:28:29 +01:00
|
|
|
value={get(this.props.modifiedData, 'sizeLimit', 1) / 1000}
|
2018-02-28 14:57:45 +01:00
|
|
|
/>
|
|
|
|
</div>
|
2019-09-10 16:34:43 +02:00
|
|
|
<Separator style={{ marginTop: '-4px' }} />
|
2018-02-28 14:57:45 +01:00
|
|
|
<div className="row">
|
|
|
|
<Input
|
|
|
|
label={{ id: 'upload.EditForm.Input.toggle.label' }}
|
|
|
|
name="enabled"
|
|
|
|
onChange={this.props.onChange}
|
|
|
|
type="toggle"
|
|
|
|
value={get(this.props.modifiedData, 'enabled', false)}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-09-10 16:34:43 +02:00
|
|
|
</Wrapper>
|
2018-02-28 14:57:45 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditForm.defaultProps = {
|
|
|
|
settings: {
|
|
|
|
providers: [],
|
|
|
|
},
|
|
|
|
};
|
2018-02-28 17:11:44 +01:00
|
|
|
|
2018-02-28 14:57:45 +01:00
|
|
|
EditForm.propTypes = {
|
2018-02-28 17:11:44 +01:00
|
|
|
didCheckErrors: PropTypes.bool.isRequired,
|
|
|
|
formErrors: PropTypes.array.isRequired,
|
2018-02-28 14:57:45 +01:00
|
|
|
modifiedData: PropTypes.object.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired,
|
2018-02-28 17:11:44 +01:00
|
|
|
selectedProviderIndex: PropTypes.number.isRequired,
|
2018-02-28 14:57:45 +01:00
|
|
|
settings: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditForm;
|