huridocs/uwazi

View on GitHub
app/react/Metadata/components/ImageViewer.tsx

Summary

Maintainability
A
0 mins
Test Coverage
D
66%
import { Translate } from 'app/I18N';
import React, { useState } from 'react';

interface ImageViewerProps {
  key: string;
  className: string;
  src: string;
  alt: string;
}

const ImageViewer = (props: ImageViewerProps) => {
  const [errorFlag, setErrorFlag] = useState(false);

  if (errorFlag) {
    return (
      <div className="media-error">
        <Translate>This file type is not supported on image fields</Translate>
      </div>
    );
  }

  return (
    <img
      {...props}
      onError={() => {
        setErrorFlag(true);
      }}
    />
  );
};

export { ImageViewer, type ImageViewerProps };