Skip to content

Commit

Permalink
fix: quote btn permission
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-liu-smile committed Mar 10, 2023
1 parent fb050be commit 5ca1cc1
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 28 deletions.
12 changes: 9 additions & 3 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default function App() {
storefrontConfig,
productQuoteEnabled,
cartQuoteEnabled,
shoppingListEnabled,
},
dispatch,
} = useContext(GlobaledContext)
Expand All @@ -88,7 +89,7 @@ export default function App() {
useOpenPDP({
setOpenPage,
isB2BUser,
role,
shoppingListEnabled,
})

useMyQuote({
Expand Down Expand Up @@ -177,10 +178,11 @@ export default function App() {
}, [])

useEffect(() => {
const isRelogin = sessionStorage.getItem('isreLogin')
loginAndRegister()
const init = async () => {
// bc token
if (!BcToken) {
if (!BcToken || isRelogin) {
await loginInfo()
}

Expand All @@ -192,7 +194,7 @@ export default function App() {
isAgenting,
}

if (!customerId) {
if (!customerId || isRelogin) {
const info = await getCurrentCustomerInfo(dispatch)
if (info) {
userInfo.role = info?.role
Expand All @@ -203,6 +205,8 @@ export default function App() {
if (!href.includes('checkout') && !(customerId && !window.location.hash)) {
gotoAllowedAppPage(+userInfo.role, userInfo.isAgenting, gotoPage)
}

sessionStorage.removeItem('isreLogin')
showPageMask(false)
}

Expand All @@ -221,13 +225,15 @@ export default function App() {
const {
productQuoteEnabled,
cartQuoteEnabled,
shoppingListEnabled,
} = getQuoteEnabled(quoteConfig, storefrontConfig, role, isB2BUser, isAgenting)

dispatch({
type: 'common',
payload: {
productQuoteEnabled,
cartQuoteEnabled,
shoppingListEnabled,
},
})
}
Expand Down
6 changes: 6 additions & 0 deletions apps/storefront/src/components/B3HoverButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const B3HoverButton = (props: B3HoverButtonProps) => {

const [isMobile] = useMobile()

const {
href,
} = window.location

if (href.includes('/checkout')) return <></>

return (
<Snackbar
sx={{
Expand Down
3 changes: 3 additions & 0 deletions apps/storefront/src/components/B3MasquradeGobalTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ export const B3MasquradeGobalTip = (props: B3MasquradeGobalTipProps) => {

const {
hash,
href,
} = window.location

if (href.includes('/checkout')) return <></>

const isAddBottom = bottomHeightPage.some((item: string) => hash.includes(item))

const [isExpansion, setExpansion] = useState<boolean>(true)
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/upload/B3Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const B3Upload = () => {
}

const openFile = () => {
if (uploadRef.current) uploadRef.current.children[1].click()
if (uploadRef.current) (uploadRef.current.children[1] as any).click()
}

const content = (
Expand Down
6 changes: 3 additions & 3 deletions apps/storefront/src/hooks/useOpenPDP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import type {
interface MutationObserverProps {
setOpenPage: Dispatch<SetStateAction<OpenPageState>>,
isB2BUser: boolean,
role: string | number,
shoppingListEnabled: boolean,
}

const useOpenPDP = ({
setOpenPage, isB2BUser, role,
setOpenPage, isB2BUser, shoppingListEnabled,
}: MutationObserverProps) => {
const [openQuickViewNum, setOpenQuickViewNum] = useState<number>(0)

Expand All @@ -41,7 +41,7 @@ const useOpenPDP = ({

useMutationObservable(document.documentElement, cd)

useB3PDPOpen(globalB3['dom.setToShoppingListParentEl'], pdpCallBbck, isB2BUser, role, openQuickViewNum)
useB3PDPOpen(globalB3['dom.setToShoppingListParentEl'], pdpCallBbck, isB2BUser, shoppingListEnabled, openQuickViewNum)
}

export {
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const Dashboard = () => {
edges = [],
totalCount,
},
}: any = await superAdminCompanies(+B3UserId, params.q)
}: any = await superAdminCompanies(+B3UserId, params)

return {
edges,
Expand Down
3 changes: 3 additions & 0 deletions apps/storefront/src/shared/global/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface GlobalState {
value: boolean,
enabledStatus: boolean,
},
shoppingLists: boolean,
},
storeEnabled: boolean,
storeName: string,
Expand All @@ -110,6 +111,7 @@ export interface GlobalState {
countriesList?: Country[],
productQuoteEnabled: boolean,
cartQuoteEnabled: boolean,
shoppingListEnabled: boolean,
quoteConfig: {
switchStatus: {
[key: string]: string
Expand Down Expand Up @@ -171,6 +173,7 @@ export const initState = {
countriesList: [],
productQuoteEnabled: false,
cartQuoteEnabled: false,
shoppingListEnabled: false,
quoteConfig: {
switchStatus: [],
otherConfigs: [],
Expand Down
20 changes: 10 additions & 10 deletions apps/storefront/src/shared/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const routes: RouteItem[] = [
wsKey: 'router-orders',
isMenuItem: false,
component: OrderDetail,
permissions: [0, 1, 2, 3, 99, 100],
permissions: [0, 1, 2, 3, 4, 99, 100],
isTokenLogin: true,
},
{
Expand Down Expand Up @@ -200,15 +200,15 @@ const routes: RouteItem[] = [
permissions: [0, 1, 2, 3, 99, 100],
isTokenLogin: false,
},
{
path: '/xxxxx',
name: 'Recently viewed',
wsKey: 'router-orders',
isMenuItem: true,
component: Dashboard,
permissions: [0, 1, 2, 3, 99, 100],
isTokenLogin: true,
},
// {
// path: '/xxxxx',
// name: 'Recently viewed',
// wsKey: 'router-orders',
// isMenuItem: true,
// component: Dashboard,
// permissions: [0, 1, 2, 3, 99, 100],
// isTokenLogin: true,
// },
]

const firstLevelRouting: RouteFirstLevelItem[] = [
Expand Down
12 changes: 6 additions & 6 deletions apps/storefront/src/shared/service/b2b/graphql/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const getAgentInfoQl = (customerId: string | number) => `{
}
}`

const superAdminCompaniesQl = (id: number, q: string) => `{
const superAdminCompaniesQl = (id: number, params: CustomFieldItems) => `{
superAdminCompanies(
superAdminId: ${id}
offset: 0
first: 10
search: "${q || ''}"
first: ${params.first}
offset: ${params.offset}
search: "${params.q || ''}"
) {
edges{
node{
Expand Down Expand Up @@ -140,8 +140,8 @@ export const getAgentInfo = (customerId: string | number): CustomFieldItems => B
query: getAgentInfoQl(customerId),
})

export const superAdminCompanies = (id: number, q: string): CustomFieldItems => B3Request.graphqlB2B({
query: superAdminCompaniesQl(id, q),
export const superAdminCompanies = (id: number, params: CustomFieldItems): CustomFieldItems => B3Request.graphqlB2B({
query: superAdminCompaniesQl(id, params),
})

export const superAdminBeginMasquerade = (companyId: number, userId: number): CustomFieldItems => B3Request.graphqlB2B({
Expand Down
11 changes: 10 additions & 1 deletion apps/storefront/src/utils/b3Init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const getQuoteEnabled = (
value: boolean,
enabledStatus: boolean,
},
shoppingLists: boolean,
},
role: number | string,
isB2BUser: boolean,
Expand All @@ -33,6 +34,8 @@ export const getQuoteEnabled = (

const quoteEnabled = storefrontConfig.quotes || false

let shoppingListEnabled = storefrontConfig.shoppingLists || false

quoteConfig.switchStatus.forEach((config) => {
if (config.key === 'quote_customer') {
customerEnabled = config.isEnabled
Expand All @@ -57,13 +60,19 @@ export const getQuoteEnabled = (
if (`${role}` === '100') { // guest
productQuoteEnabled = productQuoteEnabled && guestEnabled === '1'
cartQuoteEnabled = cartQuoteEnabled && guestEnabled === '1'
} else if (!isB2BUser || (`${role}` === '3' && !isAgenting)) { // BCUser
shoppingListEnabled = false
} else if (`${role}` === '3' && !isAgenting) {
productQuoteEnabled = false
cartQuoteEnabled = false
shoppingListEnabled = false
} else if (!isB2BUser) { // BCUser
productQuoteEnabled = productQuoteEnabled && bcUserEnabled === '1'
cartQuoteEnabled = cartQuoteEnabled && bcUserEnabled === '1'
}

return {
productQuoteEnabled,
cartQuoteEnabled,
shoppingListEnabled,
}
}
6 changes: 3 additions & 3 deletions packages/hooks/useB3PDPOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const removeElement = (_element: CustomFieldItems) => {
}
}

export const useB3PDPOpen = (el: string, cd: () => void, isB2BUser: boolean, role: string | number, openQuickViewNum: number) => {
export const useB3PDPOpen = (el: string, cd: () => void, isB2BUser: boolean, shoppingListEnabled: boolean, openQuickViewNum: number) => {
useEffect(() => {
const addToCartAll = document.querySelectorAll(el)
const wishlistSdd = document.querySelector('form[data-wishlist-add]')
let shoppingBtnDom: CustomFieldItems | null = null
if (!addToCartAll.length) return
if (document.querySelectorAll('#shoppingListBtn').length) return
if (isB2BUser && (+role === 0 || +role === 1 || +role === 2)) {
if (shoppingListEnabled) {
addToCartAll.forEach((node: CustomFieldItems) => {
shoppingBtnDom = document.createElement('div')
shoppingBtnDom.setAttribute('id', 'shoppingListBtn')
Expand All @@ -40,5 +40,5 @@ export const useB3PDPOpen = (el: string, cd: () => void, isB2BUser: boolean, rol
shoppingBtnDom.removeEventListener('click', cd)
}
}
}, [isB2BUser, role, openQuickViewNum])
}, [isB2BUser, shoppingListEnabled, openQuickViewNum])
}

0 comments on commit 5ca1cc1

Please sign in to comment.