Skip to content

Commit

Permalink
feat: add Quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile authored and b3aton committed Feb 3, 2023
1 parent 7aac756 commit bb42675
Show file tree
Hide file tree
Showing 70 changed files with 6,687 additions and 327 deletions.
511 changes: 384 additions & 127 deletions apps/storefront/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/storefront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@mui/x-date-pickers": "^5.0.0-beta.0",
"@rollup/plugin-graphql": "^1.1.0",
"@types/babel__core": "^7.1.19",
"copy-to-clipboard": "^3.3.3",
"date-fns": "^2.28.0",
"http-server": "^14.1.1",
"lodash": "^4.17.21",
Expand Down
59 changes: 51 additions & 8 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import {
import {
useOpenPDP,
useRefresh,
useMyQuote,
useRegisteredbctob2b,
} from '@/hooks'

import {
loginInfo,
getCurrentCustomerInfo,
getLogo,
getQuoteEnabled,
} from '@/utils'

import {
Expand Down Expand Up @@ -60,6 +62,11 @@ export default function App() {
role,
logo,
bcChannelId,
isAgenting,
quoteConfig,
storefrontConfig,
productQuoteEnabled,
cartQuoteEnabled,
},
dispatch,
} = useContext(GlobaledContext)
Expand All @@ -70,18 +77,25 @@ export default function App() {
role,
})

useMyQuote({
setOpenPage,
productQuoteEnabled,
cartQuoteEnabled,
})

useRefresh(isOpen, openUrl)

const setLogo = async () => {
const getQuoteConfig = async () => {
const {
quoteConfig,
} = await getB2BRegisterLogo()
const logo = getLogo(quoteConfig)
const quoteLogo = getLogo(quoteConfig)

dispatch({
type: 'common',
payload: {
logo,
logo: logo || quoteLogo,
quoteConfig,
},
})
}
Expand Down Expand Up @@ -155,27 +169,56 @@ export default function App() {
})
}

const guestGotoPage = () => {
const url = hash.split('#')[1] || ''
if (url === '/login' || url === '/quoteDraft' || url.includes('/quoteDetail')) {
setOpenPage({
isOpen: true,
openUrl: url,
})
}
}

const init = async () => {
// bc token
if (!BcToken) {
await loginInfo()
}

if (!logo) {
setLogo()
}
getQuoteConfig()
setStorefrontConfig()
setChannelStoreType(bcChannelId)
// refresh
if (!customerId) {
const data = await getCurrentCustomerInfo(dispatch)
if (data) gotoPage(data.role)
if (data) {
gotoPage(data.role)
} else {
guestGotoPage()
}
}
if (customerId && hash) gotoPage()
}

init()
}, [])

useEffect(() => {
if (quoteConfig.switchStatus.length > 0 && storefrontConfig) {
const {
productQuoteEnabled,
cartQuoteEnabled,
} = getQuoteEnabled(quoteConfig, storefrontConfig, role, isB2BUser, isAgenting)

dispatch({
type: 'common',
payload: {
productQuoteEnabled,
cartQuoteEnabled,
},
})
}
}, [isB2BUser, isAgenting, role, quoteConfig, storefrontConfig])

useRegisteredbctob2b(setOpenPage, isB2BUser, customerId)

return (
Expand Down
58 changes: 58 additions & 0 deletions apps/storefront/src/components/B3CollapseContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
Box,
Collapse,
Typography,
} from '@mui/material'

import {
useState,
ReactNode,
} from 'react'

import ExpandLess from '@mui/icons-material/ExpandLess'
import ExpandMore from '@mui/icons-material/ExpandMore'

interface CollapseContainerProps{
title?: string,
header?: ReactNode,
defaultOpen?: boolean,
children: ReactNode,
}

export const B3CollapseContainer = (props: CollapseContainerProps) => {
const {
children,
title = '',
header,
defaultOpen = false,
} = props

const [open, setOpen] = useState(defaultOpen)

const handleClick = () => {
setOpen(!open)
}

return (
<Box>
<Box
onClick={handleClick}
sx={{
display: 'flex',
justifyContent: 'space-between',
cursor: 'pointer',
}}
>
{header || <Typography variant="h5">{title}</Typography>}
{open ? <ExpandLess /> : <ExpandMore />}
</Box>
<Collapse
in={open}
timeout="auto"
unmountOnExit
>
{children}
</Collapse>
</Box>
)
}
4 changes: 4 additions & 0 deletions apps/storefront/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ export {
export {
B3LinkTipContent,
} from './B3LinkTipContent'

export {
B3CollapseContainer,
} from './B3CollapseContainer'
54 changes: 52 additions & 2 deletions apps/storefront/src/components/layout/B3Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import {
B3Mainheader,
} from './B3Mainheader'

import {
B3Dialog,
} from '../B3Dialog'

import {
routes,
} from '@/shared/routes'
Expand All @@ -60,26 +64,50 @@ export function B3Layout({
state: {
emailAddress,
customerId,
globalMessageDialog,
},
dispatch,
} = useContext(GlobaledContext)

const navigate = useNavigate()

useEffect(() => {
if (!emailAddress || !customerId) {
if ((!emailAddress || !customerId) && location.pathname !== '/quoteDraft' && !location.pathname.includes('/quoteDetail')) {
navigate('/login')
}
}, [emailAddress, customerId])

useEffect(() => {
const itemsRoutes = routes.filter((item: RouteItem) => item.path === location.pathname)
if (itemsRoutes.length) {
if (itemsRoutes.length && location.pathname !== '/quoteDraft') {
setTitle(itemsRoutes[0].name)
} else {
setTitle('')
}
dispatch({
type: 'common',
payload: {
tipMessage: {
msgs: [],
},
},
})
}, [location])

const messageDialogClose = () => {
dispatch({
type: 'common',
payload: {
globalMessageDialog: {
open: false,
title: '',
message: '',
cancelText: 'Cancel',
},
},
})
}

return (
<Box>

Expand Down Expand Up @@ -113,6 +141,7 @@ export function B3Layout({
flexDirection: 'column',
width: '250px',
pl: '20px',
displayPrint: 'none',
}}
>
<B3Logo />
Expand Down Expand Up @@ -149,6 +178,27 @@ export function B3Layout({
// </Box>
)
}

<B3Dialog
isOpen={globalMessageDialog.open}
title={globalMessageDialog.title}
leftSizeBtn={globalMessageDialog.cancelText}
rightSizeBtn={globalMessageDialog.saveText}
handleLeftClick={globalMessageDialog.cancelFn || messageDialogClose}
handRightClick={globalMessageDialog.saveFn}
showRightBtn={!!globalMessageDialog.saveText}
>
<Box
sx={{
display: 'flex',
justifyContent: `${isMobile ? 'center' : 'start'}`,
width: `${isMobile ? '100%' : '450px'}`,
height: '100%',
}}
>
{globalMessageDialog.message}
</Box>
</B3Dialog>
</Box>

)
Expand Down
31 changes: 18 additions & 13 deletions apps/storefront/src/components/layout/B3Mainheader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,24 @@ export const B3Mainheader = ({
</Box>
<B3AccountInfo />
</Box>
<Box
component="h3"
sx={{
height: '40px',
m: '0',
fontSize: '24px',
display: 'flex',
alignItems: 'end',
mb: '8px',
}}
>
{title}
</Box>
{
title && (
<Box
component="h3"
sx={{
height: '40px',
m: '0',
fontSize: '24px',
display: 'flex',
alignItems: 'end',
mb: '8px',
}}
>
{title}
</Box>
)
}

</Box>

)
Expand Down
38 changes: 38 additions & 0 deletions apps/storefront/src/components/layout/B3Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,47 @@ export const B3Nav = ({

const {
state: globalState,
dispatch,
} = useContext(GlobaledContext)

const jumpRegister = () => {
navigate('/registered')
dispatch({
type: 'common',
payload: {
globalMessageDialog: {
open: false,
title: '',
message: '',
cancelText: 'Cancel',
},
},
})
}

const handleClick = (item: RouteItem) => {
const {
role,
} = globalState

if (role === 100) {
dispatch({
type: 'common',
payload: {
globalMessageDialog: {
open: true,
title: 'Registration',
message: 'To receive full access to buyer portal, please register. It will take 2 minutes. ',
cancelText: 'Cancel',
saveText: 'Register',
saveFn: jumpRegister,
},
},
})

return
}

navigate(item.path)
if (isMobile && closeSidebar) {
closeSidebar(false)
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/spin/B3Sping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface B3SpingProps {
thickness?: number & undefined,
isCloseLoading?: Boolean,
background?: string,
spinningHeight?: number,
spinningHeight?: number | string,
isFlex?: boolean,
}

Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/spin/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ styled('div')(() => ({
}))

interface SpinContextProps {
height?: number,
height?: number | string,
isFlex?: boolean,
}

Expand Down
Loading

0 comments on commit bb42675

Please sign in to comment.