-
Notifications
You must be signed in to change notification settings - Fork 41
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 #84 from ACCT-global/feature/code-reference-minicart
Feature/code reference minicart
- Loading branch information
Showing
5 changed files
with
80 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { FunctionComponent, useMemo } from 'react' | ||
import { Loading } from 'vtex.render-runtime' | ||
import { useCssHandles } from 'vtex.css-handles' | ||
|
||
import { useItemContext } from './ItemContext' | ||
import { opaque } from './utils/opaque' | ||
import { IdentifierType } from './constants/Identifiers' | ||
|
||
const CSS_HANDLES = [ | ||
'productIdentifier', | ||
'productIdentifierValue', | ||
'productIdentifierLabelValue', | ||
] as const | ||
|
||
interface Props { | ||
identifierLabel?: string | ||
identifierOption?: string | ||
} | ||
|
||
const ProductReference: FunctionComponent<Props> = props => { | ||
const { identifierOption, identifierLabel } = props | ||
const { item, loading } = useItemContext() | ||
const handles = useCssHandles(CSS_HANDLES) | ||
|
||
const identifierValue = useMemo(() => { | ||
if (identifierOption === IdentifierType.PRODUCT_REFERENCE_ID) | ||
return item.productRefId | ||
if (identifierOption === IdentifierType.PRODUCT_SKU_REFERENCE_ID) | ||
return item.refId | ||
if (identifierOption === IdentifierType.PRODUCT_SKU_ITEM_ID) return item.id | ||
if (identifierOption === IdentifierType.PRODUCT_ID) return item.productId | ||
|
||
return item.productRefId | ||
}, [item.productRefId, identifierOption, item.id, item.productId, item.refId]) | ||
|
||
if (loading) return <Loading /> | ||
if (!identifierValue) return null | ||
|
||
return ( | ||
<div | ||
className={`c-on-base t-title lh-copy fw6 fw5-m ${ | ||
handles.productIdentifier | ||
} ${opaque(item.availability)}`} | ||
> | ||
{identifierLabel && ( | ||
<span className={`${handles.productIdentifierLabelValue}`}> | ||
{identifierLabel} | ||
</span> | ||
)} | ||
<span className={`${handles.productIdentifierValue}`}> | ||
{identifierValue} | ||
</span> | ||
</div> | ||
) | ||
} | ||
|
||
export default ProductReference |
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,6 @@ | ||
export const enum IdentifierType { | ||
PRODUCT_ID = 'ProductId', | ||
PRODUCT_SKU_ITEM_ID = 'ProductSkuItemId', | ||
PRODUCT_REFERENCE_ID = 'ProductReferenceId', | ||
PRODUCT_SKU_REFERENCE_ID = 'ProductSkuReferenceId', | ||
} |
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