-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from vtex-apps/feat/assembly
Feat/assembly
- Loading branch information
Showing
11 changed files
with
120 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "vtex-react", | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"jest": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 29 additions & 27 deletions
56
react/components/ProductSummaryAttachmentList/AddedAttachmentsList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,58 @@ | ||
import React, { Fragment } from 'react' | ||
import { arrayOf, number } from 'prop-types' | ||
import { intlShape, injectIntl } from 'react-intl' | ||
import { arrayOf, bool } from 'prop-types' | ||
import { FormattedMessage } from 'react-intl' | ||
|
||
import AttachmentItem from './AttachmentItem' | ||
|
||
import { CHOICE_TYPES } from '../../utils/attachmentHelper' | ||
|
||
import { addedOptionShape } from '../../utils/propTypes' | ||
|
||
const formatAttachmentName = (option, intl) => { | ||
const extraParams = { | ||
sign: '+', | ||
name: option.item.name, | ||
quantity: option.extraQuantity || option.normalizedQuantity, | ||
} | ||
return intl.formatMessage( | ||
{ id: 'store/productSummary.attachmentName' }, | ||
extraParams | ||
) | ||
} | ||
const formatAttachmentName = option => ( | ||
<FormattedMessage | ||
id="store/productSummary.attachmentName" | ||
values={{ | ||
sign: '+', | ||
name: option.item.name, | ||
quantity: option.normalizedQuantity, | ||
}} | ||
/> | ||
) | ||
|
||
const AddedAttachmentsList = ({ addedOptions, parentPrice, intl }) => { | ||
const AddedAttachmentsList = ({ addedOptions, showItemPrice }) => { | ||
if (addedOptions.length === 0) { | ||
return null | ||
} | ||
return ( | ||
<Fragment> | ||
<AttachmentItem | ||
productText={intl.formatMessage({ id: 'store/productSummary.unit' })} | ||
price={parentPrice} | ||
/> | ||
{addedOptions.map(option => { | ||
const isSingle = option.choiceType === CHOICE_TYPES.SINGLE | ||
const productText = isSingle | ||
? option.item.name | ||
: formatAttachmentName(option, intl) | ||
const isMultiple = option.choiceType === CHOICE_TYPES.MULTIPLE | ||
const productText = isMultiple | ||
? formatAttachmentName(option) | ||
: option.item.name | ||
return ( | ||
<AttachmentItem | ||
productText={productText} | ||
price={option.item.sellingPrice * option.normalizedQuantity} | ||
key={productText} | ||
price={ | ||
option.item.sellingPriceWithAssemblies * option.normalizedQuantity | ||
} | ||
key={`${option.item.name}-${option.choiceType}`} | ||
assemblyOptions={option.item.assemblyOptions} | ||
showItemPrice={showItemPrice} | ||
/> | ||
) | ||
})} | ||
</Fragment> | ||
) | ||
} | ||
|
||
AddedAttachmentsList.defaultProps = { | ||
showItemPrice: true, | ||
} | ||
|
||
AddedAttachmentsList.propTypes = { | ||
intl: intlShape, | ||
addedOptions: arrayOf(addedOptionShape).isRequired, | ||
parentPrice: number.isRequired, | ||
showItemPrice: bool, | ||
} | ||
|
||
export default injectIntl(AddedAttachmentsList) | ||
export default AddedAttachmentsList |
20 changes: 20 additions & 0 deletions
20
react/components/ProductSummaryAttachmentList/AttachmentChildren.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import AddedAttachmentsList from './AddedAttachmentsList' | ||
import RemovedAttachmentsList from './RemovedAttachmentsList' | ||
|
||
import styles from '../../productSummary.css' | ||
|
||
const AttachmentChildren = ({ addedOptions, removedOptions }) => { | ||
if (addedOptions.length === 0 && removedOptions.length === 0) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className={`${styles.attachmentChildrenContainer} ml3`}> | ||
<AddedAttachmentsList addedOptions={addedOptions} showItemPrice={false} /> | ||
<RemovedAttachmentsList removedOptions={removedOptions} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default AttachmentChildren |
58 changes: 41 additions & 17 deletions
58
react/components/ProductSummaryAttachmentList/AttachmentItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,57 @@ | ||
import React, { memo } from 'react' | ||
import { string, number } from 'prop-types' | ||
import { string, number, object, bool } from 'prop-types' | ||
import ProductPrice from 'vtex.store-components/ProductPrice' | ||
import { reject } from 'ramda' | ||
|
||
import styles from '../../productSummary.css' | ||
import AttachmentChildren from './AttachmentChildren' | ||
|
||
const itemShouldHide = ({ item, extraQuantity }) => | ||
extraQuantity === 0 && item.sellingPriceWithAssemblies === 0 | ||
|
||
const AttachmentItem = ({ | ||
productText, | ||
price, | ||
assemblyOptions, | ||
showItemPrice, | ||
}) => { | ||
const childrenAdded = (assemblyOptions && assemblyOptions.added) || [] | ||
const childrenRemoved = (assemblyOptions && assemblyOptions.removed) || [] | ||
const filteredChildrenAdded = reject(itemShouldHide, childrenAdded) | ||
const parentColor = | ||
filteredChildrenAdded.length > 0 || childrenRemoved.length > 0 | ||
? 'c-on-base' | ||
: 'c-muted-2' | ||
|
||
const AttachmentItem = ({ productText, price }) => { | ||
return ( | ||
<div | ||
className={`${styles.attachmentItemContainer} flex items-center justify-between pv1`} | ||
> | ||
<span className="t-small c-muted-2 tl pr3">{productText}</span> | ||
{price != null && ( | ||
<ProductPrice | ||
sellingPrice={price} | ||
sellingPriceContainerClass="c-on-base" | ||
sellingPriceLabelClass="dib" | ||
sellingPriceClass="dib t-small c-muted-2" | ||
showListPrice={false} | ||
showLabels={false} | ||
showInstallments={false} | ||
/> | ||
)} | ||
<div className={`${styles.attachmentItemContainer} flex flex-column pv1`}> | ||
<div className={`flex items-center justify-between`}> | ||
<span className={`t-small ${parentColor} tl pr3`}>{productText}</span> | ||
{price != null && showItemPrice && price > 0 && ( | ||
<ProductPrice | ||
sellingPrice={price} | ||
sellingPriceContainerClass="c-on-base" | ||
sellingPriceLabelClass="dib" | ||
sellingPriceClass="dib t-small c-muted-2" | ||
showListPrice={false} | ||
showLabels={false} | ||
showInstallments={false} | ||
/> | ||
)} | ||
</div> | ||
<AttachmentChildren | ||
addedOptions={filteredChildrenAdded} | ||
removedOptions={childrenRemoved} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
AttachmentItem.propTypes = { | ||
productText: string.isRequired, | ||
price: number, | ||
assemblyOptions: object, | ||
showItemPrice: bool, | ||
} | ||
|
||
export default memo(AttachmentItem) |
14 changes: 5 additions & 9 deletions
14
react/components/ProductSummaryAttachmentList/AttachmentList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,6 @@ | |
|
||
.imagePlaceholder { | ||
} | ||
|
||
.attachmentChildrenContainer { | ||
} |