fix(ui): call the health vs healthz based on tenants sate and login state

This commit is contained in:
Shekar Siri 2024-11-06 17:50:38 +01:00
parent c2405dfbb3
commit baebdcd8d2
4 changed files with 29 additions and 23 deletions

View file

@ -21,27 +21,32 @@ function PublicRoutes() {
const { userStore } = useStore(); const { userStore } = useStore();
const authDetails = userStore.authDetails; const authDetails = userStore.authDetails;
const isEnterprise = userStore.isEnterprise; const isEnterprise = userStore.isEnterprise;
const hideSupport = isEnterprise || location.pathname.includes('spots') || location.pathname.includes('view-spot') const hideSupport = isEnterprise || location.pathname.includes('spots') || location.pathname.includes('view-spot');
const [loading, setLoading] = React.useState(true);
useEffect(() => { useEffect(() => {
if (authDetails && !authDetails.tenants) { if (authDetails && !authDetails.tenants) {
void userStore.fetchTenants(); userStore.fetchTenants().then(() => setLoading(false));
} else {
setLoading(false);
} }
}, []); }, []);
return ( return (
<Suspense fallback={<Loader loading={true} className='flex-1' />}> <Loader loading={loading} className="flex-1">
<Switch> <Suspense fallback={<Loader loading={true} className="flex-1" />}>
<Route exact strict path={SPOT_PATH} component={Spot} /> <Switch>
<Route exact strict path={FORGOT_PASSWORD} component={ForgotPassword} /> <Route exact strict path={SPOT_PATH} component={Spot} />
<Route exact strict path={LOGIN_PATH} component={Login} /> <Route exact strict path={FORGOT_PASSWORD} component={ForgotPassword} />
<Route exact strict path={SIGNUP_PATH} component={Signup} /> <Route exact strict path={LOGIN_PATH} component={Login} />
<Redirect to={LOGIN_PATH} /> <Route exact strict path={SIGNUP_PATH} component={Signup} />
</Switch> <Redirect to={LOGIN_PATH} />
{!hideSupport && <SupportCallout />} </Switch>
</Suspense> {!hideSupport && <SupportCallout />}
</Suspense>
</Loader>
); );
} }
export default observer(PublicRoutes) export default observer(PublicRoutes);

View file

@ -163,6 +163,7 @@ const Router: React.FC<RouterProps> = (props) => {
}, [isSpotCb, isLoggedIn, localSpotJwt, isSignup]); }, [isSpotCb, isLoggedIn, localSpotJwt, isSignup]);
useEffect(() => { useEffect(() => {
if (!isLoggedIn) return
const fetchData = async () => { const fetchData = async () => {
if (siteId && siteId !== lastFetchedSiteIdRef.current) { if (siteId && siteId !== lastFetchedSiteIdRef.current) {
const activeSite = sites.find((s) => s.id == siteId); const activeSite = sites.find((s) => s.id == siteId);
@ -174,7 +175,7 @@ const Router: React.FC<RouterProps> = (props) => {
}; };
void fetchData(); void fetchData();
}, [siteId]); }, [siteId, isLoggedIn]);
const lastFetchedSiteIdRef = useRef<any>(null); const lastFetchedSiteIdRef = useRef<any>(null);

View file

@ -27,7 +27,6 @@ type SignupProps = RouteComponentProps;
const Signup: React.FC<SignupProps> = ({ history }) => { const Signup: React.FC<SignupProps> = ({ history }) => {
const { userStore } = useStore(); const { userStore } = useStore();
const authDetails = userStore.authDetails; const authDetails = userStore.authDetails;
const fetchTenants = userStore.fetchTenants;
const [healthModalPassed, setHealthModalPassed] = useState<boolean>(localStorage.getItem(healthStatusCheck_key) === 'true'); const [healthModalPassed, setHealthModalPassed] = useState<boolean>(localStorage.getItem(healthStatusCheck_key) === 'true');
const [healthStatusLoading, setHealthStatusLoading] = useState<boolean>(true); const [healthStatusLoading, setHealthStatusLoading] = useState<boolean>(true);
const [healthStatus, setHealthStatus] = useState<any>(null); const [healthStatus, setHealthStatus] = useState<any>(null);
@ -40,16 +39,17 @@ const Signup: React.FC<SignupProps> = ({ history }) => {
}; };
useEffect(() => { useEffect(() => {
if (!healthModalPassed) void getHealth(); if (!authDetails) return
}, []); if (authDetails) {
if (authDetails.tenants) {
useEffect(() => { history.push(LOGIN_ROUTE);
if (authDetails && authDetails.tenants) { } else {
history.push(LOGIN_ROUTE); void getHealth();
}
} }
}, [authDetails]); }, [authDetails]);
if (!healthModalPassed) { if (authDetails && !healthModalPassed && !authDetails.tenants) {
return ( return (
<HealthModal <HealthModal
setShowModal={() => null} setShowModal={() => null}

View file

@ -2,7 +2,7 @@ import BaseService from './BaseService';
export default class HealthService extends BaseService { export default class HealthService extends BaseService {
async fetchStatus(isPublic?: boolean): Promise<any> { async fetchStatus(isPublic?: boolean): Promise<any> {
const r = await this.client.get(isPublic ? '/healthz' : '/health'); const r = await this.client.get(isPublic ? '/health' : '/healthz');
const j = await r.json(); const j = await r.json();
return j.data || {}; return j.data || {};
} }