PageAccessoriesModalControl.jsx 3.7 KB

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