All files / app/features/messages/requests HostRequestStatusIcon.tsx

52.63% Statements 10/19
23.07% Branches 3/13
100% Functions 1/1
52.63% Lines 10/19

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 472x 2x 2x 2x 2x                   2x 3x 3x   3x   3x                                                    
import { Avatar, AvatarProps } from "@mui/material";
import { CheckIcon, CrossIcon, QuestionIcon } from "components/Icons";
import { HostRequestStatus } from "proto/messages_pb";
import React from "react";
import { theme } from "theme";
 
interface HostRequestStatusIconProps extends AvatarProps {
  status: HostRequestStatus;
  // For public-trip offers, an accepted offer is a positive terminal state for
  // the traveller, so it's shown green rather than the neutral gray of a normal
  // accepted request that's still awaiting confirmation.
  isOffer?: boolean;
}
 
export default function HostRequestStatusIcon({ status: s, isOffer = false, ...props }: HostRequestStatusIconProps) {
  let icon = null;
  let color = null;
 
  if (s === HostRequestStatus.HOST_REQUEST_STATUS_ACCEPTED) {
    icon = <CheckIcon fontSize="inherit" />;
    color = isOffer ? "green" : "gray";
  } else Eif (s === HostRequestStatus.HOST_REQUEST_STATUS_REJECTED) {
    icon = <CrossIcon fontSize="inherit" />;
    color = "red";
  } else if (s === HostRequestStatus.HOST_REQUEST_STATUS_PENDING) {
    icon = <QuestionIcon fontSize="inherit" />;
    color = "gray";
  } else if (s === HostRequestStatus.HOST_REQUEST_STATUS_CANCELLED) {
    icon = <CrossIcon fontSize="inherit" />;
    color = "gray";
  } else if (s === HostRequestStatus.HOST_REQUEST_STATUS_CONFIRMED) {
    icon = <CheckIcon fontSize="inherit" />;
    color = "green";
  } else throw new Error(`Unhandled host request case: ${s}`);
 
  return (
    <Avatar
      {...props}
      style={{ backgroundColor: color }}
      sizes=" "
      sx={{ fontSize: theme.typography.pxToRem(16), height: 18, width: 18 }}
    >
      {icon}
    </Avatar>
  );
}