PageAccessoriesModalControl.jsx 3.8 KB

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