Skip to content

Commit

Permalink
feat: get allowed routes on headless controller (#204)
Browse files Browse the repository at this point in the history
* fix: if a B2BToken is already set up, skip verification

* feat: get allowed routes on headless controller

* fix: refactor out the component from getAllowedRoutes (#205)

* fix: refactor out the component from getAllowedRoutes

* fix: also export isMenuItem for catalyst

* fix: the file location of B3MainHeader

* fix: react types

---------

Co-authored-by: Micah Thomas <[email protected]>
  • Loading branch information
bc-victor and bc-micah authored Jan 9, 2025
1 parent 61310b4 commit 4b8ab61
Show file tree
Hide file tree
Showing 16 changed files with 384 additions and 351 deletions.
9 changes: 5 additions & 4 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
// words - list of words to be always considered correct
// cspell:disable
"words": [
"accountincorrect",
"Agenting",
"bigcommerce",
"clickaway",
"Enduser",
"extrafields",
"forgotpassword",
"gql.tada",
"msword",
"Turborepo",
"registeredbctob2b",
"purchasability",
"forgotpassword",
"accountincorrect"
"registeredbctob2b",
"Turborepo"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/components/B3GlobalTip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { lazy, useContext, useEffect } from 'react';
import { flushSync } from 'react-dom';

import { DynamicallyVariableedContext } from '@/shared/dynamicallyVariable';
import { DynamicallyVariableContext } from '@/shared/dynamicallyVariable';
import { MsgsProps } from '@/shared/dynamicallyVariable/context/config';

const B3Tip = lazy(() => import('./B3Tip'));
Expand All @@ -10,7 +10,7 @@ export default function B3GlobalTip() {
const {
state: { globalTipMessage },
dispatch,
} = useContext(DynamicallyVariableedContext);
} = useContext(DynamicallyVariableContext);

useEffect(() => {
window.globalTipDispatch = dispatch;
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/components/HeadlessController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { addProductsToShoppingList } from '@/pages/PDP';
import { type SetOpenPage } from '@/pages/SetOpenPage';
import { CustomStyleContext } from '@/shared/customStyleButton';
import { GlobalContext } from '@/shared/global';
import { getAllowedRoutesWithoutComponent } from '@/shared/routeList';
import { superAdminCompanies } from '@/shared/service/b2b';
import B3Request from '@/shared/service/request/b3Fetch';
import {
Expand Down Expand Up @@ -129,7 +130,8 @@ export default function HeadlessController({ setOpenPage }: HeadlessControllerPr
...window.b2b,
callbacks: Manager,
utils: {
getRoutes: () => [],
getRoutes: () => getAllowedRoutesWithoutComponent(globalState),
// getRoutes: () => [],
openPage: (page) =>
setTimeout(() => {
if (page === 'CLOSE') {
Expand Down
8 changes: 4 additions & 4 deletions apps/storefront/src/components/layout/B3Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useB3Lang } from '@b3/lang';
import { Box, useMediaQuery } from '@mui/material';

import useMobile from '@/hooks/useMobile';
import { DynamicallyVariableedContext } from '@/shared/dynamicallyVariable';
import { DynamicallyVariableContext } from '@/shared/dynamicallyVariable';
import { getIsTokenGotoPage, routes } from '@/shared/routes';
import { useAppSelector } from '@/store';

Expand All @@ -13,7 +13,7 @@ import CompanyCredit from '../CompanyCredit';

import B3CloseAppButton from './B3CloseAppButton';
import B3Logo from './B3Logo';
import B3Mainheader from './B3Mainheader';
import B3MainHeader from './B3MainHeader';
import B3MobileLayout from './B3MobileLayout';
import B3Nav from './B3Nav';

Expand All @@ -39,7 +39,7 @@ export default function B3Layout({ children }: { children: ReactNode }) {
const {
state: { globalMessageDialog },
dispatch,
} = useContext(DynamicallyVariableedContext);
} = useContext(DynamicallyVariableContext);

const navigate = useNavigate();

Expand Down Expand Up @@ -146,7 +146,7 @@ export default function B3Layout({ children }: { children: ReactNode }) {
p: '0 0px 0px 50px',
}}
>
<B3Mainheader title={title} />
<B3MainHeader title={title} />
<CompanyCredit />
<Box
component="main"
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/components/layout/B3LayoutTip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useContext, useEffect } from 'react';
import { flushSync } from 'react-dom';

import { DynamicallyVariableedContext } from '@/shared/dynamicallyVariable';
import { DynamicallyVariableContext } from '@/shared/dynamicallyVariable';
import { MsgsProps } from '@/shared/dynamicallyVariable/context/config';

import B3Tip from '../B3Tip';
Expand All @@ -10,7 +10,7 @@ function B3LayoutTip() {
const {
state: { tipMessage },
dispatch,
} = useContext(DynamicallyVariableedContext);
} = useContext(DynamicallyVariableContext);

useEffect(() => {
window.tipDispatch = dispatch;
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/components/layout/B3Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useB3Lang } from '@b3/lang';
import { Badge, List, ListItem, ListItemButton, ListItemText, useTheme } from '@mui/material';

import { useMobile } from '@/hooks';
import { DynamicallyVariableedContext } from '@/shared/dynamicallyVariable';
import { DynamicallyVariableContext } from '@/shared/dynamicallyVariable';
import { GlobalContext } from '@/shared/global';
import { getAllowedRoutes } from '@/shared/routes';
import { useAppSelector } from '@/store';
Expand All @@ -22,7 +22,7 @@ export default function B3Nav({ closeSidebar }: B3NavProps) {
const location = useLocation();
const b3Lang = useB3Lang();

const { dispatch } = useContext(DynamicallyVariableedContext);
const { dispatch } = useContext(DynamicallyVariableContext);
const role = useAppSelector(({ company }) => company.customer.role);

const { state: globalState } = useContext(GlobalContext);
Expand Down
8 changes: 2 additions & 6 deletions apps/storefront/src/components/layout/B3RenderRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import { Outlet, Route, Routes, useLocation, useNavigate } from 'react-router-do
import { RegisteredProvider } from '@/pages/Registered/context/RegisteredContext';
import { type SetOpenPage } from '@/pages/SetOpenPage';
import { GlobalContext } from '@/shared/global';
import {
firstLevelRouting,
getAllowedRoutes,
RouteFirstLevelItem,
RouteItem,
} from '@/shared/routes';
import { RouteFirstLevelItem, RouteItem } from '@/shared/routeList';
import { firstLevelRouting, getAllowedRoutes } from '@/shared/routes';
import { getPageTranslations, useAppDispatch } from '@/store';
import { channelId } from '@/utils';

Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/hooks/useSetOpen.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useContext, useEffect } from 'react';

import { DynamicallyVariableedContext } from '@/shared/dynamicallyVariable';
import { DynamicallyVariableContext } from '@/shared/dynamicallyVariable';
import { GlobalContext } from '@/shared/global';

const { height: defaultHeight, overflow: defaultOverflow } = document.body.style;

const useSetOpen = (isOpen: boolean, _?: string, params?: CustomFieldItems) => {
const { dispatch } = useContext(GlobalContext);

const { dispatch: dispatchMsg } = useContext(DynamicallyVariableedContext);
const { dispatch: dispatchMsg } = useContext(DynamicallyVariableContext);
useEffect(() => {
if (isOpen) {
// The iframe screen is removed
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare interface Window {
callbacks: import('@/utils/b3CallbackManager').default;
utils: {
openPage: (page: import('./constants').HeadlessRoute) => void;
getRoutes: () => import('@/shared/routes').RouteItem[];
getRoutes: () => import('@/shared/routeList').BuyerPortalRoute[];
quote: {
addProductFromPage: (item: import('@/utils').LineItems) => void;
addProductsFromCart: () => Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useMemo, useReducer } from 'react';

import { DynamicallyVariableedProviderProps, initState } from './config';
import { DynamicallyVariableedContext, reducer } from './index';
import { DynamicallyVariableProviderProps, initState } from './config';
import { DynamicallyVariableContext, reducer } from './index';

export default function DynamicallyVariableProvider(props: DynamicallyVariableedProviderProps) {
export default function DynamicallyVariableProvider(props: DynamicallyVariableProviderProps) {
const [state, dispatch] = useReducer(reducer, initState);

const { children } = props;
Expand All @@ -17,8 +17,8 @@ export default function DynamicallyVariableProvider(props: DynamicallyVariableed
);

return (
<DynamicallyVariableedContext.Provider value={DynamicallyVariableValue}>
<DynamicallyVariableContext.Provider value={DynamicallyVariableValue}>
{children}
</DynamicallyVariableedContext.Provider>
</DynamicallyVariableContext.Provider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export interface DynamicallyVariableAction {
}

export type DispatchProps = Dispatch<Partial<DynamicallyVariableAction>>;
export interface DynamicallyVariableContext {
export interface DynamicallyVariableContextInterface {
state: DynamicallyVariableState;
dispatch: DispatchProps;
}

export interface DynamicallyVariableedProviderProps {
export interface DynamicallyVariableProviderProps {
children: ReactNode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { createContext } from 'react';

import {
DynamicallyVariableAction,
DynamicallyVariableContext,
DynamicallyVariableContextInterface,
DynamicallyVariableState,
initState,
} from './config';

export const DynamicallyVariableedContext = createContext<DynamicallyVariableContext>({
export const DynamicallyVariableContext = createContext<DynamicallyVariableContextInterface>({
state: initState,
dispatch: () => {},
});
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/shared/dynamicallyVariable/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { DynamicallyVariableedContext } from './context';
export { DynamicallyVariableContext } from './context';
export { default as DynamicallyVariableProvider } from './context/Provider';
Loading

0 comments on commit 4b8ab61

Please sign in to comment.