Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4.8.10] Fixed Loader Position on Sign-In #441

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harperdb-studio",
"version": "4.8.9",
"version": "4.8.10",
"description": "A UI for HarperDB",
"deploymentUrl": "studio.harperdb.io",
"private": true,
Expand Down
334 changes: 168 additions & 166 deletions src/components/layouts/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,176 +45,178 @@ const versionAlertOptions = { timeout: 0, position: positions.BOTTOM_CENTER };
let controller;

function ValidatedRoute(auth) {
// ensure org id is valid for user. if not, redirect to organizations
const { customer_id } = useParams();
// ensure org id is valid for user. if not, redirect to organizations
const { customer_id } = useParams();

if (auth.auth.orgs.some((o) => o.customer_id === customer_id)) {
return <Outlet />;
}
return <Navigate to="/organization" replace />;
if (auth.auth.orgs.some((o) => o.customer_id === customer_id)) {
return <Outlet />;
}
return <Navigate to="/organization" replace />;
}

function App() {
const canonicalUrl = document.querySelector('link[rel="canonical"]');
const navigate = useNavigate();
const alert = useAlert();
const location = useLocation();
const { search, pathname } = location;
const { redirect } = queryString.parse(search);
const auth = useStoreState(appState, (s) => s.auth);
const theme = useStoreState(appState, (s) => s.theme);
const products = useStoreState(appState, (s) => s.products);
const regions = useStoreState(appState, (s) => s.regions);
const wavelengthRegions = useStoreState(appState, (s) => s.wavelengthRegions);
const akamaiRegions = useStoreState(appState, (s) => s.akamaiRegions);
const version = useStoreState(appState, (s) => s.version);
const [fetchingUser, setFetchingUser] = useState(true);
const [showVersionAlert, setShowVersionAlert] = useState(false);
const [persistedUser, setPersistedUser] = usePersistedUser({});
const loggedIn = auth?.user_id;
const isNotEmployee = loggedIn && auth?.email.indexOf('harperdb.io') === -1 && auth?.email.indexOf('deliciousmonster.com') === -1;
const isMaintenance = version?.maintenance && isNotEmployee;

ReactGA.initialize(config.google_analytics_code);

useEffect(() => {
ReactGA.send({ hitType: 'pageview', page: window.location.pathname + window.location.search });
}, [location.pathname]);

useEffect(() => {
changeFavIcon(persistedUser?.theme);
}, [persistedUser?.theme]);

useEffect(() => {
setShowVersionAlert(checkVersion({ apiVersion: version.studio }));
}, [version.studio]);

useEffect(() => {
if (auth?.email) {
if (window._kmq) {
window._kmq.push(['identify', auth.email]);
}
if (auth?.update_password) {
navigate('/update-password');
}
if (redirect) {
navigate(redirect);
}
}
// eslint-disable-next-line
}, [auth?.email]);

useEffect(() => {
if (showVersionAlert) alert.info(`HarperDB Studio v${showVersionAlert} is now available. Refresh to update.`, versionAlertOptions);
// eslint-disable-next-line
}, [showVersionAlert]);

useEffect(() => {
canonicalUrl.href = window.location.href;
}, [location, canonicalUrl]);

useEffect(() => {
init({ currentPath: location.pathname, navigate, persistedUser, setPersistedUser, setFetchingUser, controller });
// eslint-disable-next-line
}, []);

useInterval(() => {
if (!products) getProducts();
if (!regions) getRegions();
if (!wavelengthRegions) getWavelengthRegions();
if (!akamaiRegions) getAkamaiRegions();
}, config.refresh_content_interval);

useInterval(() => {
getCurrentVersion();
refreshUser({ auth, controller });
}, config.check_version_interval);

return (
<div className={`${theme} ${config.maintenance ? 'maintenance' : ''}`}>
<Suspense fallback={<Loader header=" " spinner />}>
<TopNav isMaintenance={isMaintenance} loggedIn={loggedIn} />
</Suspense>
{fetchingUser ? (
<Loader header="signing in" spinner />
) : loggedIn ? (
<main id="app-container">
<ErrorBoundary FallbackComponent={ErrorFallback}>
<Suspense fallback={
<div className="auth-centered-container">
<Loader header=" " spinner />
</div>
}>
{/* can we put instance routes in here, each in a suspense tag (since they're lazily loaded) */}
<Routes>
<Route element={isMaintenance ? <Maintenance /> : <UpdatePassword />} path="/update-password" />
<Route element={isMaintenance ? <Maintenance /> : <Profile />} path="/profile/*" />
<Route element={isMaintenance ? <Maintenance /> : <ValidatedRoute auth={auth} />}>
<Route element={<Instance />} path="/o/:customer_id/i/:compute_stack_id/*" />
<Route element={<Instances />} path="/o/:customer_id/instances/:action?/:purchaseStep?" />
<Route element={<Organization />} path="/o/:customer_id/*" />
</Route>
<Route element={isMaintenance ? <Maintenance /> : <Organizations />} path="/:list?/:action?" />
<Route element={<Navigate to="/" replace />} />
</Routes>
</Suspense>
</ErrorBoundary>
</main>
) : (
<main className="auth-container">
<ErrorBoundary FallbackComponent={ErrorFallbackAuth}>
<Suspense fallback={<Loader header=" " spinner />}>
<Container fluid="xs" className="h-100">
<Row xs="1" sm="2" className="h-100">
<Col className="p-5 auth-studio-info d-none d-sm-flex justify-content-center align-items-center">
<div className='auth-studio-info-container'>
<h1 className="auth-title">HarperDB Studio</h1>
<span className="mb-4 auth-subtitle d-inline-block">Manage all your HarperDB instances.</span>
<ul className="auth-info-list-items">
<li>
<h3 className="item-title">Manage All Instances</h3>
<span className="item-subtitle">Set access, cluster, monitor, and more.</span>
</li>
<li>
<h3 className="item-title">Embedded API Server</h3>
<span className="item-subtitle">HarperDB components give you unlimited application flexibility.</span>
</li>
<li>
<h3 className="item-title">Fully Managed Cloud & 5G Instances</h3>
<span className="item-subtitle">Go from zero to code in minutes.</span>
</li>
<li>
<h3 className="item-title">Deploy Anywhere</h3>
<div className="mt-3">
<a href="https://hub.docker.com/r/harperdb/harperdb" target="_blank" rel="noreferrer" className="deploy-subitem">Docker</a>
<a href="https://www.npmjs.com/package/harperdb" target="_blank" rel="noreferrer" className="deploy-subitem">npm</a>
<a href="https://docs.harperdb.io/docs/deployments/install-harperdb" target="_blank" rel="noreferrer" className="deploy-subitem">all options</a>
</div>
</li>
</ul>
</div>
</Col>
<Col className="p-5 d-flex justify-content-center align-items-center auth-form-container">
<Routes>
<Route element={<SignIn />} path="/" />
<Route element={config.maintenance ? <Maintenance /> : <SignUp />} path="/sign-up" />
<Route element={isMaintenance ? <Maintenance /> : <ResetPassword />} path="/reset-password" />
<Route path="*" element={<Navigate to={`/?redirect=${pathname}${search}`} replace />} />
</Routes>
</Col>
</Row>
</Container>
</Suspense>
</ErrorBoundary>
</main>
)}
<div id="app-bg-color" />
<div className="version">
HarperDB Studio v{config.studio_version}
{version.maintenance && ' - MAINTENANCE MODE'}
</div>
</div>
);
const canonicalUrl = document.querySelector('link[rel="canonical"]');
const navigate = useNavigate();
const alert = useAlert();
const location = useLocation();
const { search, pathname } = location;
const { redirect } = queryString.parse(search);
const auth = useStoreState(appState, (s) => s.auth);
const theme = useStoreState(appState, (s) => s.theme);
const products = useStoreState(appState, (s) => s.products);
const regions = useStoreState(appState, (s) => s.regions);
const wavelengthRegions = useStoreState(appState, (s) => s.wavelengthRegions);
const akamaiRegions = useStoreState(appState, (s) => s.akamaiRegions);
const version = useStoreState(appState, (s) => s.version);
const [fetchingUser, setFetchingUser] = useState(true);
const [showVersionAlert, setShowVersionAlert] = useState(false);
const [persistedUser, setPersistedUser] = usePersistedUser({});
const loggedIn = auth?.user_id;
const isNotEmployee = loggedIn && auth?.email.indexOf('harperdb.io') === -1 && auth?.email.indexOf('deliciousmonster.com') === -1;
const isMaintenance = version?.maintenance && isNotEmployee;

ReactGA.initialize(config.google_analytics_code);

useEffect(() => {
ReactGA.send({ hitType: 'pageview', page: window.location.pathname + window.location.search });
}, [location.pathname]);

useEffect(() => {
changeFavIcon(persistedUser?.theme);
}, [persistedUser?.theme]);

useEffect(() => {
setShowVersionAlert(checkVersion({ apiVersion: version.studio }));
}, [version.studio]);

useEffect(() => {
if (auth?.email) {
if (window._kmq) {
window._kmq.push(['identify', auth.email]);
}
if (auth?.update_password) {
navigate('/update-password');
}
if (redirect) {
navigate(redirect);
}
}
// eslint-disable-next-line
}, [auth?.email]);

useEffect(() => {
if (showVersionAlert) alert.info(`HarperDB Studio v${showVersionAlert} is now available. Refresh to update.`, versionAlertOptions);
// eslint-disable-next-line
}, [showVersionAlert]);

useEffect(() => {
canonicalUrl.href = window.location.href;
}, [location, canonicalUrl]);

useEffect(() => {
init({ currentPath: location.pathname, navigate, persistedUser, setPersistedUser, setFetchingUser, controller });
// eslint-disable-next-line
}, []);

useInterval(() => {
if (!products) getProducts();
if (!regions) getRegions();
if (!wavelengthRegions) getWavelengthRegions();
if (!akamaiRegions) getAkamaiRegions();
}, config.refresh_content_interval);

useInterval(() => {
getCurrentVersion();
refreshUser({ auth, controller });
}, config.check_version_interval);

return (
<div className={`${theme} ${config.maintenance ? 'maintenance' : ''}`}>
<Suspense fallback={<Loader header=" " spinner />}>
<TopNav isMaintenance={isMaintenance} loggedIn={loggedIn} />
</Suspense>
{fetchingUser ? (
<div className="vh-100">
<Loader header="signing in" spinner />
</div>
) : loggedIn ? (
<main id="app-container">
<ErrorBoundary FallbackComponent={ErrorFallback}>
<Suspense fallback={
<div className="auth-centered-container">
<Loader header=" " spinner />
</div>
}>
{/* can we put instance routes in here, each in a suspense tag (since they're lazily loaded) */}
<Routes>
<Route element={isMaintenance ? <Maintenance /> : <UpdatePassword />} path="/update-password" />
<Route element={isMaintenance ? <Maintenance /> : <Profile />} path="/profile/*" />
<Route element={isMaintenance ? <Maintenance /> : <ValidatedRoute auth={auth} />}>
<Route element={<Instance />} path="/o/:customer_id/i/:compute_stack_id/*" />
<Route element={<Instances />} path="/o/:customer_id/instances/:action?/:purchaseStep?" />
<Route element={<Organization />} path="/o/:customer_id/*" />
</Route>
<Route element={isMaintenance ? <Maintenance /> : <Organizations />} path="/:list?/:action?" />
<Route element={<Navigate to="/" replace />} />
</Routes>
</Suspense>
</ErrorBoundary>
</main>
) : (
<main className="auth-container">
<ErrorBoundary FallbackComponent={ErrorFallbackAuth}>
<Suspense fallback={<Loader header=" " spinner />}>
<Container fluid="xs" className="h-100">
<Row xs="1" sm="2" className="h-100">
<Col className="p-5 auth-studio-info d-none d-sm-flex justify-content-center align-items-center">
<div className='auth-studio-info-container'>
<h1 className="auth-title">HarperDB Studio</h1>
<span className="mb-4 auth-subtitle d-inline-block">Manage all your HarperDB instances.</span>
<ul className="auth-info-list-items">
<li>
<h3 className="item-title">Manage All Instances</h3>
<span className="item-subtitle">Set access, cluster, monitor, and more.</span>
</li>
<li>
<h3 className="item-title">Embedded API Server</h3>
<span className="item-subtitle">HarperDB components give you unlimited application flexibility.</span>
</li>
<li>
<h3 className="item-title">Fully Managed Cloud & 5G Instances</h3>
<span className="item-subtitle">Go from zero to code in minutes.</span>
</li>
<li>
<h3 className="item-title">Deploy Anywhere</h3>
<div className="mt-3">
<a href="https://hub.docker.com/r/harperdb/harperdb" target="_blank" rel="noreferrer" className="deploy-subitem">Docker</a>
<a href="https://www.npmjs.com/package/harperdb" target="_blank" rel="noreferrer" className="deploy-subitem">npm</a>
<a href="https://docs.harperdb.io/docs/deployments/install-harperdb" target="_blank" rel="noreferrer" className="deploy-subitem">all options</a>
</div>
</li>
</ul>
</div>
</Col>
<Col className="p-5 d-flex justify-content-center align-items-center auth-form-container">
<Routes>
<Route element={<SignIn />} path="/" />
<Route element={config.maintenance ? <Maintenance /> : <SignUp />} path="/sign-up" />
<Route element={isMaintenance ? <Maintenance /> : <ResetPassword />} path="/reset-password" />
<Route path="*" element={<Navigate to={`/?redirect=${pathname}${search}`} replace />} />
</Routes>
</Col>
</Row>
</Container>
</Suspense>
</ErrorBoundary>
</main>
)}
<div id="app-bg-color" />
<div className="version">
HarperDB Studio v{config.studio_version}
{version.maintenance && ' - MAINTENANCE MODE'}
</div>
</div>
);
}

export default App;