diff --git a/packages/react-sdk-components/src/samples/FullPortal/index.tsx b/packages/react-sdk-components/src/samples/FullPortal/index.tsx index 9bcadd96..e1fa0019 100644 --- a/packages/react-sdk-components/src/samples/FullPortal/index.tsx +++ b/packages/react-sdk-components/src/samples/FullPortal/index.tsx @@ -1,6 +1,6 @@ +/* eslint-disable @typescript-eslint/no-use-before-define */ /* eslint-disable no-console */ import { useEffect, useMemo, useState } from 'react'; -import ReactDOM from 'react-dom'; import { useLocation, useNavigate } from 'react-router-dom'; import CssBaseline from '@mui/material/CssBaseline'; import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles'; @@ -24,10 +24,22 @@ function useQuery() { return useMemo(() => new URLSearchParams(search), [search]); } +function RootComponent(props) { + const PegaConnectObj = createPConnectComponent(); + const thePConnObj = ; + + const contextValue = useMemo(() => { + return { store: PCore.getStore() }; + }, []); + + return {thePConnObj}; +} + export default function FullPortal() { const [portalSelectionScreen, setPortalSelectionScreen] = useState(false); const [defaultPortalName, setDefaultPortalName] = useState(''); const [availablePortals, setAvailablePortals] = useState([]); + const [rootComponentProps, setRootComponentProps] = useState(null); const navigate = useNavigate(); const query = useQuery(); @@ -40,71 +52,16 @@ export default function FullPortal() { sessionStorage.setItem('rsdk_locale', localeOverride); } - // const outlet = document.getElementById("outlet"); - - // from react_root.js with some modifications - // eslint-disable-next-line react/no-unstable-nested-components - function RootComponent(props) { - // const { portalTarget, styleSheetTarget } = props; - const PegaConnectObj = createPConnectComponent(); - - // remove from Provider to work around compiler error for now: context={StoreContext} - // return ( - // - // - // - // ); - - // const thePConnObj =
the RootComponent
; - const thePConnObj = ; - - return ( - // eslint-disable-next-line react/jsx-no-constructed-context-values - {thePConnObj} - ); - } - /** * Callback from onPCoreReady that's called once the top-level render object * is ready to be rendered * @param inRenderObj the initial, top-level PConnect object to render */ function initialRender(inRenderObj) { - // modified from react_root.js render - const { props, domContainerID = null, componentName, portalTarget, styleSheetTarget } = inRenderObj; - let target: any = null; - if (domContainerID !== null) { - target = document.getElementById(domContainerID); - } else if (portalTarget !== null) { - target = portalTarget; - } - const Component: any = RootComponent; - if (componentName) { - Component.displayName = componentName; - } - - // 1st arg was: - // , - - // var theComponent =
the Component
; - const theComponent = ( - - - - ; - - - ); + const { props, portalTarget, styleSheetTarget } = inRenderObj; - ReactDOM.render( - // was { - document.addEventListener('SdkConstellationReady', () => { - // start the portal - sessionStorage.setItem('isLoggedIn', 'true'); - startPortal(); - }); - let localeOverride: any = sessionStorage.getItem('rsdk_locale'); - if (!localeOverride) { - localeOverride = undefined; - } + document.addEventListener('SdkConstellationReady', handleSdkConstellationReady); + + const locale: any = sessionStorage.getItem('rsdk_locale') || undefined; + const isLoggedIn = sessionStorage.getItem('isLoggedIn'); const redirected = sessionStorage.getItem('redirected'); if (isLoggedIn !== 'true' && redirected !== 'true') { @@ -193,16 +143,27 @@ export default function FullPortal() { appName: 'portal', mainRedirect: true, redirectDoneCB: doRedirectDone, - locale: localeOverride, - enableSemanticUrls: true + locale + // semanticUrls: true }); }, []); + const handleSdkConstellationReady = () => { + sessionStorage.setItem('isLoggedIn', 'true'); + // start the portal + startPortal(); + }; + return portalSelectionScreen ? ( ) : ( -
-
+
+ + + + {rootComponentProps && } + +
); }