Skip to content

Commit

Permalink
fix: shoppingList footer permission repair
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile authored and BrianJiang2021 committed Sep 28, 2023
1 parent addfb8a commit 02829bd
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,22 +459,48 @@ function ShoppingDetailFooter(props: ShoppingDetailFooterProps) {
}
}

const buttonList = [
{
name: allowJuniorPlaceOrder
? b3Lang('shoppingList.footer.proceedToCheckout')
: b3Lang('shoppingList.footer.addToCart'),
const buttons = {
adSelectedToCart: {
name: b3Lang('shoppingList.footer.addToCart'),
key: 'add-selected-to-cart',
handleClick: handleAddProductsToCart,
isDisabled: false,
},
{
proceedToCheckout: {
name: b3Lang('shoppingList.footer.proceedToCheckout'),
key: 'add-select-to-checkout',
handleClick: handleAddProductsToCart,
isDisabled: false,
},
addSelectedToQuote: {
name: b3Lang('shoppingList.footer.addToQuote'),
key: 'add-selected-to-quote',
handleClick: handleAddSelectedToQuote,
isDisabled: !productQuoteEnabled,
isDisabled: false,
},
]
}

const allowButtonList = () => {
if (!(shoppingListInfo?.status === 0 || !isB2BUser)) return []

if (role === 2) {
if (allowJuniorPlaceOrder && productQuoteEnabled) {
return [buttons.proceedToCheckout, buttons.addSelectedToQuote]
}

if (allowJuniorPlaceOrder) return [buttons.proceedToCheckout]
if (productQuoteEnabled) {
return [buttons.adSelectedToCart, buttons.addSelectedToQuote]
}
return []
}

return productQuoteEnabled
? [buttons.adSelectedToCart, buttons.addSelectedToQuote]
: [buttons.adSelectedToCart]
}

const buttonList = allowButtonList()

return (
<Grid
Expand Down Expand Up @@ -584,8 +610,7 @@ function ShoppingDetailFooter(props: ShoppingDetailFooterProps) {
/>
</CustomButton>
)}
{((role !== 2 && shoppingListInfo?.status === 0) ||
!isB2BUser) && (
{buttonList.length && (
<Box
sx={{
display: 'flex',
Expand All @@ -595,42 +620,54 @@ function ShoppingDetailFooter(props: ShoppingDetailFooterProps) {
width: isMobile ? '100%' : 'auto',
}}
>
<CustomButton
variant="contained"
onClick={handleOpenBtnList}
sx={{
marginRight: isMobile ? '1rem' : 0,
width: isMobile ? '100%' : 'auto',
}}
endIcon={<ArrowDropDown />}
>
{b3Lang('shoppingList.footer.addSelectedTo')}
</CustomButton>
<Menu
id="basic-menu"
anchorEl={anchorEl}
open={open}
onClose={handleClose}
MenuListProps={{
'aria-labelledby': 'basic-button',
}}
>
{buttonList.length > 0 &&
buttonList.map((button) => {
if (button.isDisabled) return null

return (
<MenuItem
key={button.key}
onClick={() => {
button.handleClick()
}}
>
{button.name}
</MenuItem>
)
})}
</Menu>
{buttonList.length === 1 && (
<CustomButton
variant="contained"
onClick={buttonList[0].handleClick}
sx={{
marginRight: isMobile ? '1rem' : 0,
width: isMobile ? '100%' : 'auto',
}}
>
{buttonList[0].name}
</CustomButton>
)}
{buttonList.length === 2 && (
<>
<CustomButton
variant="contained"
onClick={handleOpenBtnList}
sx={{
marginRight: isMobile ? '1rem' : 0,
width: isMobile ? '100%' : 'auto',
}}
endIcon={<ArrowDropDown />}
>
{b3Lang('shoppingList.footer.addSelectedTo')}
</CustomButton>
<Menu
id="basic-menu"
anchorEl={anchorEl}
open={open}
onClose={handleClose}
MenuListProps={{
'aria-labelledby': 'basic-button',
}}
>
{buttonList.length > 1 &&
buttonList.map((button) => (
<MenuItem
key={button.key}
onClick={() => {
button.handleClick()
}}
>
{button.name}
</MenuItem>
))}
</Menu>
</>
)}
</Box>
)}
</Box>
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/shared/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ const getAllowedRoutes = (globalState: GlobalState): RouteItem[] => {
(config: QuoteConfigProps) =>
config.key === 'shopping_list_on_product_page'
)?.extraFields
return storefrontConfig.quotes && shoppingListOnProductPage?.b2b
return storefrontConfig.shoppingLists && shoppingListOnProductPage?.b2b
}

if (item.configKey === 'quickOrderPad') {
Expand Down

0 comments on commit 02829bd

Please sign in to comment.