department-of-veterans-affairs/vets-website

View on GitHub
src/applications/mhv-supply-reordering/containers/Alerts.jsx

Summary

Maintainability
A
2 hrs
Test Coverage
import React from 'react';
import { useSelector } from 'react-redux';

import {
  AlertDeceased,
  AlertNoRecordForUser,
  AlertNoSuppliesForReorder,
  AlertReorderAccessExpired,
  AlertSomethingWentWrong,
} from '../components/alerts';

import {
  canReorderOn,
  showAlertDeceased,
  showAlertNoRecordForUser,
  showAlertNoSuppliesForReorder,
  showAlertReorderAccessExpired,
  showAlertSomethingWentWrong,
} from '../selectors';

const Alerts = () => {
  const reorderDate = useSelector(canReorderOn);
  const renderAlertDeceased = useSelector(showAlertDeceased);
  const renderAlertNoRecordForUser = useSelector(showAlertNoRecordForUser);
  const renderAlertNoSuppliesForReorder = useSelector(
    showAlertNoSuppliesForReorder,
  );
  const renderAlertReorderAccessExpired = useSelector(
    showAlertReorderAccessExpired,
  );
  const renderAlertSomethingWentWrong = useSelector(
    showAlertSomethingWentWrong,
  );

  if (renderAlertDeceased) {
    return <AlertDeceased />;
  }

  if (renderAlertNoRecordForUser) {
    return <AlertNoRecordForUser />;
  }

  if (renderAlertReorderAccessExpired) {
    return <AlertReorderAccessExpired />;
  }

  if (renderAlertSomethingWentWrong) {
    return <AlertSomethingWentWrong />;
  }

  if (renderAlertNoSuppliesForReorder) {
    return <AlertNoSuppliesForReorder reorderDate={reorderDate} />;
  }

  return null;
};

export default Alerts;