PageAccessoriesModalControl.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React, { Fragment, useMemo } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { useTranslation } from 'react-i18next';
  4. import { UncontrolledTooltip } from 'reactstrap';
  5. import { useCurrentPageId } from '~/stores/context';
  6. import AttachmentIcon from './Icons/AttachmentIcon';
  7. import HistoryIcon from './Icons/HistoryIcon';
  8. import PageListIcon from './Icons/PageListIcon';
  9. import ShareLinkIcon from './Icons/ShareLinkIcon';
  10. import TimeLineIcon from './Icons/TimeLineIcon';
  11. import { withUnstatedContainers } from './UnstatedUtils';
  12. const PageAccessoriesModalControl = (props) => {
  13. const { t } = useTranslation();
  14. const {
  15. pageAccessoriesContainer, isGuestUser, isSharedUser,
  16. } = props;
  17. const isLinkSharingDisabled = pageAccessoriesContainer.appContainer.config.disableLinkSharing;
  18. const { data: pageId } = useCurrentPageId();
  19. const accessoriesBtnList = useMemo(() => {
  20. return [
  21. {
  22. name: 'pagelist',
  23. Icon: <PageListIcon />,
  24. disabled: isSharedUser,
  25. i18n: t('page_list'),
  26. },
  27. {
  28. name: 'timeline',
  29. Icon: <TimeLineIcon />,
  30. disabled: isSharedUser,
  31. i18n: t('Timeline View'),
  32. },
  33. {
  34. name: 'pageHistory',
  35. Icon: <HistoryIcon />,
  36. disabled: isGuestUser || isSharedUser,
  37. i18n: t('History'),
  38. },
  39. {
  40. name: 'attachment',
  41. Icon: <AttachmentIcon />,
  42. i18n: t('attachment_data'),
  43. },
  44. {
  45. name: 'shareLink',
  46. Icon: <ShareLinkIcon />,
  47. disabled: isGuestUser || isSharedUser || isLinkSharingDisabled,
  48. i18n: t('share_links.share_link_management'),
  49. },
  50. ];
  51. }, [t, isGuestUser, isSharedUser, 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 = 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>
  83. );
  84. };
  85. PageAccessoriesModalControl.propTypes = {
  86. pageAccessoriesContainer: PropTypes.any,
  87. isGuestUser: PropTypes.bool.isRequired,
  88. isSharedUser: PropTypes.bool.isRequired,
  89. };
  90. /**
  91. * Wrapper component for using unstated
  92. */
  93. const PageAccessoriesModalControlWrapper = withUnstatedContainers(PageAccessoriesModalControl, []);
  94. export default PageAccessoriesModalControlWrapper;