Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Extract CartItem from the starter to @faststore/ui #198

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@faststore/api": "^1.11.7",
"@faststore/graphql-utils": "^1.10.34",
"@faststore/sdk": "^1.10.34",
"@faststore/ui": "^1.11.8",
"@faststore/ui": "^1.11.20",
"@vtex/client-cms": "^0.2.10",
"gatsby": "^4.16.0",
"gatsby-plugin-gatsby-cloud": "^4.16.0",
Expand Down
38 changes: 23 additions & 15 deletions src/components/cart/CartItem/CartItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { sendAnalyticsEvent } from '@faststore/sdk'
import { Card, CardActions, CardContent, CardImage } from '@faststore/ui'
import {
CartItem as UICartItem,
CartItemActions as UICartItemActions,
CartItemSummary as UICartItemSummary,
CartItemTitle as UICartItemTitle,
CartItemPrices as UICartItemPrices,
CartItemContent as UICartItemContent,
CartItemImage as UICartItemImage,
} from '@faststore/ui'
import { useCallback, useMemo } from 'react'
import type {
AddToCartEvent,
Expand Down Expand Up @@ -81,27 +89,27 @@ function CartItem({ item, gift = false }: Props) {
)

return (
<Card
<UICartItem
className={styles.fsCartItem}
data-testid="cart-item"
data-sku={item.itemOffered.sku}
data-seller={item.seller.identifier}
>
<CardContent data-fs-cart-item-content>
<CardImage>
<UICartItemContent>
<UICartItemImage>
<Image
src={item.itemOffered.image[0].url}
alt={item.itemOffered.image[0].alternateName}
width={72}
height={72}
/>
</CardImage>
<div data-fs-cart-item-summary>
<p className="text__body" data-fs-cart-item-title>
</UICartItemImage>
<UICartItemSummary>
<UICartItemTitle className="text__body">
{item.itemOffered.isVariantOf.name}
</p>
</UICartItemTitle>
{!gift && (
<span data-fs-cart-item-prices>
<UICartItemPrices>
<Price
value={item.listPrice}
formatter={useFormattedPrice}
Expand All @@ -120,13 +128,13 @@ function CartItem({ item, gift = false }: Props) {
classes="text__title-subsection"
SRText="Price:"
/>
</span>
</UICartItemPrices>
)}
</div>
</CardContent>
</UICartItemSummary>
</UICartItemContent>

{!gift && (
<CardActions data-fs-cart-item-actions>
<UICartItemActions>
<Button
variant="tertiary"
icon={<Icon name="XCircle" width={18} height={18} />}
Expand All @@ -140,9 +148,9 @@ function CartItem({ item, gift = false }: Props) {
initial={item.quantity}
onChange={onQuantityChange}
/>
</CardActions>
</UICartItemActions>
)}
</Card>
</UICartItem>
)
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1978,10 +1978,10 @@
dependencies:
idb-keyval "^5.1.3"

"@faststore/ui@^1.11.8":
version "1.11.8"
resolved "https://registry.yarnpkg.com/@faststore/ui/-/ui-1.11.8.tgz#b9ed0d59831750239a5fdf20434b6c82ec606f28"
integrity sha512-n/rr9wgKsfom+O0I16lF6raMtV2Engt0nd9IVekzeX50fIeiIu5VyobZR7kryUYcr+mtXPo8/8FpxQvCkuntvg==
"@faststore/ui@^1.11.20":
version "1.11.20"
resolved "https://registry.yarnpkg.com/@faststore/ui/-/ui-1.11.20.tgz#f2aad301a65713b48230dc3b7a3814ad94c8ba71"
integrity sha512-OsRWZ0zV24vBFKerm4vYJ59II2NhPCb8GYBXOdA4S5nObUwCoX4rQTDtvMKXJWXubPzHIv1Vsc7xYMDJVqrpTQ==
dependencies:
"@reach/popover" "^0.16.0"
"@storybook/addon-a11y" "^6.4.4"
Expand Down