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

Feat/voucherify2 #2

Draft
wants to merge 89 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
dbe6958
define general types for marketing promotions
Nov 23, 2023
51c7269
exted commerce service definition by voucers feature
Nov 23, 2023
f5e7733
fake promotions feature in commerce generic
Nov 23, 2023
f626180
Cart drawer summary - added price before discount and discount
weronika-kurczyna Nov 24, 2023
975dfdf
Create VoucherForm
weronika-kurczyna Nov 24, 2023
de02273
voucherify package - PoC installation/uninstallation script
Nov 24, 2023
62cf751
Set error messages
weronika-kurczyna Nov 24, 2023
9782455
Add Promotions
weronika-kurczyna Nov 24, 2023
88803d9
Remove duplicated button (mobile version of cart)
weronika-kurczyna Nov 24, 2023
23f1abc
Add discounts to summary and bag-summary-mobile
weronika-kurczyna Nov 24, 2023
12a0993
Add discount info to Order summary - checkout
weronika-kurczyna Nov 24, 2023
e1a7d10
Update order summary labels
weronika-kurczyna Nov 24, 2023
7d3df7f
Merge branch 'feat/voucherify2' into feat/voucherify2-frontend
weronika-kurczyna Nov 24, 2023
78e75ea
Fix imports
weronika-kurczyna Nov 24, 2023
3d6127c
Update voucher-form.tsx
weronika-kurczyna Nov 24, 2023
6e9789d
Fix translations in cart-drawer-summary
weronika-kurczyna Nov 27, 2023
dc5329e
Change the order of components in cart drawer
weronika-kurczyna Nov 27, 2023
b8366bf
Add dividers to cart summary
weronika-kurczyna Nov 27, 2023
ebdb19e
Change totalPrice to priceBeforeDiscount
weronika-kurczyna Nov 27, 2023
14c53b2
Fix: Change totalPrice to priceBeforeDiscount
weronika-kurczyna Nov 27, 2023
2e9c3bd
Add saveCart to add/delete voucher
weronika-kurczyna Nov 27, 2023
1dfe91e
Add saveCart to add/delete voucher
weronika-kurczyna Nov 27, 2023
3a3706c
Add case when voucher is already applied
weronika-kurczyna Nov 27, 2023
c65baf2
Merge branch 'feat/voucherify2' into feat/voucherify2-frontend
weronika-kurczyna Nov 27, 2023
4ace91d
Change the order of taxes and shipping in cart
weronika-kurczyna Nov 27, 2023
c95b7a7
Better UI
weronika-kurczyna Nov 27, 2023
02c74da
Make alert disappear
weronika-kurczyna Nov 27, 2023
f81d891
Add replacing for addVoucher and deleteVoucher
weronika-kurczyna Nov 27, 2023
c502076
Update install.ts
weronika-kurczyna Nov 27, 2023
c93b025
Update discount.ts
weronika-kurczyna Nov 27, 2023
63f0d00
Merge branch 'feat/voucherify2' into feat/voucherify2-frontend
weronika-kurczyna Nov 27, 2023
db522e8
Add Voucherify script
weronika-kurczyna Nov 27, 2023
48049ec
Add validation
weronika-kurczyna Nov 27, 2023
d5e1881
Add 'get-cart' to install.ts
weronika-kurczyna Nov 27, 2023
902399c
Update discount value
weronika-kurczyna Nov 27, 2023
91395dd
Update discount.ts
weronika-kurczyna Nov 27, 2023
5933f75
Update uninstall.ts
weronika-kurczyna Nov 27, 2023
189da94
Merge branch 'feat/voucherify2' into feat/voucherify2-frontend
weronika-kurczyna Nov 27, 2023
5edf756
Update discount.ts
weronika-kurczyna Nov 28, 2023
9c2531a
Refactor discount.ts
weronika-kurczyna Nov 28, 2023
bf15841
Add condition for already applied voucher
weronika-kurczyna Nov 28, 2023
aeb22f5
Change spacing in order summary
weronika-kurczyna Nov 28, 2023
c783816
Update discount.ts
weronika-kurczyna Nov 28, 2023
14999bf
Update discount.ts
weronika-kurczyna Nov 28, 2023
1af50b0
Refactor cart-with-discounts
weronika-kurczyna Nov 28, 2023
9f4ca5f
Update discount.ts
weronika-kurczyna Nov 28, 2023
7249fc6
Shorten install and uninstall
weronika-kurczyna Nov 28, 2023
1af01b6
Use saveCart in main methods
weronika-kurczyna Nov 28, 2023
e643b15
Docs: first version
weronika-kurczyna Nov 28, 2023
5fba034
Add missing translations to cart-summary.test
weronika-kurczyna Nov 28, 2023
45486d7
Update cart-summary.test.tsx
weronika-kurczyna Nov 28, 2023
76e7276
Change IconButton to Button ('Apply')
weronika-kurczyna Nov 29, 2023
f862b17
Move install scripts to /scripts
weronika-kurczyna Nov 29, 2023
d4810ce
Remove saveCart from discount
weronika-kurczyna Nov 29, 2023
b1b9657
Add redeemed discounts to cart (and redeem in voucherify)
weronika-kurczyna Nov 29, 2023
124642f
Update order and redeem only if payment is successful
weronika-kurczyna Nov 29, 2023
f235ddd
Redemption when the payment is successful
weronika-kurczyna Nov 29, 2023
4c63cda
Move voucherify-config
weronika-kurczyna Nov 30, 2023
14138f9
Update cart-summary test
weronika-kurczyna Nov 30, 2023
f755833
Update voucher-form.tsx
weronika-kurczyna Nov 30, 2023
157ffec
Add discount specific files to docs
weronika-kurczyna Dec 1, 2023
946cc64
Do not pass the status and payment
weronika-kurczyna Dec 1, 2023
0dc35f7
Merge branch 'feat/voucherify2' into feat/voucherify2-redemption
weronika-kurczyna Dec 1, 2023
4dacd89
Update voucherify.md
weronika-kurczyna Dec 1, 2023
5f76fb6
Merge branch 'feat/voucherify2' into feat/voucherify2-redemption
weronika-kurczyna Dec 1, 2023
6f00bbd
Update documentation and voucherifySDK version
weronika-kurczyna Dec 1, 2023
ef08c4f
Merge branch 'feat/voucherify2' into feat/voucherify2-redemption
weronika-kurczyna Dec 4, 2023
13c6cbf
Add mock for InputField
weronika-kurczyna Dec 4, 2023
f11c7a7
changes proposal - WIP
Dec 4, 2023
9ba165b
refactoring suggestions WIP
Dec 4, 2023
5c71133
Move toCent and centToString to one place
weronika-kurczyna Dec 4, 2023
005d537
Move files from 'data' to 'src'
weronika-kurczyna Dec 4, 2023
f5eaf1b
Add voucherify to createOrder (script)
weronika-kurczyna Dec 4, 2023
22138c2
v% scripts
weronika-kurczyna Dec 4, 2023
c025d7a
Put file operations in operations.ts file
weronika-kurczyna Dec 5, 2023
1933fd3
fix typo
weronika-kurczyna Dec 5, 2023
2f41f0a
Merge branch 'feat/voucherify2' into feat/voucherify2-redemption
weronika-kurczyna Dec 5, 2023
6f0d42a
Export @composable/commerce-generic, change the name of script files
weronika-kurczyna Dec 6, 2023
d1cdc47
Update comment
weronika-kurczyna Dec 6, 2023
119d4c0
Update scripts
weronika-kurczyna Dec 6, 2023
6fe5f4a
Change name to 'code-updater'
weronika-kurczyna Dec 6, 2023
8f81bdd
Better error handling
weronika-kurczyna Dec 6, 2023
22c8647
use toCent in voucherify
weronika-kurczyna Dec 6, 2023
d25a1d2
update toCent
weronika-kurczyna Dec 6, 2023
453c217
Update cart-summary.tsx
weronika-kurczyna Dec 6, 2023
f3086bd
Fix frontend bugs
weronika-kurczyna Dec 6, 2023
e940f90
Add tax to cartItem type
weronika-kurczyna Dec 6, 2023
2f7ed81
Update docs
weronika-kurczyna Dec 6, 2023
0c9c5fd
Merge pull request #4 from voucherifyio/feat/voucherify2-redemption
weronika-kurczyna Dec 6, 2023
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
9 changes: 9 additions & 0 deletions composable-ui/src/__mocks__/@composable/ui.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { ImageBannerProps } from '@composable/ui'
import { FormControl, Input } from '@chakra-ui/react'

export const ImageBanner = (props: ImageBannerProps) => {
return <div>{props.image?.src}</div>
}

export const InputField = () => {
return (
<FormControl>
<Input />
</FormControl>
)
}
1 change: 1 addition & 0 deletions composable-ui/src/components/cart/__data__/cart-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const cartData: CartData = {
name: 'Venture Daypack',
brand: 'Riley',
price: 129,
tax: 0.07,
image: {
url: '/img/products/_0000s_0001_backpack-rugged-black-front.jpg',
alt: '',
Expand Down
38 changes: 35 additions & 3 deletions composable-ui/src/components/cart/__tests__/cart-summary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,35 @@ jest.mock('hooks', () => ({
subtotalPrice: 70,
shipping: 10,
taxes: 15,
totalPrice: 95,
priceBeforeDiscount: 95,
totalDiscountAmount: 10,
totalPrice: 85,
},
vouchersApplied: [
{
code: 'CODE',
label: 'VOUCHER',
discount: '10',
},
],
promotionsApplied: [],
},
}
},
}))

const translations = {
'action.proceedToCheckout': 'Proceed to Checkout',
'cart.summary.orderTotal': 'Order Total',
'cart.summary.orderTotal': 'Grand Total',
'cart.summary.shipping': 'Shipping Label',
'cart.summary.subtotal': 'Subtotal',
'cart.summary.taxes': 'Taxes Label',
'cart.summary.title': 'Cart Title',
'cart.summary.label.voucher': 'Voucher code',
'cart.summary.priceBeforeDiscount': 'Order Total',
'cart.summary.totalDiscountAmount': 'All discounts',
'action.addVoucher': 'Add Voucher',
'cart.summary.vouchers': 'Vouchers',
}

describe('CartSummary', () => {
Expand All @@ -54,15 +69,27 @@ describe('CartSummary', () => {
// taxes
const taxesPrice = screen.getByText('$15.00')
const taxesLabel = screen.getByText(translations['cart.summary.taxes'])
// priceBeforeDiscount
const priceBeforeDiscount = screen.getByText('$95.00')
const priceBeforeDiscountLabel = screen.getByText(
translations['cart.summary.priceBeforeDiscount']
)
// totalDiscountAmount
const totalDiscountAmount = screen.getByText('$10.00')
const totalDiscountAmountLabel = screen.getByText(
translations['cart.summary.totalDiscountAmount']
)
// totalPrice
const totalPrice = screen.getByText('$95.00')
const totalPrice = screen.getByText('$85.00')
const totalPriceLabel = screen.getByText(
translations['cart.summary.orderTotal']
)
// checkout button
const proceedToCheckout = screen.getByText(
translations['action.proceedToCheckout']
)
// vouchers
const vouchers = screen.getByText(translations['cart.summary.vouchers'])

expect(title).toBeInTheDocument()
expect(subtotalPrice).toBeInTheDocument()
Expand All @@ -71,9 +98,14 @@ describe('CartSummary', () => {
expect(shippingLabel).toBeInTheDocument()
expect(taxesPrice).toBeInTheDocument()
expect(taxesLabel).toBeInTheDocument()
expect(priceBeforeDiscount).toBeInTheDocument()
expect(priceBeforeDiscountLabel).toBeInTheDocument()
expect(totalDiscountAmount).toBeInTheDocument()
expect(totalDiscountAmountLabel).toBeInTheDocument()
expect(totalPrice).toBeInTheDocument()
expect(totalPriceLabel).toBeInTheDocument()
expect(proceedToCheckout).toBeInTheDocument()
expect(vouchers).toBeInTheDocument()

fireEvent.click(proceedToCheckout)
expect(pushMock).toHaveBeenCalledWith('/checkout')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const CartDrawerFooter = () => {
color={'text-muted'}
textStyle={{ base: 'Mobile/Eyebrow', md: 'Desktop/Body-XS' }}
>
{intl.formatMessage({ id: 'cart.summary.estimatedTotal' })}
{intl.formatMessage({ id: 'cart.summary.orderTotal' })}
</Text>
</Box>
<Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Divider, Box, Flex, Text } from '@chakra-ui/react'
import { Divider, Box, Flex, Text, Stack } from '@chakra-ui/react'
import { useIntl } from 'react-intl'
import { useCart } from 'hooks'
import { CartDrawerSummaryItem } from './cart-drawer-summary-item'
import { Price } from '../../price'
import { CartPromotions } from '../cart-promotions'
import { CartVouchers } from '../cart-vouchers'

export const CartDrawerSummary = () => {
const { cart } = useCart()
const intl = useIntl()

const promotions = cart.promotionsApplied || []

return (
<Box>
<Divider m={'10px 0'} />

{cart.summary?.subtotalPrice && (
<CartDrawerSummaryItem
label={intl.formatMessage({ id: 'cart.summary.subtotal' })}
Expand Down Expand Up @@ -46,15 +49,57 @@ export const CartDrawerSummary = () => {
)}
<Divider m={'10px 0'} />

<Stack spacing="8">
{promotions.length > 0 && (
<Stack bg="shading.100" p={'0.7rem 1.5rem'} mb={'-5'}>
<CartPromotions promotions={promotions} />
</Stack>
)}
<Stack bg="shading.100" p={'0.7rem 1.5rem'} mb={'0'}>
<CartVouchers />
</Stack>
</Stack>
<Divider m={'10px 0'} />
{cart.summary?.priceBeforeDiscount && (
<CartDrawerSummaryItem
label={intl.formatMessage({ id: 'cart.summary.priceBeforeDiscount' })}
>
<Box>
<Price
rootProps={{ textStyle: 'Body-XS' }}
price={cart.summary.priceBeforeDiscount}
/>
</Box>
</CartDrawerSummaryItem>
)}

{cart.summary?.totalDiscountAmount && (
<>
<CartDrawerSummaryItem
label={intl.formatMessage({
id: 'cart.summary.totalDiscountAmount',
})}
>
<Box>
<Price
rootProps={{
textStyle: 'Body-XS',
color: 'green',
}}
price={`-${cart.summary.totalDiscountAmount}`}
/>
</Box>
</CartDrawerSummaryItem>
</>
)}
{cart.summary?.totalPrice && (
<>
<Divider m={'10px 0'} />
<Flex
justify="space-between"
textStyle={{ base: 'Mobile/S', md: 'Desktop/S' }}
>
<Text>
{intl.formatMessage({ id: 'cart.summary.estimatedTotal' })}
</Text>
<Text>{intl.formatMessage({ id: 'cart.summary.orderTotal' })}</Text>
<Box>
<Price
rootProps={{ textStyle: 'Desktop/S' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const CartDrawer = () => {
) : cart.isEmpty ? (
<CartDrawerEmptyState onClose={cartDrawer.onClose} />
) : (
<Stack spacing="8">
<Stack spacing="4">
<Stack
spacing="8"
divider={<Divider />}
Expand Down
48 changes: 48 additions & 0 deletions composable-ui/src/components/cart/cart-promotions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useIntl } from 'react-intl'
import { Promotion } from '@composable/types'
import { Box, Flex, Tag, TagLabel, TagLeftIcon } from '@chakra-ui/react'
import { MdShoppingCart } from 'react-icons/md'
import { Price } from 'components/price'
import { CartSummaryItem } from '.'

interface CartPromotionsProps {
promotions: Promotion[]
}

export const CartPromotions = ({ promotions }: CartPromotionsProps) => {
const intl = useIntl()
if (!promotions.length) {
return null
}

return (
<>
<CartSummaryItem
label={intl.formatMessage({
id: 'cart.summary.promotions',
})}
></CartSummaryItem>
{promotions.map((redeemable) => (
<Flex key={redeemable.id} justify="space-between">
<Tag
size="md"
paddingRight={2}
paddingLeft={2}
borderRadius="sm"
variant="outline"
colorScheme="whiteAlpha"
>
<TagLeftIcon boxSize="12px" as={MdShoppingCart} />
<TagLabel>{redeemable.label}</TagLabel>
</Tag>
<Box>
<Price
rootProps={{ textStyle: 'Body-S', color: 'green' }}
price={`-${redeemable.discountAmount}`}
/>
</Box>
</Flex>
))}
</>
)
}
45 changes: 40 additions & 5 deletions composable-ui/src/components/cart/cart-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
StackProps,
Text,
} from '@chakra-ui/react'
import { CartSummaryItem } from '.'
import { CartSummaryItem, CartPromotions, CartVouchers } from '.'

interface CartSummaryProps {
rootProps?: StackProps
Expand All @@ -28,6 +28,7 @@ export const CartSummary = ({
const { cart } = useCart()
const intl = useIntl()
const _cartData = cartData ?? cart
const promotions = _cartData.promotionsApplied || []

return (
<Stack spacing={{ base: '4', md: '6' }} width="full" {...rootProps}>
Expand All @@ -52,6 +53,18 @@ export const CartSummary = ({
/>
</CartSummaryItem>
)}

{_cartData.summary?.taxes && (
<CartSummaryItem
label={intl.formatMessage({ id: 'cart.summary.taxes' })}
>
<Price
rootProps={{ textStyle: 'Body-S' }}
price={_cartData.summary.taxes}
/>
</CartSummaryItem>
)}

{_cartData.summary?.shipping && (
<CartSummaryItem
label={intl.formatMessage({ id: 'cart.summary.shipping' })}
Expand All @@ -62,14 +75,36 @@ export const CartSummary = ({
/>
</CartSummaryItem>
)}

{_cartData.summary?.taxes && (
{promotions.length > 0 && (
<>
<Divider m={'2px 0'} />
<CartPromotions promotions={promotions} />
</>
)}
<Divider m={'2px 0'} />
<CartVouchers />
<Divider />
{_cartData.summary?.priceBeforeDiscount && (
<CartSummaryItem
label={intl.formatMessage({ id: 'cart.summary.taxes' })}
label={intl.formatMessage({
id: 'cart.summary.priceBeforeDiscount',
})}
>
<Price
rootProps={{ textStyle: 'Body-S' }}
price={_cartData.summary.taxes}
price={`${_cartData.summary.priceBeforeDiscount}`}
/>
</CartSummaryItem>
)}
{_cartData.summary?.totalDiscountAmount && (
<CartSummaryItem
label={intl.formatMessage({
id: 'cart.summary.totalDiscountAmount',
})}
>
<Price
rootProps={{ textStyle: 'Body-S', color: 'green' }}
price={`-${_cartData.summary.totalDiscountAmount}`}
/>
</CartSummaryItem>
)}
Expand Down
15 changes: 1 addition & 14 deletions composable-ui/src/components/cart/cart-total.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { useIntl } from 'react-intl'
import { useRouter } from 'next/router'
import { CartData, useCart } from 'hooks'
import { Price } from 'components/price'
import { Button, Flex, Text, FlexProps } from '@chakra-ui/react'
import { Flex, Text, FlexProps } from '@chakra-ui/react'

interface CartTotalProps {
rootProps?: FlexProps
cartData?: CartData
}

export const CartTotal = ({ cartData, rootProps }: CartTotalProps) => {
const router = useRouter()
const { cart } = useCart()
const intl = useIntl()
const _cartData = cartData ?? cart
Expand All @@ -26,17 +24,6 @@ export const CartTotal = ({ cartData, rootProps }: CartTotalProps) => {
<Text>{intl.formatMessage({ id: 'cart.summary.estimatedTotal' })}</Text>
<Price price={_cartData.summary?.totalPrice ?? ''} />
</Flex>
<Button
onClick={() => {
router.push('/checkout')
}}
w={{ base: 'full' }}
maxW={{ base: 'full' }}
variant={'solid'}
size={'lg'}
>
{intl.formatMessage({ id: 'action.proceedToCheckout' })}
</Button>
</>
)
}
Loading