-
Notifications
You must be signed in to change notification settings - Fork 197
@W-19168138 add a new modal to be used for bonus product selection modal #2988
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
Merged
sf-shikhar-prasoon
merged 12 commits into
feature/manual-bonus-products-v4
from
t/cc-sharks/W-19168138/add-new-modal/main
Aug 15, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8109de6
add a new modal
sf-shikhar-prasoon b2607ac
lint fix
sf-shikhar-prasoon a625b64
update tests
sf-shikhar-prasoon 881997f
Merge branch 'feature/manual-bonus-products-v4' into t/cc-sharks/W-19…
sf-shikhar-prasoon 54f9f98
Merge branch 'feature/manual-bonus-products-v4' into t/cc-sharks/W-19…
sf-shikhar-prasoon c1b7f13
renamed to BonusProductSelectionModal
sf-shikhar-prasoon 10958a8
extract out button
sf-shikhar-prasoon 606f912
color and padding fix
sf-shikhar-prasoon 90b1c1a
extract reusable custom hook
sf-shikhar-prasoon 407faa9
Merge branch 'feature/manual-bonus-products-v4' into t/cc-sharks/W-19…
sf-shikhar-prasoon 7c993a5
fix data flow
sf-shikhar-prasoon f7252c9
Merge branch 'feature/manual-bonus-products-v4' into t/cc-sharks/W-19…
sf-shikhar-prasoon 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 hidden or 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
61 changes: 61 additions & 0 deletions
61
packages/template-chakra-storefront/src/components/select-bonus-products-button/index.jsx
This file contains hidden or 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,61 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import {Button} from '@chakra-ui/react' | ||
import {useIntl} from 'react-intl' | ||
|
||
const SelectBonusProductsButton = ({ | ||
bonusDiscountLineItems, | ||
product, | ||
itemsAdded, | ||
onOpenBonusModal, | ||
onClose, | ||
...buttonProps | ||
}) => { | ||
const intl = useIntl() | ||
|
||
const handleClick = () => { | ||
if (onOpenBonusModal) { | ||
onOpenBonusModal({ | ||
bonusDiscountLineItems, | ||
product, | ||
itemsAdded | ||
}) | ||
} | ||
if (onClose) onClose() | ||
} | ||
|
||
return ( | ||
<Button | ||
onClick={handleClick} | ||
width="100%" | ||
variant="outline-gray" | ||
color="blue.600" | ||
size="md" | ||
height={9} | ||
minWidth={11} | ||
textStyle="sm" | ||
{...buttonProps} | ||
> | ||
{intl.formatMessage({ | ||
defaultMessage: 'Select Bonus Products', | ||
id: 'add_to_cart_modal.button.select_bonus_products' | ||
})} | ||
</Button> | ||
) | ||
} | ||
|
||
SelectBonusProductsButton.propTypes = { | ||
bonusDiscountLineItems: PropTypes.array, | ||
product: PropTypes.object, | ||
itemsAdded: PropTypes.array, | ||
onOpenBonusModal: PropTypes.func, | ||
onClose: PropTypes.func | ||
} | ||
|
||
export default SelectBonusProductsButton |
This file contains hidden or 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 hidden or 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 hidden or 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
91 changes: 91 additions & 0 deletions
91
packages/template-chakra-storefront/src/hooks/use-bonus-product-selection-modal.js
This file contains hidden or 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,91 @@ | ||
/* | ||
* Copyright (c) 2025, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import React, {useContext, useState, useEffect} from 'react' | ||
import {useLocation} from 'react-router-dom' | ||
import PropTypes from 'prop-types' | ||
import {Dialog, Button, Text, Box, useBreakpointValue} from '@chakra-ui/react' | ||
import {useModalState} from './use-modal-state' | ||
|
||
/** | ||
* Context for managing the BonusProductSelectionModal. | ||
* Used in top level App component. | ||
*/ | ||
export const BonusProductSelectionModalContext = React.createContext() | ||
export const useBonusProductSelectionModalContext = () => | ||
useContext(BonusProductSelectionModalContext) | ||
|
||
export const BonusProductSelectionModalProvider = ({children}) => { | ||
const bonusProductSelectionModal = useBonusProductSelectionModal() | ||
return ( | ||
<BonusProductSelectionModalContext.Provider value={bonusProductSelectionModal}> | ||
{children} | ||
<BonusProductSelectionModal /> | ||
</BonusProductSelectionModalContext.Provider> | ||
) | ||
} | ||
|
||
BonusProductSelectionModalProvider.propTypes = { | ||
children: PropTypes.node.isRequired | ||
} | ||
|
||
/** | ||
* Modal for selecting from available bonus products. | ||
*/ | ||
export const BonusProductSelectionModal = () => { | ||
const {isOpen, onClose, data} = useBonusProductSelectionModalContext() | ||
const size = useBreakpointValue({base: 'full', lg: 'lg', xl: 'xl'}) | ||
|
||
if (!isOpen) { | ||
return null | ||
} | ||
|
||
// todo: this component will be replaced in the next work item. The component will display bonus products available for selection. | ||
return ( | ||
<Dialog.Root | ||
size={size} | ||
open={isOpen} | ||
onOpenChange={onClose} | ||
scrollBehavior="inside" | ||
placement="center" | ||
> | ||
<Dialog.Backdrop /> | ||
<Dialog.Positioner> | ||
<Dialog.Content> | ||
<Dialog.Body bgColor="white" padding={8}> | ||
<Text fontSize="md" mb="4"> | ||
Bonus Product Modal | ||
</Text> | ||
{data && ( | ||
<Box p="4" bg="gray.100" borderRadius="md" mb="4"> | ||
<Text fontSize="sm" fontWeight="bold" mb="2"> | ||
Received Data: | ||
</Text> | ||
<Text fontSize="xs" fontFamily="mono"> | ||
{JSON.stringify(data, null, 2)} | ||
</Text> | ||
</Box> | ||
)} | ||
</Dialog.Body> | ||
<Dialog.Footer bgColor="white" padding={8}> | ||
<Button onClick={onClose} variant="solid" width="100%"> | ||
Close | ||
</Button> | ||
</Dialog.Footer> | ||
</Dialog.Content> | ||
</Dialog.Positioner> | ||
</Dialog.Root> | ||
) | ||
} | ||
|
||
export const useBonusProductSelectionModal = () => { | ||
const {isOpen, data, onOpen, onClose} = useModalState({ | ||
closeOnRouteChange: true, | ||
resetDataOnClose: true | ||
}) | ||
return {isOpen, data, onOpen, onClose} | ||
} |
Oops, something went wrong.
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.
Can we refactor this button into a new SelectBonusProductsButton component?
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.
This would be preferable