PageAccessoriesModalControl.jsx 3.9 KB

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