All files / lib/libs/email/content email-components.tsx

92.42% Statements 61/66
98.03% Branches 50/51
95.65% Functions 22/23
92.06% Lines 58/63

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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382                        30x                               30x     25x     198x   30x 1x                             30x 94x                         30x             26x                                           30x           6x                                                   30x 1x               30x         42x 21x                   21x               107x   96x 148x                                                 30x 86x   498x 86x                     52x                     412x                           30x             26x               30x                     42x                                                       30x 188x     30x 94x                           30x                       30x 27x 27x 27x   27x   27x 7x 7x     20x             30x 26x 26x     26x   26x 2x     24x   44x   44x 4x     4x     40x   44x                                                  
import { Column, Heading, Hr, Link, Row, Section, Text } from "@react-email/components";
import { Fragment, ReactNode } from "react";
import {
  Attachment,
  AttachmentKey,
  CommonEmailVariables,
  EmailAddresses,
  Events,
} from "shared-types";
import * as os from "shared-types/opensearch";
 
import { styles } from "./email-styles";
export const EMAIL_CONFIG = {
  DEV_EMAIL: "mako.stateuser+dev-to@gmail.com",
  CHIP_EMAIL: "CHIPSPASubmissionMailBox@cms.hhs.gov",
  SPA_EMAIL: "spa@cms.hhs.gov",
  SPAM_EMAIL: "SPAM@cms.hhs.gov",
} as const;
export interface EmailAddress {
  name: string;
  email: string;
}
 
interface AttachmentGroup {
  files?: Attachment[];
  label: string;
}
 
const areAllAttachmentsEmpty = (
  attachments: Partial<Record<string, { label: string; files?: any[] }>>,
): boolean => {
  return Object.values(attachments).every((att) => !att || !att.files || att.files.length === 0);
};
 
const Divider = () => <Hr style={styles.divider} />;
 
const Textarea = ({ children }: { children: React.ReactNode }) => (
  <Text
    style={{
      width: "100%",
      backgroundColor: "transparent",
      fontSize: "14px",
      lineHeight: "1.4",
      outline: "none",
      whiteSpace: "pre-line",
      wordWrap: "break-word",
    }}
  >
    {children}
  </Text>
);
 
const EmailNav = ({ appEndpointUrl }: { appEndpointUrl: string }) => (
  <Section style={styles.logo.container}>
    <Link href={appEndpointUrl} target="_blank" style={styles.logo.link}>
      <img
        height={40}
        width={112}
        style={{ maxWidth: "112px" }}
        src={`${appEndpointUrl}onemac-logo.png`}
        alt="OneMAC Logo"
      />
    </Link>
  </Section>
);
 
const LoginInstructions = ({
  appEndpointURL,
  useThisLink,
}: {
  appEndpointURL: string;
  useThisLink?: boolean;
}) => (
  <ul style={{ marginLeft: "-20px" }}>
    <li>
      <Text style={styles.text.description}>
        The submission can be accessed in the OneMAC application, which you can find at{" "}
        <Link href={appEndpointURL}>{useThisLink ? "this link" : appEndpointURL}</Link>.
      </Text>
    </li>
    <li>
      <Text style={styles.text.description}>
        If you are not already logged in, please click the "Login" link at the top of the page and
        log in using your Enterprise User Administration (EUA) credentials.
      </Text>
    </li>
    <li>
      <Text style={styles.text.description}>
        After you have logged in, you will be taken to the OneMAC application. The submission will
        be listed on the dashboard page, and you can view its details by clicking on its ID number.
      </Text>
    </li>
  </ul>
);
 
const SubDocHowToAccess = ({
  appEndpointURL,
}: {
  appEndpointURL: string;
  useThisLink?: boolean;
}) => (
  <>
    <Divider />
    <Text style={{ ...styles.text.base, fontWeight: "bold" }}>How to Access:</Text>
    <ul>
      <li>
        <Text style={styles.text.description}>
          These documents can be found in OneMAC through this link{" "}
          <Link href={appEndpointURL}>{appEndpointURL}</Link>.
        </Text>
      </li>
      <li>
        <Text style={styles.text.description}>
          If you are not already logged in, click “Login” at the top of the page and log in using
          your Enterprise User Administration (EUA) credentials.
        </Text>
      </li>
 
      <li>
        <Text style={styles.text.description}>
          After you logged in, click the submission ID number on the dashboard page to view details.
        </Text>
      </li>
    </ul>
  </>
);
 
const DetailsHeading = () => (
  <div>
    <Divider />
    <Heading as="h2" style={styles.heading.h2}>
      Details:
    </Heading>
  </div>
);
 
const Attachments = ({
  attachments,
}: {
  attachments: Partial<Record<AttachmentKey, AttachmentGroup>>;
}) => {
  if (!attachments || areAllAttachmentsEmpty(attachments)) {
    return (
      <>
        <Heading as="h2" style={styles.heading.h2}>
          Files:
        </Heading>
        <Text>No attachments</Text>
      </>
    );
  }
 
  return (
    <>
      <Divider />
      <Heading as="h2" style={styles.heading.h2}>
        Files:
      </Heading>
 
      {Object.entries(attachments).map(([key, group]) => {
        if (!group?.files?.length) return null;
 
        return group.files.map((file, index) => (
          <Row key={key} style={{ marginBottom: "2px", marginTop: "2px" }}>
            <Column
              align="left"
              style={{
                width: "50%",
                verticalAlign: "top",
              }}
            >
              {" "}
              <span key={group.label + index}>
                <Text style={{ ...styles.text.title }}>{group.label}:</Text>{" "}
              </span>
            </Column>
            <Column style={{ verticalAlign: "top" }}>
              <Text style={styles.text.description}>
                <span key={file.filename + index}>{file.filename}</span>
              </Text>
            </Column>
          </Row>
        ));
      })}
    </>
  );
};
 
const PackageDetails = ({ details }: { details: Record<string, ReactNode> }) => (
  <Section>
    {Object.entries(details).map(([label, value], index) => {
      if (label === "Summary") {
        return (
          <Row key={label + index}>
            <Divider />
            <Text style={{ margin: ".5em" }}>
              <Heading as="h2" style={styles.heading.h2}>
                Summary:
              </Heading>
            </Text>
            <Text style={styles.text.base}>
              {typeof value === "string" && value.trim()
                ? value.split("\n").map((line, index, array) => (
                    <Fragment key={index}>
                      {line}
                      {index !== array.length - 1 && <br />}
                    </Fragment>
                  ))
                : "No additional information submitted"}
            </Text>
          </Row>
        );
      }
 
      return (
        <Row key={label + index}>
          <Column align="left" style={{ width: "50%" }}>
            <Text style={styles.text.title}>{label}:</Text>
          </Column>
          <Column>
            <Text style={styles.text.description}>{value ?? "Not provided"}</Text>
          </Column>
        </Row>
      );
    })}
  </Section>
);
 
const MailboxNotice = ({
  type,
  onWaivers = true,
}: {
  type: "SPA" | "Waiver";
  onWaivers?: boolean;
}) => (
  <Text style={{ ...styles.text.description, marginTop: "16px", marginBottom: "16px" }}>
    {type === "SPA"
      ? "This mailbox is for the submittal of State Plan Amendments and non-web based responses to Requests for Additional Information (RAI) on submitted SPAs only."
      : `This mailbox is for the submittal of Section 1915(b) and 1915(c) Waivers, responses to Requests for Additional Information (RAI)${onWaivers ? " on Waivers" : ""}, and extension requests on Waivers only.`}
    {" Any other correspondence will be disregarded."}
  </Text>
);
 
const FollowUpNotice = ({
  isChip,
  includeStateLead = true,
  includeDidNotExpect = true,
  withDivider = true,
}: {
  isChip?: boolean;
  includeStateLead?: boolean;
  includeDidNotExpect?: boolean;
  withDivider?: boolean;
}) => (
  <>
    {withDivider && <Divider />}
    {isChip ? (
      <Section>
        <Text style={{ marginTop: "8px", fontSize: "14px" }}>
          {`If you have any question${
            includeDidNotExpect ? " or did not expect this email" : ""
          }, please contact `}
          <Link href={`mailto:${EMAIL_CONFIG.CHIP_EMAIL}`} style={{ textDecoration: "underline" }}>
            {EMAIL_CONFIG.CHIP_EMAIL}
          </Link>
          {includeStateLead ? " or your state lead." : "."}
        </Text>
      </Section>
    ) : (
      <Section>
        <Text style={{ marginTop: "8px", fontSize: "14px" }}>
          {`If you have any questions, please contact `}
          <Link href={`mailto:${EMAIL_CONFIG.SPA_EMAIL}`} style={{ textDecoration: "underline" }}>
            {EMAIL_CONFIG.SPA_EMAIL}
          </Link>
          {includeStateLead ? " or your state lead." : "."}
        </Text>
      </Section>
    )}
  </>
);
 
const EmailFooter = ({ children }: { children: React.ReactNode }) => (
  <Section style={styles.section.footer}>{children}</Section>
);
 
const BasicFooter = () => (
  <EmailFooter>
    <Text style={{ ...styles.text.footer, margin: "8px" }}>
      U.S. Centers for Medicare & Medicaid Services
    </Text>
    <Text style={{ ...styles.text.footer, margin: "8px" }}>
      © {new Date().getFullYear()} | 7500 Security Boulevard, Baltimore, MD 21244
    </Text>
  </EmailFooter>
);
 
export interface WithdrawRAIProps {
  variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses };
}
 
const WithdrawRAI: React.FC<WithdrawRAIProps> = ({ variables }) => {
  return (
    <Section>
      <Text>
        The OneMAC Submission Portal received a request to withdraw the Formal RAI Response. You are
        are receiving this email notification as the Formal RAI for {variables.id} was withdrawn by{" "}
        {variables.submitterName} {variables.submitterEmail}.
      </Text>
    </Section>
  );
};
 
const getCpocEmail = (item?: os.main.ItemResult): string[] => {
  try {
    const email = item?._source?.leadAnalystEmail;
    const name = item?._source?.leadAnalystName;
 
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
 
    if (!email || !emailRegex.test(email)) {
      console.error(`Invalid or missing email for item: ${JSON.stringify(item?._source, null, 2)}`);
      return [];
    }
 
    return [`${name} <${email}>`];
  } catch (e) {
    console.error("Error getting CPOC email", e);
    return [];
  }
};
 
const getSrtEmails = (item?: os.main.ItemResult): string[] => {
  try {
    const reviewTeam = item?._source?.reviewTeam;
 
    // Email validation regex
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
 
    if (!reviewTeam || reviewTeam.length === 0) {
      return [];
    }
 
    return reviewTeam
      .map((reviewer: { name: string; email: string }) => {
        const { name, email } = reviewer;
 
        if (!email || !emailRegex.test(email)) {
          console.error(
            `Invalid or missing email for reviewer: ${JSON.stringify(reviewer, null, 2)}`,
          );
          return null;
        }
 
        return `${name} <${email}>`;
      })
      .filter((email): email is string => email !== null);
  } catch (e) {
    console.error("Error getting SRT emails", e);
    return [];
  }
};
 
export {
  Textarea,
  EmailNav,
  LoginInstructions,
  SubDocHowToAccess,
  DetailsHeading,
  Divider,
  Attachments,
  PackageDetails,
  MailboxNotice,
  FollowUpNotice,
  BasicFooter,
  WithdrawRAI,
  EmailFooter,
  getCpocEmail,
  getSrtEmails,
  areAllAttachmentsEmpty,
};