All files / app/features/dashboard ReminderItem.tsx

100% Statements 44/44
70.37% Branches 19/27
100% Functions 2/2
100% Lines 44/44

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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 1412x 2x 2x 2x 2x 2x 2x 2x   2x             2x   2x   23x             15x   15x             15x 4x 4x 4x 4x 4x 4x 11x   1x 1x 1x           1x 1x         10x 1x 1x 1x 1x 9x 6x 6x 6x 6x 3x 2x 2x 2x 2x   1x         14x                                                                                                                        
import { alpha, Box, Typography } from "@mui/material";
import { useMediaQuery } from "@mui/system";
import Button from "components/Button";
import IconButton from "components/IconButton";
import { CloseIcon } from "components/Icons";
import { useTranslation } from "i18n";
import { DASHBOARD } from "i18n/namespaces";
import Link from "next/link";
import { Reminder } from "proto/account_pb";
import { ReferenceType } from "proto/references_pb";
import {
  referenceTypeRoute,
  routeToEditProfile,
  routeToHostRequest,
  routeToLeaveReference,
  strongVerificationRoute,
} from "routes";
 
import { theme } from "../../theme";
 
export default function ReminderItem({
  reminder,
  onDismiss,
}: {
  reminder: Reminder.AsObject;
  onDismiss?: () => void;
}) {
  const { t } = useTranslation([DASHBOARD]);
 
  const isMobile = useMediaQuery(theme.breakpoints.down("md"));
 
  let title: string;
  let description: string;
  let buttonText: string;
  let href: string;
 
  if (reminder.respondToHostRequestReminder) {
    const { hostRequestId, surferUser } = reminder.respondToHostRequestReminder;
    const name = surferUser?.name ?? "";
    title = t("reminder.respond_to_host_request.title", { name });
    description = t("reminder.respond_to_host_request.description", { name });
    buttonText = t("reminder.respond_to_host_request.button");
    href = routeToHostRequest(hostRequestId);
  } else if (reminder.writeReferenceReminder?.otherUser) {
    const { hostRequestId, otherUser, referenceType } =
      reminder.writeReferenceReminder;
    title = t("reminder.write_reference.title");
    description = t(
      referenceType === ReferenceType.REFERENCE_TYPE_SURFED
        ? "reminder.write_reference.description_surfed"
        : "reminder.write_reference.description_hosted",
      { name: otherUser.name },
    );
    buttonText = t("reminder.write_reference.button");
    href = routeToLeaveReference(
      referenceTypeRoute[referenceType],
      otherUser.userId,
      hostRequestId,
    );
  } else if (reminder.completeMyHomeReminder) {
    title = t("reminder.complete_my_home.title");
    description = t("reminder.complete_my_home.description");
    buttonText = t("reminder.complete_my_home.button");
    href = routeToEditProfile("home");
  } else if (reminder.completeProfileReminder) {
    title = t("reminder.complete_profile.title");
    description = t("reminder.complete_profile.description");
    buttonText = t("reminder.complete_profile.button");
    href = routeToEditProfile();
  } else if (reminder.completeVerificationReminder) {
    title = t("reminder.strong_verification.title");
    description = t("reminder.strong_verification.description");
    buttonText = t("reminder.strong_verification.button");
    href = strongVerificationRoute;
  } else {
    return null;
  }
 
  return (
    <Box
      sx={(theme) => ({
        backgroundColor: alpha(theme.palette.secondary.main, 0.08),
        padding: isMobile ? "14px" : "24px",
        display: "flex",
        flexDirection: "column",
        height: "100%",
      })}
    >
      <Box
        sx={{
          display: "flex",
          justifyContent: "space-between",
          alignItems: "flex-start",
          marginBottom: isMobile ? "8px" : "16px",
        }}
      >
        <Typography
          variant={isMobile ? "h4" : "h3"}
          sx={{ fontWeight: 800, flexGrow: 1 }}
        >
          {title}
        </Typography>
        {onDismiss && (
          <IconButton
            aria-label={t("reminder.carousel_dismiss_button_a11y")}
            onClick={onDismiss}
            size="small"
            sx={{ marginTop: "-4px", marginRight: "-4px", flexShrink: 0 }}
          >
            <CloseIcon />
          </IconButton>
        )}
      </Box>
 
      <Typography
        sx={{
          flexGrow: 1,
          marginBottom: isMobile ? "10px" : "18px",
          fontSize: isMobile ? ".75rem" : ".85rem",
        }}
      >
        {description}
      </Typography>
 
      <Button
        component={Link}
        href={href}
        fullWidth
        variant="contained"
        size={isMobile ? "small" : "medium"}
        sx={{
          fontWeight: 700,
          borderRadius: "8px",
        }}
      >
        {buttonText}
      </Button>
    </Box>
  );
}