forked from composable-com/composable-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Voucherify integration (deprecated) #1
Draft
marcin-slezak
wants to merge
14
commits into
feat/cart-persistance
Choose a base branch
from
commerce-wrapper
base: feat/cart-persistance
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0461d97
commerce wrapper - POC - WIP
c56b763
wrap commerce-generic and validate cart
5ca245b
PoC coupon on frontend side
be8b4e4
PoC handling coupon errors on frontend
0f512b6
refactoring
0d936a4
Merge branch 'feat/cart-persistance' into commerce-wrapper
310b634
reafactoring round one
1ac1568
refactoring round two
0b079e6
upload products to Voucherify
0726e9c
PoC Promotions
7fc7458
fix build error
d35191c
- display vouchers and promotions seperatelly
1f044eb
Voucherify documentation
dcdb4ec
add to documentation information about required partial redeem
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,66 @@ | ||
import { useIntl } from 'react-intl' | ||
import { CartItem, Redeemable } from '@composable/types' | ||
import { | ||
Box, | ||
Divider, | ||
Flex, | ||
HStack, | ||
Link, | ||
StackDivider, | ||
Tag, | ||
TagCloseButton, | ||
TagLabel, | ||
Wrap, | ||
WrapItem, | ||
Text, | ||
useBreakpointValue, | ||
TagLeftIcon, | ||
} from '@chakra-ui/react' | ||
import { Icon } from '@chakra-ui/icons' | ||
import { MdShoppingCart } from 'react-icons/md' | ||
import { Price } from 'components/price' | ||
import { QuantityPicker } from 'components/quantity-picker' | ||
import { CartItemData, CartSummaryItem } from '.' | ||
|
||
interface CartPromotionsProps { | ||
promotions: Redeemable[] | ||
} | ||
|
||
export const CartPromotions = ({ promotions }: CartPromotionsProps) => { | ||
const intl = useIntl() | ||
// const isMobile = useBreakpointValue({ base: true, md: false }) | ||
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.discount}`} | ||
/> | ||
</Box> | ||
</Flex> | ||
))} | ||
</> | ||
) | ||
} |
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,156 @@ | ||
import * as yup from 'yup' | ||
import { useIntl } from 'react-intl' | ||
import { useForm } from 'react-hook-form' | ||
import { | ||
Alert, | ||
AlertIcon, | ||
Box, | ||
Flex, | ||
TagLeftIcon, | ||
Wrap, | ||
WrapItem, | ||
} from '@chakra-ui/react' | ||
import { yupResolver } from '@hookform/resolvers/yup' | ||
import { useState } from 'react' | ||
import { IconButton, Text } from '@chakra-ui/react' | ||
import { ArrowForwardIcon } from '@chakra-ui/icons' | ||
import { InputField } from '@composable/ui' | ||
import { Tag, TagLabel, TagCloseButton } from '@chakra-ui/react' | ||
import { useCart } from 'hooks' | ||
import { Price } from 'components/price' | ||
import { CartSummaryItem } from 'components/cart' | ||
import { Icon } from '@chakra-ui/react' | ||
import { MdDiscount } from 'react-icons/md' | ||
import { displayValue } from '@tanstack/react-query-devtools/build/lib/utils' | ||
|
||
export const CouponForm = () => { | ||
const intl = useIntl() | ||
const [errorMessage, setErrorMessage] = useState<false | string>(false) | ||
const { | ||
register, | ||
handleSubmit, | ||
setError, | ||
setValue, | ||
formState: { errors }, | ||
} = useForm<{ coupon: string }>({ | ||
resolver: yupResolver(couponFormSchema()), | ||
mode: 'all', | ||
}) | ||
const { cart, addCartCoupon, deleteCartCoupon } = useCart({ | ||
onCartCouponAddError: (msg) => { | ||
setErrorMessage(msg || 'Could not add coupon') | ||
}, | ||
}) | ||
|
||
const content = { | ||
input: { | ||
coupon: { | ||
label: intl.formatMessage({ id: 'cart.summary.label.coupon' }), | ||
placeholder: intl.formatMessage({ id: 'cart.summary.label.coupon' }), | ||
}, | ||
}, | ||
button: { | ||
login: intl.formatMessage({ id: 'action.addCoupon' }), | ||
}, | ||
} | ||
|
||
const vouchers = | ||
cart.redeemables?.filter((redeemable) => redeemable.object === 'voucher') || | ||
[] | ||
|
||
return ( | ||
<> | ||
<CartSummaryItem | ||
label={intl.formatMessage({ | ||
id: 'cart.summary.couponCodes', | ||
})} | ||
></CartSummaryItem> | ||
<form | ||
role={'form'} | ||
onSubmit={handleSubmit(async (data) => { | ||
setErrorMessage(false) | ||
|
||
// setError('coupon', {message: 'Could not add coupon' }) | ||
await addCartCoupon.mutate({ | ||
cartId: cart.id || '', | ||
coupon: data.coupon, | ||
}) | ||
setValue('coupon', '') | ||
})} | ||
> | ||
<Box | ||
display={'flex'} | ||
flexDirection={'row'} | ||
alignItems={'flex-start'} | ||
justifyContent={'center'} | ||
height={'60px'} | ||
gap={3} | ||
> | ||
<InputField | ||
inputProps={{ | ||
size: 'sm', | ||
fontSize: 'sm', | ||
placeholder: content.input.coupon.placeholder, | ||
...register('coupon'), | ||
}} | ||
error={errors.coupon} | ||
label={''} | ||
/> | ||
<IconButton | ||
mt={2} | ||
aria-label="Search database" | ||
icon={<ArrowForwardIcon />} | ||
type="submit" | ||
size="sm" | ||
variant={'outline'} | ||
/> | ||
</Box> | ||
{errorMessage && ( | ||
<Alert mt={2} status="warning" borderRadius={'6px'}> | ||
<AlertIcon alignSelf={'flex-start'} /> | ||
{errorMessage} | ||
</Alert> | ||
)} | ||
</form> | ||
{vouchers.map((redeemable) => ( | ||
<Flex | ||
key={redeemable.id} | ||
justify="space-between" | ||
textStyle={{ base: 'Mobile/S', md: 'Desktop/S' }} | ||
> | ||
<Tag | ||
size="md" | ||
paddingRight={2} | ||
paddingLeft={2} | ||
borderRadius="sm" | ||
variant="outline" | ||
colorScheme="whiteAlpha" | ||
> | ||
<TagLeftIcon boxSize="12px" as={MdDiscount} /> | ||
<TagLabel>{redeemable.label}</TagLabel> | ||
<TagCloseButton | ||
onClick={() => | ||
deleteCartCoupon.mutate({ | ||
cartId: cart.id || '', | ||
coupon: redeemable.id, | ||
}) | ||
} | ||
/> | ||
</Tag> | ||
<Box> | ||
<Price | ||
rootProps={{ textStyle: 'Body-S', color: 'green' }} | ||
price={`-${redeemable.discount}`} | ||
/> | ||
</Box> | ||
</Flex> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
const couponFormSchema = () => { | ||
return yup.object().shape({ | ||
coupon: yup.string().required(), | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this
voucher
const can be deleted from this file