PageAccessoriesModalControl.jsx 3.3 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 PageListIcon from './Icons/PageListIcon';
  6. import TimeLineIcon from './Icons/TimeLineIcon';
  7. import HistoryIcon from './Icons/HistoryIcon';
  8. import AttachmentIcon from './Icons/AttachmentIcon';
  9. import ShareLinkIcon from './Icons/ShareLinkIcon';
  10. import { withUnstatedContainers } from './UnstatedUtils';
  11. import { useCurrentPageId } from '~/stores/context';
  12. const PageAccessoriesModalControl = (props) => {
  13. const {
  14. t, pageAccessoriesContainer, isGuestUser, isSharedUser,
  15. } = props;
  16. const isLinkSharingDisabled = pageAccessoriesContainer.appContainer.config.disableLinkSharing;
  17. const { data: pageId } = useCurrentPageId();
  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,
  36. i18n: t('History'),
  37. },
  38. {
  39. name: 'attachment',
  40. Icon: <AttachmentIcon />,
  41. i18n: t('attachment_data'),
  42. },
  43. {
  44. name: 'shareLink',
  45. Icon: <ShareLinkIcon />,
  46. disabled: isGuestUser || isSharedUser || isLinkSharingDisabled,
  47. i18n: t('share_links.share_link_management'),
  48. },
  49. ];
  50. }, [t, isGuestUser, isSharedUser, isLinkSharingDisabled]);
  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 = t('Not available for guest');
  57. if (accessory.name === 'shareLink' && isLinkSharingDisabled) {
  58. tooltipMessage = t('Link sharing is disabled');
  59. }
  60. }
  61. else {
  62. tooltipMessage = accessory.i18n;
  63. }
  64. return (
  65. <Fragment key={accessory.name}>
  66. <div id={`shareLink-btn-wrapper-for-tooltip-for-${accessory.name}`}>
  67. <button
  68. type="button"
  69. className={`btn btn-link grw-btn-page-accessories ${accessory.disabled ? 'disabled' : ''}`}
  70. onClick={() => pageAccessoriesContainer.openPageAccessoriesModal(accessory.name)}
  71. >
  72. {accessory.Icon}
  73. </button>
  74. </div>
  75. <UncontrolledTooltip placement="top" target={`shareLink-btn-wrapper-for-tooltip-for-${accessory.name}`} fade={false}>
  76. {tooltipMessage}
  77. </UncontrolledTooltip>
  78. </Fragment>
  79. );
  80. })}
  81. </div>
  82. );
  83. };
  84. /**
  85. * Wrapper component for using unstated
  86. */
  87. const PageAccessoriesModalControlWrapper = withUnstatedContainers(PageAccessoriesModalControl, []);
  88. PageAccessoriesModalControl.propTypes = {
  89. t: PropTypes.func.isRequired, // i18next
  90. pageAccessoriesContainer: PropTypes.any,
  91. isGuestUser: PropTypes.bool.isRequired,
  92. isSharedUser: PropTypes.bool.isRequired,
  93. };
  94. export default withTranslation()(PageAccessoriesModalControlWrapper);