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 authDetails = userStore.authDetails;
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(() => {
if (authDetails && !authDetails.tenants) {
void userStore.fetchTenants();
userStore.fetchTenants().then(() => setLoading(false));
} else {
setLoading(false);
}
}, []);
return (
<Suspense fallback={<Loader loading={true} className='flex-1' />}>
<Switch>
<Route exact strict path={SPOT_PATH} component={Spot} />
<Route exact strict path={FORGOT_PASSWORD} component={ForgotPassword} />
<Route exact strict path={LOGIN_PATH} component={Login} />
<Route exact strict path={SIGNUP_PATH} component={Signup} />
<Redirect to={LOGIN_PATH} />
</Switch>
{!hideSupport && <SupportCallout />}
</Suspense>
<Loader loading={loading} className="flex-1">
<Suspense fallback={<Loader loading={true} className="flex-1" />}>
<Switch>
<Route exact strict path={SPOT_PATH} component={Spot} />
<Route exact strict path={FORGOT_PASSWORD} component={ForgotPassword} />
<Route exact strict path={LOGIN_PATH} component={Login} />
<Route exact strict path={SIGNUP_PATH} component={Signup} />
<Redirect to={LOGIN_PATH} />
</Switch>
{!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]);
useEffect(() => {
if (!isLoggedIn) return
const fetchData = async () => {
if (siteId && siteId !== lastFetchedSiteIdRef.current) {
const activeSite = sites.find((s) => s.id == siteId);
@ -174,7 +175,7 @@ const Router: React.FC<RouterProps> = (props) => {
};
void fetchData();
}, [siteId]);
}, [siteId, isLoggedIn]);
const lastFetchedSiteIdRef = useRef<any>(null);

View file

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

View file

@ -2,7 +2,7 @@ import BaseService from './BaseService';
export default class HealthService extends BaseService {
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();
return j.data || {};
}