2021-02-15 14:55:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { Label } from '@buffetjs/core';
|
|
|
|
|
import { Inputs } from '@buffetjs/custom';
|
|
|
|
|
import Select from 'react-select';
|
|
|
|
|
import { Col, Row } from 'reactstrap';
|
|
|
|
|
import { useIntl } from 'react-intl';
|
2021-02-25 15:29:15 +01:00
|
|
|
import { BaselineAlignment } from 'strapi-helper-plugin';
|
2021-02-15 14:55:08 +01:00
|
|
|
import { useFormikContext } from 'formik';
|
|
|
|
|
import { getTrad } from '../../utils';
|
|
|
|
|
|
|
|
|
|
const BaseForm = ({ options, defaultOption }) => {
|
|
|
|
|
const { formatMessage } = useIntl();
|
|
|
|
|
const { values, handleChange, setFieldValue } = useFormikContext();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Row>
|
|
|
|
|
<Col>
|
|
|
|
|
<span id="locale-code">
|
|
|
|
|
<Label htmlFor="">
|
|
|
|
|
{formatMessage({
|
|
|
|
|
id: getTrad('Settings.locales.modal.locales.label'),
|
|
|
|
|
})}
|
|
|
|
|
</Label>
|
|
|
|
|
</span>
|
|
|
|
|
|
2021-02-25 15:29:15 +01:00
|
|
|
<BaselineAlignment top size="5px" />
|
|
|
|
|
|
2021-02-15 14:55:08 +01:00
|
|
|
<Select
|
|
|
|
|
aria-labelledby="locale-code"
|
|
|
|
|
options={options}
|
|
|
|
|
defaultValue={defaultOption}
|
|
|
|
|
onChange={selection => {
|
|
|
|
|
setFieldValue('displayName', selection.value);
|
|
|
|
|
setFieldValue('code', selection.label);
|
|
|
|
|
}}
|
2021-02-25 15:29:15 +01:00
|
|
|
styles={{
|
|
|
|
|
control: base => ({ ...base, height: '34px', minHeight: 'unset' }),
|
|
|
|
|
}}
|
2021-02-15 14:55:08 +01:00
|
|
|
/>
|
|
|
|
|
</Col>
|
|
|
|
|
|
|
|
|
|
<Col>
|
2021-02-25 15:29:15 +01:00
|
|
|
<BaselineAlignment top size="2px" />
|
|
|
|
|
|
2021-02-15 14:55:08 +01:00
|
|
|
<Inputs
|
|
|
|
|
label={formatMessage({
|
|
|
|
|
id: getTrad('Settings.locales.modal.locales.displayName'),
|
|
|
|
|
})}
|
|
|
|
|
name="displayName"
|
|
|
|
|
description={formatMessage({
|
|
|
|
|
id: getTrad('Settings.locales.modal.locales.displayName.description'),
|
|
|
|
|
})}
|
|
|
|
|
type="text"
|
|
|
|
|
value={values.displayName}
|
|
|
|
|
onChange={handleChange}
|
|
|
|
|
validations={{
|
|
|
|
|
max: 50,
|
|
|
|
|
}}
|
|
|
|
|
translatedErrors={{
|
|
|
|
|
max: formatMessage({
|
|
|
|
|
id: getTrad('Settings.locales.modal.locales.displayName.error'),
|
|
|
|
|
}),
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BaseForm.defaultProps = {
|
|
|
|
|
defaultOption: undefined,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BaseForm.propTypes = {
|
|
|
|
|
options: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.exact({ value: PropTypes.string.isRequired, label: PropTypes.string.isRequired })
|
|
|
|
|
).isRequired,
|
|
|
|
|
defaultOption: PropTypes.exact({
|
|
|
|
|
value: PropTypes.string.isRequired,
|
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default BaseForm;
|