Skip to content

Commit

Permalink
fix: show tpa by setting (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and CarlLiu2023 committed Jul 28, 2023
1 parent 3a8e9d1 commit db140cd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default function App() {

useEffect(() => {
handleHideRegisterPage(registerEnabled)
}, [registerEnabled, storefrontConfig])
}, [registerEnabled, storefrontConfig, window.location.pathname])

useEffect(() => {
if (isOpen) {
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/components/HeadlessController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function HeadlessController({
salesRepCompanyId = 0,
isB2BUser,
currentChannelId,
registerEnabled,
},
} = useContext(GlobaledContext)
const { addToQuote: addProductFromPageToQuote } =
Expand Down Expand Up @@ -170,6 +171,7 @@ export default function HeadlessController({
storeDispatch,
saveFn,
setOpenPage,
registerEnabled,
})
},
addProducts: (shoppingListId, items) =>
Expand Down
18 changes: 14 additions & 4 deletions apps/storefront/src/hooks/dom/useOpenPDP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ interface AddProductFromPageParams {
storeDispatch: DispatchRedux<AnyAction>
saveFn: () => void
setOpenPage: (value: SetStateAction<OpenPageState>) => void
registerEnabled: boolean
}

export const addProductFromPage = ({
role,
storeDispatch,
saveFn,
setOpenPage,
registerEnabled,
}: AddProductFromPageParams) => {
if (role === 100) {
storeDispatch(
Expand All @@ -53,7 +55,7 @@ export const addProductFromPage = ({
message:
'Please create an account, or login to create a shopping list.',
cancelText: 'Cancel',
saveText: 'Register',
saveText: registerEnabled ? 'Register' : '',
saveFn,
},
})
Expand All @@ -76,7 +78,7 @@ export const useOpenPDP = ({ setOpenPage, role }: MutationObserverProps) => {
const storeDispatch = useDispatch()
const {
dispatch,
state: { isB2BUser, shoppingListEnabled },
state: { isB2BUser, shoppingListEnabled, registerEnabled },
} = useContext(GlobaledContext)

const [roleText] = useRole()
Expand All @@ -102,9 +104,10 @@ export const useOpenPDP = ({ setOpenPage, role }: MutationObserverProps) => {
storeDispatch,
saveFn: jumpRegister,
setOpenPage,
registerEnabled,
})
},
[role]
[role, registerEnabled]
)

const [openQuickView] = useDomVariation(
Expand Down Expand Up @@ -217,5 +220,12 @@ export const useOpenPDP = ({ setOpenPage, role }: MutationObserverProps) => {
item.removeEventListener('click', pdpCallBack)
})
}
}, [isB2BUser, shoppingListEnabled, openQuickView, shoppingListBtn, roleText])
}, [
isB2BUser,
shoppingListEnabled,
openQuickView,
shoppingListBtn,
roleText,
registerEnabled,
])
}
12 changes: 11 additions & 1 deletion apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ export default function Login(props: RegisteredProps) {
navigate('/forgotpassword')
}

const loginAndRegisterContainerWidth = registerEnabled ? '100%' : '50%'
const loginContainerWidth = registerEnabled ? '50%' : 'auto'

return (
<B3Card setOpenPage={setOpenPage}>
<LoginContainer paddings={isMobile ? '0' : '20px 20px'}>
Expand Down Expand Up @@ -304,13 +307,18 @@ export default function Login(props: RegisteredProps) {
<Box
sx={{
padding: isMobile ? 0 : '0 5%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
}}
>
{loginInfo.widgetHeadText && (
<LoginWidget
sx={{
mt: isMobile ? '20px' : '32px',
minHeight: '48px',
width: registerEnabled || isMobile ? '100%' : '50%',
}}
isVisible={loginInfo.isShowWidgetHead}
html={loginInfo.widgetHeadText}
Expand All @@ -324,11 +332,12 @@ export default function Login(props: RegisteredProps) {
display: 'flex',
flexDirection: isMobile ? 'column' : 'row',
justifyContent: 'center',
width: isMobile ? 'auto' : loginAndRegisterContainerWidth,
}}
>
<Box
sx={{
width: isMobile ? 'auto' : '50%',
width: isMobile ? 'auto' : loginContainerWidth,
paddingRight: isMobile ? 0 : '2%',
ml: '16px',
mr: isMobile ? '16px' : '',
Expand Down Expand Up @@ -363,6 +372,7 @@ export default function Login(props: RegisteredProps) {
sx={{
mt: '20px',
minHeight: '48px',
width: registerEnabled || isMobile ? '100%' : '50%',
}}
isVisible={loginInfo.isShowWidgetFooter}
html={loginInfo.widgetFooterText}
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/utils/b3HideRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const handleHideRegisterPage = (registerEnabled: boolean) => {

if (registerPageAll.length > 0) {
registerPageAll.forEach((page: CustomFieldItems) => {
page.style.display = registerEnabled ? 'block' : 'none'
page.style.display = registerEnabled ? 'inline-block' : 'none'
})
}

if (navUserOrText.length > 0) {
navUserOrText.forEach((text: CustomFieldItems) => {
text.style.display = registerEnabled ? 'block' : 'none'
text.style.display = registerEnabled ? 'inline-block' : 'none'
})
}
}
Expand Down

0 comments on commit db140cd

Please sign in to comment.