PageAccessoriesModalControl.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import React, { Fragment, useMemo } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import { UncontrolledTooltip } from 'reactstrap';
  5. import PageAccessoriesContainer from '../services/PageAccessoriesContainer';
  6. import PageListIcon from './Icons/PageListIcon';
  7. import TimeLineIcon from './Icons/TimeLineIcon';
  8. import HistoryIcon from './Icons/HistoryIcon';
  9. import AttachmentIcon from './Icons/AttachmentIcon';
  10. import ShareLinkIcon from './Icons/ShareLinkIcon';
  11. import SeenUserInfo from './User/SeenUserInfo';
  12. import { withUnstatedContainers } from './UnstatedUtils';
  13. const PageAccessoriesModalControl = (props) => {
  14. const {
  15. t, pageAccessoriesContainer, isGuestUser, isSharedUser, isNotFoundPage,
  16. } = props;
  17. const accessoriesBtnList = useMemo(() => {
  18. return [
  19. {
  20. name: 'pagelist',
  21. Icon: <PageListIcon />,
  22. disabled: isSharedUser,
  23. i18n: t('page_list'),
  24. },
  25. {
  26. name: 'timeline',
  27. Icon: <TimeLineIcon />,
  28. disabled: isSharedUser,
  29. i18n: t('Timeline View'),
  30. },
  31. {
  32. name: 'pageHistory',
  33. Icon: <HistoryIcon />,
  34. disabled: isGuestUser || isSharedUser || isNotFoundPage,
  35. i18n: t('History'),
  36. },
  37. {
  38. name: 'attachment',
  39. Icon: <AttachmentIcon />,
  40. disabled: isNotFoundPage,
  41. i18n: t('attachment_data'),
  42. },
  43. {
  44. name: 'shareLink',
  45. Icon: <ShareLinkIcon />,
  46. disabled: isGuestUser || isSharedUser || isNotFoundPage,
  47. i18n: t('share_links.share_link_management'),
  48. },
  49. ];
  50. }, [t, isGuestUser, isSharedUser, isNotFoundPage]);
  51. return (
  52. <div className="grw-page-accessories-control d-flex flex-nowrap align-items-center justify-content-end justify-content-lg-between">
  53. {accessoriesBtnList.map((accessory) => {
  54. let tooltipMessage;
  55. if (accessory.disabled) {
  56. tooltipMessage = isNotFoundPage ? t('not_found_page.page_not_exist') : t('Not available for guest');
  57. }
  58. else {
  59. tooltipMessage = accessory.i18n;
  60. }
  61. return (
  62. <Fragment key={accessory.name}>
  63. <div id={`shareLink-btn-wrapper-for-tooltip-for-${accessory.name}`}>
  64. <button
  65. type="button"
  66. className={`btn btn-link grw-btn-page-accessories ${accessory.disabled ? 'disabled' : ''}`}
  67. onClick={() => pageAccessoriesContainer.openPageAccessoriesModal(accessory.name)}
  68. >
  69. {accessory.Icon}
  70. </button>
  71. </div>
  72. <UncontrolledTooltip placement="top" target={`shareLink-btn-wrapper-for-tooltip-for-${accessory.name}`} fade={false}>
  73. {tooltipMessage}
  74. </UncontrolledTooltip>
  75. </Fragment>
  76. );
  77. })}
  78. <div className="d-flex align-items-center">
  79. <span className="border-left grw-border-vr">&nbsp;</span>
  80. <SeenUserInfo disabled={isSharedUser} />
  81. </div>
  82. </div>
  83. );
  84. };
  85. /**
  86. * Wrapper component for using unstated
  87. */
  88. const PageAccessoriesModalControlWrapper = withUnstatedContainers(PageAccessoriesModalControl, [PageAccessoriesContainer]);
  89. PageAccessoriesModalControl.propTypes = {
  90. t: PropTypes.func.isRequired, // i18next
  91. pageAccessoriesContainer: PropTypes.instanceOf(PageAccessoriesContainer).isRequired,
  92. isGuestUser: PropTypes.bool.isRequired,
  93. isSharedUser: PropTypes.bool.isRequired,
  94. isNotFoundPage: PropTypes.bool.isRequired,
  95. };
  96. export default withTranslation()(PageAccessoriesModalControlWrapper);