All files / app/features/auth/notifications PushNotificationDenied.tsx

76.47% Statements 26/34
41.66% Branches 5/12
100% Functions 5/5
75.75% Lines 25/33

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 911x 1x 1x 1x   1x             1x 2x 2x 2x     2x 4x     2x 2x         2x       2x       2x           2x         2x 2x           2x       2x       2x 2x                   2x                               1x  
import Alert from "components/Alert";
import { useTranslation } from "i18n";
import { AUTH } from "i18n/namespaces";
import makeStyles from "utils/makeStyles";
 
const useStyles = makeStyles((theme) => ({
  alert: {
    marginBottom: theme.spacing(3),
    marginTop: theme.spacing(2),
  },
}));
 
const PushNotificationDenied = () => {
  const { t } = useTranslation(AUTH);
  const userAgent = navigator.userAgent.toLowerCase();
  const classes = useStyles();
 
  // @TODO - Add mobile browser and OS instructions per platform
  const isMobile = () => {
    return /android|iphone|ipad/i.test(userAgent);
  };
 
  const getBrowserInstructions = () => {
    Iif (isMobile()) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.mobile.browser"
      );
    }
    Iif (userAgent.includes("chrome")) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.chrome"
      );
    } else Iif (userAgent.includes("firefox")) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.firefox"
      );
    } else Iif (userAgent.includes("safari")) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.safari"
      );
    }
 
    return t(
      "notification_settings.push_notifications.permission_denied.instructions.generic"
    );
  };
 
  const getOSInstructions = () => {
    Iif (isMobile()) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.mobile.os"
      );
    }
 
    Iif (userAgent.includes("mac")) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.macos"
      );
    } else Iif (userAgent.includes("windows")) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.windows"
      );
    } else if (userAgent.includes("linux")) {
      return t(
        "notification_settings.push_notifications.permission_denied.instructions.linux.gnome"
      );
    }
 
    return t(
      "notification_settings.push_notifications.permission_denied.instructions.generic"
    );
  };
 
  return (
    <>
      <Alert className={classes.alert} severity="error">
        {getBrowserInstructions()}
      </Alert>
      <Alert className={classes.alert} severity="error">
        {t(
          "notification_settings.push_notifications.permission_denied.platform_settings_description"
        ) +
          " " +
          getOSInstructions()}
      </Alert>
    </>
  );
};
 
export default PushNotificationDenied;