PageItemControl.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React, { FC } from 'react';
  2. import toastr from 'toastr';
  3. import { useTranslation } from 'react-i18next';
  4. import { IPageHasId } from '~/interfaces/page';
  5. type PageItemControlProps = {
  6. page: Partial<IPageHasId>
  7. isEnableActions: boolean
  8. isDeletable: boolean
  9. onClickDeleteButton?: (pageId: string) => void
  10. }
  11. const PageItemControl: FC<PageItemControlProps> = (props: PageItemControlProps) => {
  12. const {
  13. page, isEnableActions, onClickDeleteButton, isDeletable,
  14. } = props;
  15. const { t } = useTranslation('');
  16. const deleteButtonHandler = () => {
  17. if (onClickDeleteButton != null && page._id != null) {
  18. onClickDeleteButton(page._id);
  19. }
  20. };
  21. return (
  22. <>
  23. <button
  24. type="button"
  25. className="btn-link dropdown-toggle dropdown-toggle-no-caret border-0 rounded grw-btn-page-management p-0"
  26. data-toggle="dropdown"
  27. >
  28. <i className="icon-options fa fa-rotate-90 text-muted p-1"></i>
  29. </button>
  30. <div className="dropdown-menu dropdown-menu-right">
  31. {/* TODO: if there is the following button in XD add it here
  32. <button
  33. type="button"
  34. className="btn btn-link p-0"
  35. value={page.path}
  36. onClick={(e) => {
  37. window.location.href = e.currentTarget.value;
  38. }}
  39. >
  40. <i className="icon-login" />
  41. </button>
  42. */}
  43. {/*
  44. TODO: add function to the following buttons like using modal or others
  45. ref: https://estoc.weseek.co.jp/redmine/issues/79026
  46. */}
  47. {/* TODO: show dropdown when permalink section is implemented */}
  48. {!isEnableActions && <p className="dropdown-item">{t('search_result.currently_not_implemented')}</p>}
  49. {isEnableActions && (
  50. <button className="dropdown-item" type="button" onClick={() => toastr.warning(t('search_result.currently_not_implemented'))}>
  51. <i className="icon-fw icon-star"></i>
  52. {t('Add to bookmark')}
  53. </button>
  54. )}
  55. {isEnableActions && (
  56. <button className="dropdown-item" type="button" onClick={() => toastr.warning(t('search_result.currently_not_implemented'))}>
  57. <i className="icon-fw icon-docs"></i>
  58. {t('Duplicate')}
  59. </button>
  60. )}
  61. {isEnableActions && (
  62. <button className="dropdown-item" type="button" onClick={() => toastr.warning(t('search_result.currently_not_implemented'))}>
  63. <i className="icon-fw icon-note"></i>
  64. {t('Rename')}
  65. </button>
  66. )}
  67. {isDeletable && isEnableActions && (
  68. <>
  69. <div className="dropdown-divider"></div>
  70. <button className="dropdown-item text-danger pt-2" type="button" onClick={deleteButtonHandler}>
  71. <i className="icon-fw icon-trash"></i>
  72. {t('Delete')}
  73. </button>
  74. </>
  75. )}
  76. </div>
  77. </>
  78. );
  79. };
  80. export default PageItemControl;