AttachmentIcon.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as React from "react";
  2. import { Box, Link } from "@mui/material";
  3. import { useTranslation } from "react-i18next";
  4. import fileDocument from "../img/file-document.svg";
  5. import fileImage from "../img/file-image.svg";
  6. import fileVideo from "../img/file-video.svg";
  7. import fileAudio from "../img/file-audio.svg";
  8. import fileApp from "../img/file-app.svg";
  9. const AttachmentIcon = (props) => {
  10. const { t } = useTranslation();
  11. const { type } = props;
  12. let imageFile;
  13. let imageLabel;
  14. if (!type) {
  15. imageFile = fileDocument;
  16. imageLabel = t("notifications_attachment_file_image");
  17. } else if (type.startsWith("image/")) {
  18. imageFile = fileImage;
  19. imageLabel = t("notifications_attachment_file_video");
  20. } else if (type.startsWith("video/")) {
  21. imageFile = fileVideo;
  22. imageLabel = t("notifications_attachment_file_video");
  23. } else if (type.startsWith("audio/")) {
  24. imageFile = fileAudio;
  25. imageLabel = t("notifications_attachment_file_audio");
  26. } else if (type === "application/vnd.android.package-archive") {
  27. imageFile = fileApp;
  28. imageLabel = t("notifications_attachment_file_app");
  29. } else {
  30. imageFile = fileDocument;
  31. imageLabel = t("notifications_attachment_file_document");
  32. }
  33. return (
  34. <Link href={props.href} target="_blank">
  35. <Box
  36. component="img"
  37. src={imageFile}
  38. alt={imageLabel}
  39. loading="lazy"
  40. sx={{
  41. width: "28px",
  42. height: "28px",
  43. }}
  44. />
  45. </Link>
  46. );
  47. };
  48. export default AttachmentIcon;