From 8147e29ca764c6c84682145bf9970531c65dbbe3 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 20 Dec 2017 18:40:08 +0200 Subject: [PATCH] FieldCustomAttributeSelect --- .../FieldCustomAttributeSelect.css | 4 ++ .../FieldCustomAttributeSelect.js | 68 +++++++++++++++++++ src/components/index.js | 3 + src/translations/en.json | 7 ++ 4 files changed, 82 insertions(+) create mode 100644 src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.css create mode 100644 src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.js diff --git a/src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.css b/src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.css new file mode 100644 index 00000000..93adba15 --- /dev/null +++ b/src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.css @@ -0,0 +1,4 @@ +@import '../../marketplace.css'; + +.root { +} diff --git a/src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.js b/src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.js new file mode 100644 index 00000000..bb15a85c --- /dev/null +++ b/src/components/FieldCustomAttributeSelect/FieldCustomAttributeSelect.js @@ -0,0 +1,68 @@ +import React from 'react'; +import { string } from 'prop-types'; +import { intlShape, injectIntl } from 'react-intl'; +import classNames from 'classnames'; +import config from '../../config'; +import { required } from '../../util/validators'; +import { SelectField } from '../../components'; + +import css from './FieldCustomAttributeSelect.css'; + +const FieldCustomAttributeSelect = props => { + const { className, rootClassName, id, customAttribute, intl } = props; + + // Does custom attribute 'customAttribute' exists in current marketplace configuration + const ca = config.customAttributes && config.customAttributes[customAttribute]; + const isSingleChoice = ca && ca.select === 'single' && ca.type === 'string'; + + // If custom attribute config for given 'customAttribute' doesn't exist, don't print SelectField + if (!isSingleChoice) { + return null; + } + + const caLabel = intl.formatMessage({ id: `FieldCustomAttributeSelect.${customAttribute}.label` }); + const caPlaceholder = intl.formatMessage({ + id: `FieldCustomAttributeSelect.${customAttribute}.placeholder`, + }); + const caRequired = required( + intl.formatMessage({ + id: `FieldCustomAttributeSelect.${customAttribute}.required`, + }) + ); + + const classes = classNames(rootClassName || css.root, className); + + return ( + + + {ca.values.map(c => ( + + ))} + + ); +}; + +FieldCustomAttributeSelect.defaultProps = { + className: null, + rootClassName: null, +}; + +FieldCustomAttributeSelect.propTypes = { + className: string, + rootClassName: string, + id: string.isRequired, + customAttribute: string.isRequired, + + // From react-intl + intl: intlShape.isRequired, +}; + +export default injectIntl(FieldCustomAttributeSelect); diff --git a/src/components/index.js b/src/components/index.js index b98aa345..a8c6054b 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -27,6 +27,9 @@ export { default as EditListingWizard } from './EditListingWizard/EditListingWiz export { default as ExpandingTextarea } from './ExpandingTextarea/ExpandingTextarea'; export { default as ExternalLink } from './ExternalLink/ExternalLink'; export { default as FilterPanel } from './FilterPanel/FilterPanel'; +export { + default as FieldCustomAttributeSelect, +} from './FieldCustomAttributeSelect/FieldCustomAttributeSelect'; export { default as FieldReviewRating } from './FieldReviewRating/FieldReviewRating'; export { default as Footer } from './Footer/Footer'; export { default as Form } from './Form/Form'; diff --git a/src/translations/en.json b/src/translations/en.json index 03b4aa72..1e340a33 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -184,6 +184,13 @@ "EnquiryForm.messageRequired": "A message is required", "EnquiryForm.sendEnquiryError": "Whoops, something went wrong. Please try again.", "EnquiryForm.submitButtonText": "Send enquiry", + "FieldCustomAttributeSelect.category.label": "Sauna type", + "FieldCustomAttributeSelect.category.option.mountain": "Mountain", + "FieldCustomAttributeSelect.category.option.other": "Other", + "FieldCustomAttributeSelect.category.option.road": "Road", + "FieldCustomAttributeSelect.category.option.track": "Track", + "FieldCustomAttributeSelect.category.placeholder": "Choose the type of your sauna…", + "FieldCustomAttributeSelect.category.required": "You need to select a category for your sauna.", "FieldReviewRating.star1": "Bad experience - 1 star", "FieldReviewRating.star2": "Not so nice - 2 stars", "FieldReviewRating.star3": "OK - 3 stars",