index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React, { useEffect } from 'react';
  2. import toastError from "../../errors/toastError";
  3. import { Button, Divider, Typography} from "@material-ui/core";
  4. import { i18n } from '../../translate/i18n';
  5. const LocationPreview = ({ image, link, description }) => {
  6. useEffect(() => {}, [image, link, description]);
  7. const handleLocation = async() => {
  8. try {
  9. window.open(link);
  10. } catch (err) {
  11. toastError(err);
  12. }
  13. }
  14. return (
  15. <>
  16. <div style={{
  17. minWidth: "250px",
  18. }}>
  19. <div>
  20. <div style={{ float: "left" }}>
  21. <img src={image} alt="loc" onClick={handleLocation} style={{ width: "100px" }} />
  22. </div>
  23. { description && (
  24. <div style={{ display: "flex", flexWrap: "wrap" }}>
  25. <Typography style={{ marginTop: "12px", marginLeft: "15px", marginRight: "15px", float: "left" }} variant="subtitle1" color="primary" gutterBottom>
  26. <div dangerouslySetInnerHTML={{ __html: description.replace('\\n', '<br />') }}></div>
  27. </Typography>
  28. </div>
  29. )}
  30. <div style={{ display: "block", content: "", clear: "both" }}></div>
  31. <div>
  32. <Divider />
  33. <Button
  34. fullWidth
  35. color="primary"
  36. onClick={handleLocation}
  37. disabled={!link}
  38. >
  39. {i18n.t("locationPreview.button")}
  40. </Button>
  41. </div>
  42. </div>
  43. </div>
  44. </>
  45. );
  46. };
  47. export default LocationPreview;