|
| 1 | +import { Suspense } from "react"; |
| 2 | +import { useParams } from "react-router-dom"; |
| 3 | +import useFederatedComponent from "mf-cra"; |
| 4 | +import React from "react"; |
| 5 | +import Title from "../components/Title"; |
| 6 | +function RemoteApp({ app }) { |
| 7 | + // console.log("app ", app); |
| 8 | + const { Component: RemoteComponent } = useFederatedComponent(app); |
| 9 | + // console.log("RemoteComponent ", RemoteComponent); |
| 10 | + return ( |
| 11 | + <> |
| 12 | + <Title title={app.remoteName} /> |
| 13 | + <Suspense |
| 14 | + fallback={ |
| 15 | + <div style={{ height: "300px" }}> |
| 16 | + <div |
| 17 | + style={{ |
| 18 | + marginLeft: "45%", |
| 19 | + marginTop: "150px", |
| 20 | + fontSize: "45px", |
| 21 | + color: "#3dd3e0" |
| 22 | + }} |
| 23 | + className="loader-37" |
| 24 | + ></div> |
| 25 | + </div> |
| 26 | + } |
| 27 | + > |
| 28 | + <div |
| 29 | + style={{ |
| 30 | + boxShadow: "0 1px 3px 0 rgba(0, 0, 0, 0.33)", |
| 31 | + backgroundColor: "#ffffff", |
| 32 | + width: "100%", |
| 33 | + overflow: "hidden", |
| 34 | + borderRadius: 3, |
| 35 | + minHeight: "70vh" |
| 36 | + }} |
| 37 | + > |
| 38 | + {RemoteComponent && <RemoteComponent />} |
| 39 | + </div> |
| 40 | + </Suspense> |
| 41 | + </> |
| 42 | + ); |
| 43 | +} |
| 44 | +function checkObjectProperties(obj) { |
| 45 | + // Check if all three properties exist in the object |
| 46 | + if ( |
| 47 | + obj && |
| 48 | + obj.remoteName !== undefined && |
| 49 | + obj.remoteUrl !== undefined && |
| 50 | + obj.moduleToLoad !== undefined |
| 51 | + ) { |
| 52 | + return true; // All properties are present |
| 53 | + } else { |
| 54 | + return false; // At least one property is missing |
| 55 | + } |
| 56 | +} |
| 57 | +export default function RemoteAppContainer() { |
| 58 | + const { remoteApp } = useParams(); |
| 59 | + |
| 60 | + const obj = { |
| 61 | + remoteUrl: window.location.origin + "/mfbuild/remoteEntry.js", |
| 62 | + moduleToLoad: "./AppRoutes", |
| 63 | + remoteName: remoteApp |
| 64 | + }; |
| 65 | + // console.log("obj ", obj); |
| 66 | + const isMf = checkObjectProperties(obj); |
| 67 | + if (isMf) { |
| 68 | + const appToLoad = obj; |
| 69 | + return <RemoteApp app={appToLoad} />; |
| 70 | + } else { |
| 71 | + return ( |
| 72 | + <div className="flex items-center justify-center h-screen w-full bg-white rounded"> |
| 73 | + <div className="text-center"> |
| 74 | + <h1 className="text-[60px] lg:text-[120px] font-semibold text-black"> |
| 75 | + 404 |
| 76 | + </h1> |
| 77 | + <p className="text-[30px] lg:text-[50px] text-black"> |
| 78 | + Page Not Found |
| 79 | + </p> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + ); |
| 83 | + } |
| 84 | +} |
0 commit comments