also check if user is able to load extensions as well as if they loaded so guest forms can work

This commit is contained in:
jasquat 2024-02-09 10:21:23 -05:00
parent 4983d48f22
commit 7a62a8688c
No known key found for this signature in database
2 changed files with 18 additions and 3 deletions

View File

@ -25,6 +25,9 @@ export default function ContainerForExtensions() {
const [extensionUxElements, setExtensionNavigationItems] = useState< const [extensionUxElements, setExtensionNavigationItems] = useState<
UiSchemaUxElement[] | null UiSchemaUxElement[] | null
>(null); >(null);
const [canLoadExtensions, setCanLoadExtensions] = useState<boolean | null>(
null
);
let contentClassName = 'main-site-body-centered'; let contentClassName = 'main-site-body-centered';
if (window.location.pathname.startsWith('/editor/')) { if (window.location.pathname.startsWith('/editor/')) {
@ -77,10 +80,13 @@ export default function ContainerForExtensions() {
return; return;
} }
if (ability.can('GET', targetUris.extensionListPath)) { if (ability.can('GET', targetUris.extensionListPath)) {
setCanLoadExtensions(true);
HttpService.makeCallToBackend({ HttpService.makeCallToBackend({
path: targetUris.extensionListPath, path: targetUris.extensionListPath,
successCallback: processExtensionResult, successCallback: processExtensionResult,
}); });
} else {
setCanLoadExtensions(false);
} }
}; };
@ -101,7 +107,12 @@ export default function ContainerForExtensions() {
<Routes> <Routes>
<Route <Route
path="/*" path="/*"
element={<BaseRoutes extensionUxElements={extensionUxElements} />} element={
<BaseRoutes
extensionUxElements={extensionUxElements}
canLoadExtensions={canLoadExtensions}
/>
}
/> />
<Route path="/editor/*" element={<EditorRoutes />} /> <Route path="/editor/*" element={<EditorRoutes />} />
<Route path="/extensions/:page_identifier" element={<Extension />} /> <Route path="/extensions/:page_identifier" element={<Extension />} />

View File

@ -19,10 +19,14 @@ import { ExtensionUxElementMap } from '../components/ExtensionUxElementForDispla
import Extension from './Extension'; import Extension from './Extension';
type OwnProps = { type OwnProps = {
canLoadExtensions: boolean | null;
extensionUxElements?: UiSchemaUxElement[] | null; extensionUxElements?: UiSchemaUxElement[] | null;
}; };
export default function BaseRoutes({ extensionUxElements }: OwnProps) { export default function BaseRoutes({
canLoadExtensions,
extensionUxElements,
}: OwnProps) {
const elementCallback = (uxElement: UiSchemaUxElement) => { const elementCallback = (uxElement: UiSchemaUxElement) => {
return ( return (
<Route <Route
@ -32,7 +36,7 @@ export default function BaseRoutes({ extensionUxElements }: OwnProps) {
); );
}; };
if (extensionUxElements) { if (extensionUxElements || canLoadExtensions === false) {
const extensionRoutes = ExtensionUxElementMap({ const extensionRoutes = ExtensionUxElementMap({
displayLocation: 'routes', displayLocation: 'routes',
elementCallback, elementCallback,