All files / app/features/auth/jail Jail.tsx

0% Statements 0/41
0% Branches 0/15
0% Functions 0/5
0% Lines 0/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93                                                                                                                                                                                         
import { Backdrop } from "@material-ui/core";
import Alert from "components/Alert";
import CircularProgress from "components/CircularProgress";
import HtmlMeta from "components/HtmlMeta";
import PageTitle from "components/PageTitle";
import Redirect from "components/Redirect";
import TextBody from "components/TextBody";
import { useAuthContext } from "features/auth/AuthProvider";
import CommunityGuidelinesSection from "features/auth/jail/CommunityGuidelinesSection";
import LocationSection from "features/auth/jail/LocationSection";
import TOSSection from "features/auth/jail/TOSSection";
import { useTranslation } from "i18n";
import { AUTH } from "i18n/namespaces";
import { JailInfoRes } from "proto/jail_pb";
import React, { useEffect, useState } from "react";
import { loginRoute } from "routes";
import { service } from "service";
import makeStyles from "utils/makeStyles";
 
import ModNoteSection from "./ModNoteSection";
 
const useStyles = makeStyles((theme) => ({
  bottomMargin: { marginBottom: theme.spacing(4) },
  section: { marginBottom: theme.spacing(4) },
}));
 
export default function Jail() {
  const { t } = useTranslation(AUTH);
  const classes = useStyles(makeStyles);
 
  const { authState, authActions } = useAuthContext();
  const isJailed = authState.jailed;
  const authError = authState.error;
  const authLoading = authState.loading;
  const isAuthenticated = authState.authenticated;
 
  const [loading, setLoading] = useState(false);
  const [jailInfo, setJailInfo] = useState<null | JailInfoRes.AsObject>(null);
 
  useEffect(() => {
    (async () => {
      //just in case the store is stale
      authActions.updateJailStatus();
      setLoading(true);
      setJailInfo(await service.jail.getJailInfo());
      setLoading(false);
    })();
  }, [authActions]);
 
  const updateJailed = () => {
    authActions.updateJailStatus();
  };
 
  Iif (!isAuthenticated) return <Redirect to={loginRoute} />;
 
  return (
    <>
      {!isJailed && <Redirect to="/" />}
      <HtmlMeta title={t("jail.title")} />
      <PageTitle>{t("jail.title")}</PageTitle>
      {authError && <Alert severity="error">{authError}</Alert>}
      <TextBody className={classes.bottomMargin}>
        {t("jail.description")}
      </TextBody>
      <Backdrop open={loading || authLoading}>
        <CircularProgress />
      </Backdrop>
      {jailInfo?.hasNotAcceptedTos && (
        <TOSSection updateJailed={updateJailed} className={classes.section} />
      )}
      {jailInfo?.hasPendingModNotes && (
        <ModNoteSection
          updateJailed={updateJailed}
          pendingModNotes={jailInfo.pendingModNotesList}
          className={classes.section}
        />
      )}
      {jailInfo?.hasNotAcceptedCommunityGuidelines && (
        <CommunityGuidelinesSection
          updateJailed={updateJailed}
          className={classes.section}
        />
      )}
      {jailInfo?.hasNotAddedLocation && (
        <LocationSection
          updateJailed={updateJailed}
          className={classes.section}
        />
      )}
    </>
  );
}